Why does flex start shrinking vertically, below a certain width? - html

I'm just testing out flex with a simple layout and I noticed that when I inspect the page and test it's responsiveness, when it gets below around 400px in width, the content start shrinking vertically, leaving a bunch of empty on the bottom space as show below. Is it normal for flex to do this below a certain width? if so, do you just use media queries to fix this or is there another method?
(the top is just header with shrunken items, which is why it looks weird)
Here is the link as I'm not yet allowed to post pictures
* {
margin: 0;
padding: 0;
overflow-y: hidden;
}
#mainContent{
display: flex;
background-color: rgb(208, 255, 218);
}
.sideNav{
background-color: rgb(159, 255, 134);
padding: 100% 2% 100% 2%;
}
Home Component
import React from 'react'
import Header from './Header';
import SideBar from './SideBar';
function Home() {
return (
<div>
<Header></Header>
<div id='mainContent'>
<SideBar></SideBar>
</div>
</div>
)
}
export default Home
Header Component
import React from 'react'
import {BrowserRouter as Link} from "react-router-dom";
function Header() {
return (
<div>
<navbar className="nav-bar">
<ul className="navItems">
<li>
<h1>Groupster</h1>
</li>
<li>
<Link to='/'>Home</Link>
</li>
<li>
<Link to='/login'>Login</Link>
</li>
</ul>
</navbar>
</div>
)
}
export default Header
SideBar Component
import React from 'react';
function SideBar() {
return (
<div className='sideNav'></div>
)
}
export default SideBar

Related

Layering components on pages in gatsby

Hi I've been trying to add a navbar to my homepage. Since my navbar is going to have the same background, I would like to have the content on my homepage to stay at the exact same spot.
The issue however is that when I import my navbar, or insert anything under the class home, the content on my homepage gets squeezed down.
Hence I would like to import my navbar in a way such that it lays on top of my homepage or recenter the items on my homepage such that it takes into account the downward shift caused by the navbar.
In the example below, I would like only the class hometext to be centered
home.js:
import React from "react";
import Navbar from "../components/Navbar";
const home = () => {
return (
<>
<div className="home">
<Navbar />
<p className="hometext">Home</p>
</div>
</>
);
};
export default home;
Navbar.js:
import React from "react";
const Navbar = () => {
return <nav>This is navbar</nav>;
};
export default Navbar;
main.css
.home {
background: var(--background);
}
.hometext {
height: 100vh;
font-family: Ace Sans;
font-size: 3rem;
display: flex;
justify-content: center;
align-items: center;
}
Using an absolute position is not an option for me as the webpage as a whole uses a snap scroll feature so under the homepage there are different pages with different content. Thank you!

Adding a component in React results in horizontal scroll bar

