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

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.

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

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

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

How to properly fit an image into a div in HTML and CSS using ReactJS

I am about to finish a small database of images of vessels. As you can see from the screenshot below, the problem I have is that the cards are all different sizes despite I fix the css classes to a specific width. I am trying to have all the card of same width and height. What am I doing wrong?
Below the snippet of code related to this problem:
vessels.js
export default function Vessel({ vessel }) {
const { name, slug, images /* size */ } = vessel;
return (
<div>
<article className="room">
<div className="img-container">
<img src={images[0] || defaultImg} alt="single" />
<Link to={`/vessels/${slug}`} className="btn-primary">
Features
</Link>
</div>
</article>
</div>
);
}
And the related App.css classes:
.room {
display: block;
box-shadow: var(--lightShadow);
transition: var(--mainTransition);
}
.img-container {
position: relative;
}
.img-container img {
width: 100%;
display: block;
transition: var(--mainTransition);
}
What I have done so far:
I have been trying to research and figure out the problem of why that is happening but couldn't understand what I am doing wrong. I consulted this source which seems to be pretty clear. I apply and the result I have is the one on the image I posted.
I tried also to add the height property on the css but that didn't change the problem
.img-container img {
width: 100%;
height: 100%;
display: block;
transition: var(--mainTransition);
}
At a certain point I suspected it was a probelm of visibility but that also didn't change the issue I have. And I think it is not a problem of visibility property.
It seems to me that there is a (probable?) property that could be overwritten? Or maybe that is not the problem.
Thanks for pointing to the right direction on how to solve this issue.
Try using flexbox and styled components for your desired design.
Example:
import React from "react";
import styled from "styled-components";
import "./styles.css";
const BoatContainer = styled.div`
display: flex;
flex-flow: row wrap;
`;
const BoatImg = styled.img`
width: 200px;
margin: 5px;
`;
export default function App() {
return (
<div className="App">
<h1>Behold: boats.</h1>
<BoatContainer>
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Motorboat_at_Kankaria_lake.JPG/1920px-Motorboat_at_Kankaria_lake.JPG" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Boats_at_Bhimili_beach_in_Visakhapatnam.jpg/1280px-Boats_at_Bhimili_beach_in_Visakhapatnam.jpg" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Motorboat_at_Kankaria_lake.JPG/1920px-Motorboat_at_Kankaria_lake.JPG" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Boats_at_Bhimili_beach_in_Visakhapatnam.jpg/1280px-Boats_at_Bhimili_beach_in_Visakhapatnam.jpg" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Motorboat_at_Kankaria_lake.JPG/1920px-Motorboat_at_Kankaria_lake.JPG" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Boats_at_Bhimili_beach_in_Visakhapatnam.jpg/1280px-Boats_at_Bhimili_beach_in_Visakhapatnam.jpg" />
</BoatContainer>
</div>
);
}
Sandbox demo: https://codesandbox.io/s/stack-63731876-boats-e7onm
Here's a handy CSS Tricks guide to flexbox for reference: https://css-tricks.com/snippets/css/a-guide-to-flexbox/