Here's the website before adding the Navbar component:
and here's the website after adding the new component:
I have no idea what properties are causing this, but here's the code:
index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
// React entry point
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
index.css
/* tailwind directives */
#tailwind base;
#tailwind components;
#tailwind utilities;
body,
html {
margin: 0;
padding: 0;
font-family: 'Raleway', sans-serif !important;
}
App.js
import { ChakraProvider } from '#chakra-ui/react';
import Welcome from './components/Welcome';
import Navbar from './components/Navbar'
// Main React component
export default function App() {
return (
<ChakraProvider>
<div className="App w-screen">
<Welcome />
<Navbar />
</div>
</ChakraProvider>
);
}
Welcome.js
import "./Welcome.css"
import React from "react";
// Welcome section
export default function Welcome() {
return (
<div className="Welcome w-screen h-screen grid place-items-center">
<div className="Welcome-content grid place-items-center space-y-10 text-white">
<p className="Welcome-text text-center ">
Hello, I'm <span className="Welcome-name text-emerald-400">Omar El Atyqy</span>.
<br />
I'm a <span className="Welcome-job text-emerald-400 txt-rotate" data-period="1000"
data-rotate='[ "web developper", "data scientist", "passionate geek" ]'></span>.
</p>
<a href="#" className="Welcome-button hover:bg-emerald-500 py-4 px-6">
Let's have a look!
</a>
</div>
</div>
);
}
welcome.css
.Welcome {
background-image: url("../../public/images/background.png");
}
.Welcome-text {
font-size: 32pt;
line-height: 36pt;
font-weight: 400;
}
.Welcome-button {
font-size: 15pt;
border: 2px solid #fff;
transition-duration: 0.5s;
}
Navbar.js
import './Navbar.css'
export default function Navbar () {
return (
<div className='Navbar w-screen'>
hello world
</div>
);
}
I haven't included App.css and Navbar.css because they are empty.
Since you are using w-screen, the navbar and welcome components will have a with of 100vw. Which is exactly the with of the viewport. You have set h-screen on the welcome component, so that one will fill the viewport completely. Now if you add the navbar, the height of the total page will exceed the hight of the viewprot, so it will add a sidebar on the right. This makes the actual area to fit the components in smaller, so your components are to wide for the window, that’s why the vertical scroll bar appears.
You can fix this by replacing w-screen with w-full, which makes components take 100% of the available space, rather than fixed width based on the width of the viewport.
See the different descriptions of the classes in the tailwind docs.
Hope this helps.
Try using the browser debug, if you are using chrome, press F12, after opening, press CTRL + SHIFT + C or select the pointer in the upper left corner and hover over the element, check what is causing this, because this way, it is very complicated to debug and understand
Have you tried adding margin: 0 and box-sizing: border-box in App.css ?
By default, div elements might have margin: 1rem or kind of stuff so if you set your container element to take full width, its content might overflow and causes a slider.
So App.css file will look like this.
* {
margin: 0;
box-sizing: border-box;
}

How can I make links on top of background images clickable?

Forgive me if this has been asked before, I have tried some solutions that have been suggested and none has worked for me just yet.
I have a background image and I want to add links in a div, the links are currently unclickable and I don't know where I am going wrong.
Here's my code so far:
import '../../stylesheets/new_style.scss';
import React, {Fragment, useReducer, useState} from 'react';
import {Button, Col, Row, Modal} from 'react-bootstrap';
const NewGreeting = props => {
return (
<div className="full-page">
<Modal.Dialog>
<Modal.Body>
<p> Modal Content Here </p>
</Modal.Body>
</Modal.Dialog>
<div className='trial text-center'>
test
</div>
</div>
);
};
export default NewGreeting;
And here is my css code:
.full-page {
background-image: url("./hello.png");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.trial{
display: block;
color: #474747;
font-size: 2.1em;
margin-top: 50vh;
}
(Converting my comment to an answer:)
The problem is the <Modal.Dialog> element has special behaviour that makes it "take over" the page and make the rest of the page non-interactive - and your <div> with links in it is located outside that <Modal> dialog, so just move your links into the <Modal.Body> and they'll be made interactive again.
Like so:
import '../../stylesheets/new_style.scss';
import React, {Fragment, useReducer, useState} from 'react';
import {Button, Col, Row, Modal} from 'react-bootstrap';
const NewGreeting = props => {
return (
<div className="full-page">
<Modal.Dialog>
<Modal.Body>
<p> Modal Content Here </p>
<div className='trial text-center'>
test
</div>
</Modal.Body>
</Modal.Dialog>
</div>
);
};
export default NewGreeting;
Try this:
.trial{
display: block;
color: #474747;
font-size: 2.1em;
margin-top: 50vh;
z-index: 999;
}
z-index will help you.
https://www.w3schools.com/cssref/pr_pos_z-index.asp

How can I make top navbar take 100% of the width?

How can I make top navbar take 100% of the width? I have tried many things, including setting width to 100% as well as using <br> after getting desperate. I also read that we should not use row with navbar and I tried to follow the best practise of using Container within Navbar. What's wrong with my thought process?
import React from 'react';
import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom';
import { Navbar, Nav, Container } from 'react-bootstrap';
import './Navigation.css';
import Table from '../../assets/table/Table';
import TableGrouping from '../../assets/table/TableGrouping';
import Home from '../../pages/Home';
const Navigation = () => {
return(
<Navbar className="navbar pt-0 fixed-top>
<Router>
<Container>
<Nav className="bg-custom col-12">
<Link className="nav-item" to="/">Home</Link>
<Link className="nav-item" to="/tableGrouping">Grouping</Link>
<Link className="nav-item" to="/table">Table</Link>
</Nav>
</Container>
<br/>
<Container>
<Routes>
<Route path="/" element={<Home/>}/>
<Route path="/tableGrouping" element={<TableGrouping/>}></Route>
<Route path="/table" element={<Table/>}></Route>
</Routes>
</Container>
</Router>
</Navbar>
)
}
export default Navigation;
Here is my style sheet:
.nav-item {
text-decoration: none;
color: white;
padding: 5px 10px 8px 20px;
}
.container {
width: 100%;
}
.bg-custom {
background-color: rgb(154, 166, 218);
width: 100%;
}
Using <div class="Container"> in Bootstrap will certainly contain the width but you are using <container>. It might be a case of one or the other for Bootstrap to work for your advantage. Try removing that container/div and also check the result without your edited CSS as that may ultimately cause other Bootstrap styling problems later on.

AngularDart App Layout issue with material-navigation

I've been trying to implement a material design site using AngularDart, and I've hit a wall using the angular_components App Layout setup. For the life of me I can't figure out how to change the look of the nav class="material-navigation" content to match the examples (things like background, text color, and text highlight color). Currently the text has a grey box surrounding it rather than matching the header color. It doesn't seem like these properties are set in layout.scss, so I'm stumped. I've made minimal changes to the layout.scss file, which I've posted below. Any insight into what I'm missing? Thanks in advance :)
AngularDart Material Nav
import 'package:angular/angular.dart';
import 'package:angular_components/angular_components.dart';
import 'package:angular_components/material_icon/material_icon.dart';
import 'package:angular_components/material_button/material_button.dart';
import 'package:angular_components/material_list/material_list.dart';
import 'package:angular_components/material_list/material_list_item.dart';
import 'package:angular_components/material_toggle/material_toggle.dart';
import 'package:angular_components/app_layout/material_persistent_drawer.dart';
import 'dart:async';
#Component(
selector: 'my-app',
directives: [
coreDirectives,
MaterialIconComponent,
MaterialButtonComponent,
MaterialToggleComponent,
MaterialListComponent,
MaterialListItemComponent,
MaterialPersistentDrawerDirective],
templateUrl: 'app_component.html',
styleUrls: [
//Holds modifications for angular_components style sheets. Particularly
//app_layout, which is *not* a component but a weird grouping of components
//and styles.
'main.css',
'app_component.css',
],
providers: [ClassProvider(NomiService)],
)
...
#import 'package:angular_components/app_layout/layout';
.material-header {
background-color: $mat-vanilla-red-400; //vs. $mat-indigo-500
}
// A row within the header.
.material-header-row {
/// Class uses for the title inside of a header.
.material-header-title {
left: auto; //vs. $mat-grid * 10;
height: 36px; //$mat-header-height; //vs. $mat-title-font-size
font-size: 36px;
//border: 3px solid green; Use to check work!
//Used to center text!
margin-left: 37.5%;
margin-right: 37.5%;
text-align: center;
width: 25%;
}
.material-navigation{
border: 3px solid green;
}
}
<header class="material-header shadow">
<div class="material-header-row">
<material-button icon class="material-drawer-button" (trigger)="drawer.toggle()">
<material-icon icon="menu"></material-icon>
</material-button>
<img src="favicon.png" width="30">
<span class="material-header-title">Nomi</span>
<div class="material-spacer"></div>
<nav class="material-navigation">
<a>Test</a>
</nav>
</div>
</header>
<material-drawer persistent #drawer="drawer">
<material-list>
<div group>
<material-list-item>
<material-icon icon ="inbox"></material-icon>Inbox
</material-list-item>
<material-list-item>
<material-icon icon ="star"></material-icon>Star
</material-list-item>
<material-list-item>
<material-icon icon ="send"></material-icon>Sent Mail
</material-list-item>
<material-list-item>
<material-icon icon ="drafts"></material-icon>Drafts
</material-list-item>
</div>
</material-list>
</material-drawer>