bootstrap 5 navbar in 2 rows - html

I'm trying to create this navbar design, but I also want to maintain the responsiveness, hamburger menu but only for the upper part (home, contact us, etc links)
.red {
background-color: red;
width: 100px;
height: 100px;
}
.blue {
background-color: blue;
width: 100px;
height: 100px;
}
.yellow {
background-color: yellow;
width: 100px;
height: 100px;
}
.orange {
background-color: orange;
width: 50px;
height: 50px;
border: 2px solid black;
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0-beta1/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg bg-black">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<div class="red">a</div>
</a>
<button class="navbar-toggler ms-auto" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-menu">
<div class="yellow"></div>
</span>
</button>
<div class="container">
<div class="row">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active text-white active-page fs-2" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-white fs-2" href="#">Rooms</a>
</li>
<li class="nav-item">
<a class="nav-link text-white fs-2" href="#">Team</a>
</li>
<li class="nav-item">
<a class="nav-link text-white fs-2" href="#">Info</a>
</li>
<li class="nav-item">
<a class="nav-link text-white fs-2" href="#">Contact us</a>
</li>
</ul>
</div>
</div>
<div class="d-none d-lg-block bg-white p-3">
<!-- Have to make like this, if i put everything in a single div it brakes -->
<div class="row justify-content-md-center">
<div class="col-3 d-flex align-items-center">
<span class="font-SansSerifBldFLFCond text-blue">CALL US NOW</span>
<div class="orange">s</div>
</div>
<div class="col-3 d-flex align-items-center">
<p class="text-blue">From</p>
<div id="today-date ">
<h4 class="fs-6 text-blue">SUNDAY</h4>
<p class="fs-3">15 May</p>
</div>
<div class="orange">s</div>
</div>
<div class="col-3 d-flex align-items-center">
<p class="text-blue">To</p>
<div id="tomorrow-date">
<h4 class="fs-6 text-blue">MONDAY</h4>
<p class="fs-3">16 May</p>
</div>
<div class="orange">s</div>
</div>
<div class="col-3 d-flex align-items-center">
<p class="text-blue font-SansSerifBldFLFCond">INFO</p>
</div>
</div>
</div>
</div>
</div>
</nav>
First main problem is I want to center the links (home, about info)
Second, I want to remove all the padding and margin so the icon (red div) have the same height of the Navbar.
And final thing The height of the 2 columns (links and calendar, phone ecc) should be 50% of the logo each, so combined they have the same height of the logo

Related

How can the navbar be edited such that the link 1 appears aligned to the right side link 2 at the center and link 3 on the right

I have tried using flex property and justify content but that doesn't work as well. I tried the below mentioned code.
the aim is to make a website with a logo on top and navbar right below like shown below
how the site looks like as of now
<header class="top-part">
<div class="logo">
<img class="logo" src="images/logo.png" height=100px width="237px" >
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light ">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ">
<li >
<a class="nav-link" id="home"href="#">link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" id="cart" href="#">link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact"href="#">link 3</a>
</li>
</ul>
</div>
</nav>
</header>
</head>
css :
#media screen and (min-width:777px){
.nav-link {
padding:18px 0;
min-width:120px;
}
.navbar {
padding: 0
}
}
.header{
position:sticky ;
top: 0;
}
I'd recommend doing some research and practicing with some basic HTML/CSS, so you understand the basics and know what everything does.
For this specific example you should look into 'flexbox'!
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<header class="d-flex flex-column align-items-center">
<img style="width: 100px;" src="https://images.unsplash.com/photo-1605666807892-8c11d020bede?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTJ8fGJhbmFuYXxlbnwwfHwwfHw%3D&w=1000&q=80" alt="">
<nav class="w-100 d-flex bg-light">
<a class="p-2 bd-highlight text-black-50 text-decoration-none" href="">link 1</a>
<a class="p-2 bd-highlight text-black-50 text-decoration-none" href="">link 2</a>
<a class="p-2 bd-highlight text-black-50 text-decoration-none" href="">link 3</a>
</nav>
</header>
header {
width: 100%;
text-align: center;
}
a:first-of-type{
float: left;
}
a:last-of-type{
float: right;
}
<header>
<img style="width: 100px;" src="https://images.unsplash.com/photo-1605666807892-8c11d020bede?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTJ8fGJhbmFuYXxlbnwwfHwwfHw%3D&w=1000&q=80" alt="">
<nav>
link 1
link 2
link 3
</nav>
</header>
Here is one method:
Add d-flex, flex-row, and justify-content-center to your parent div containing the logo.
You can add the same to your parent div for the links (ul and li's)
Your links are left aligned, so you can add "text-center" to classes of your <ul> element.
It would look like this:
<header class="top-part">
<div class="logo d-flex flex-row justify-content-center">
<img class="logo" src="images/logo.png" height=100px width="237px" >
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light ">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-flex flex-row justify-content-center" id="navbarNavDropdown">
<ul class="navbar-nav text-center">
<li>
<a class="nav-link" id="home" href="#">link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" id="cart" href="#">link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact"href="#">link 3</a>
</li>
</ul>
</div>
</nav>
</header>
Also just a note, I see your code above is ending with </head>. Make sure you are not putting this code in the <head> of your site, but the <body> :)

(bootstrap) how to align h1 vertically to the middle

<body>
<nav class="navbar navbar-expand-md bg-dark navbar-dark py-3">
<div class="container">
<div class="navbar-brand mx-auto"><h2 style="color: white;">Name</h2></div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#burger"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="burger">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<h2 style="color: white;">Python</h2>
</li>
<li class="nav-item">
<h2 style="color: white;">Name</h2>
</li>
<li class="nav-item">
<h2 style="color: white;">Html&Css</h2>
</li>
</ul>
</div>
</div>
</nav>
<!--Secion One-->
<section class="bg-dark text-light p-5 p-lg-0 text-center text-md-start">
<div class="container">
<div class="row align-items-center text-center">
<h1 class="hi">Design made by the <span style="color: #F23DFF;">youth</span></h1>
</div>
</div>
</section>
</body>
Here is what it looks like right now
!(https://media.discordapp.net/attachments/855988935149486120/896932433319059487/unknown.png?width=609&height=406)
Use flex:
<body class="h-100 d-flex flex-column">
<nav class="navbar navbar-expand-md bg-dark navbar-dark py-3">
<div class="container">
<div class="navbar-brand mx-auto">
<h2 style="color: white">Name</h2>
</div>
<button
class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#burger">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="burger">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a href="#python" class="nav-link px-3">
<h2 style="color: white">Python</h2>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link px-3">
<h2 style="color: white">Name</h2>
</a>
</li>
<li class="nav-item">
<a href="#html&css" class="nav-link px-3">
<h2 style="color: white">Html&Css</h2>
</a>
</li>
</ul>
</div>
</div>
</nav>
<!--Secion One-->
<section
class="
d-flex
align-items-center
flex-1
justify-items-center
bg-dark
text-light
p-5 p-lg-0
text-center text-md-start
">
<div class="container">
<div class="row align-items-center text-center">
<h1 class="hi">
Design made by the <span style="color: #f23dff">youth</span>
</h1>
</div>
</div>
</section>
</body>
the only thing you should also note is that the wrapping html might not be taking the full height, so add the following css:
html{
height:100%
}
.flex-1{
flex: 1;
}

How to place logo image , phone, location above navbar in bootstrap?

I am new to Bootstrap: I want to place logo image, location image with address, phone number with text above the navigation. Logo details should be centered.
What I have tried:
<header >
<div class="container ">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<img class="img-fluid" style="max-width: 50%;" src="images/logo.png" alt="logo">
<img class="img-fluid" style="max-width: 5%" src="images/header-address.png" alt="logo">
<span class="span-text">1234 Abcd Efg <br> HI jk Lm,123466 </span>
<img class="img-fluid" style="max-width: 5%;" src="images/header-phone.png" alt="logo">
<span class="span_text">(123) 456 7890 <br> Call Us </span>
</div>
<div class="col-md-6">
</div>
</div>
</div>
</header>
<section >
<div class="container mx-auto">
<div class="row">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ABOUT</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">GALLERY</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CONTACT US</a>
</li>
</ul>
</div>
</div>
</nav></div>
</div>
</section>
The alignment of the logo, location, and phone number is not achieved.
How to fix this?
Use margin: 0 auto; for .col-md-6
.col-md-6 {
flex: 0 0 auto;
width: 50%;
text-align: center;
}
and if you want to also center the navigation items then add this:
.navbar-expand-lg .navbar-nav {
flex-direction: row;
margin: 0 auto;
}
Top Phone number... centered:
Nav Items centered:
Both centered with text-align

Bootstrap 4 add text over image in navigation bar

I still do not fully understand the flex structure in Bootstrap. I'll put down what I'm trying to do and the codes I've written. In short, what I want to do is add text over the image in the navbar. But the container of the navbar does not allow this. I think it's because I set the containers wrong. Thanks in advance for those who help.
Code:
.navbar-brand {
position: absolute;
width: 100%;
z-index: 3000;
}
.mnav {
height: 123px;
z-index: 2000;
width: 1200px
}
.has-bg-img {
z-index: 2000;
}
<div class="section fixed-top">
<div class="container-fluid bg-dark">
<div class="row p-3 bg-dark mx-auto ">
<div class="container text-light" style="max-width: 1200px">topnav</div>
</div>
</div>
<div class="container-fluid bg-light d-flex shadow-lg">
<nav class="navbar navbar-expand-lg navbar-light bg-light mx-auto mnav">
<div class="navbar-collapse collapse w-30 order-1 order-md-0 dual-collapse2">
<ul class="navbar-nav mr-auto h-dark">
<li class="nav-item active ">
<a class="nav-link text-dark" href="#">Home</a>
</li>
<li class="nav-item ">
<a class="nav-link text-dark" href="//codeply.com">Clinic</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#">Blog</a>
</li>
</ul>
</div>
<div class="col-auto mx-auto">
<div class="shadow rounded-circle">
<img src="https://i.imgur.com/swpgs2N.png" class="img-circle navbar-brand p-0 m-0" alt="marmarasmile-logo">
</div>
</div>
<div class="mx-5 order-0">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="navbar-collapse collapse w-30 order-1 order-md-0 dual-collapse2">
<ul class="navbar-nav mr-auto h-dark">
<li class="nav-item active ">
<a class="nav-link text-dark" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#">Blog</a>
</li>
</ul>
</div>
<div class="row pt-4 d-flex align-items-center">
<div class="col-3 text-white ">
<span class="navbar-toggler-icon"></span>
<h5>Appointment</h5>
<h5>Now !</h5>
<img src="https://i.imgur.com/4m0eRiP.png" class="img-circle navbar-brand p-0 m-0" alt="marmarasmile-logo">
</div>
</div>
</nav>
</div>
</div>
<script src="js/jquery-3.x-git.slim"></script>
<script src="js/bootstrap.min.js"></script>
If the only problem is that your text should be placed over the image, have a look at this article: https://www.w3schools.com/howto/howto_css_image_text.asp
In order to transfer it to your code, you can use the following snippet (I added font-awesome because i am not sure where your icon came from):
.bookmark {
position: relative;
text-align: center;
color: white;
}
.bookmark-texts {
padding: 20px;
position: absolute;
top: 0;
left: 0;
font-size: 18px;
}
.fa {
font-size: 35px !important;
margin-bottom: 5px;
}
.now {
font-style: italic;
font-weight: bold;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<div class="row pt-4 d-flex align-items-center">
<div class="col-3">
<div id="bookmark" class="d-inline-block">
<img src="https://i.imgur.com/4m0eRiP.png" class="img-circle navbar-brand p-0 m-0" alt="marmarasmile-logo">
<div class="bookmark-texts text-center text-white">
<!-- <span class="navbar-toggler-icon"></span> -->
<i class="fa fa-calendar" aria-hidden="true"></i>
<div class="appointment">Appointment</div>
<div class="now">Now !</div>
</div>
</div>
</div>
</div>
Also have a look at this fiddle resulting in this:

Bootstrap 4 collapse sidebar into a navbar dropdown

I have a navbar and a sidebar to the left which I want to collapse to the navbar as a dropdown option in smaller screens. This is what it looks like in bigger screens
When the screen size is small, I want something like this to happen
Here are my codes
HTML body
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-md navbar-dark bg-dark py-2">
<a class="navbar-brand" href="#">CDR</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Login</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid flex-grow-1">
<div class="row h-100">
<!-- Sidebar -->
<!-- Collapse as a navbar dropdown in smaller screens -->
<div class="col-lg-3 col-sm-4 sidebar">
<div class="sidebar-container mt-4 mx-2">
<h4 class="text-capitalize py-2">Subjects</h4>
<ul class="nav flex-column subjects">
<li class="subject" data-subject="mathematics">
<h5 class="subject-title mb-1">Mathematics</h5>
<h6 class="subject-details m-0">
<span class="teacher">Prof X.</span> |
<span class="room">Room 113</span>
</h6>
</li>
<li class="subject" data-subject="science">
<h5 class="subject-title mb-1">Science</h5>
<h6 class="subject-details m-0">
<span class="teacher">Prof Y.</span> |
<span class="room">Room 111</span>
</h6>
</li>
<li class="subject" data-subject="english">
<h5 class="subject-title mb-1">English</h5>
<h6 class="subject-details m-0">
<span class="teacher">Prof Z.</span> |
<span class="room">Room 130</span>
</h6>
</li>
</ul>
</div>
</div>
<!-- Content -->
<div class="col-lg-9 col-sm-8 content-container">
<div class="row h-100">
<div class="col-lg-9 col-md-9 col-sm-12 main-container"></div>
<div class="col-lg-3 col-md-3 d-none d-md-block announcement-container">uwu</div>
</div>
</div>
</div>
</div>
</body>
CSS
html,
body {
height: 100%;
display: flex;
flex-direction: column;
}
.sidebar {
border-right: 1px solid var(--light-grey);
}
.subjects {
user-select: none;
}
.subject {
padding: 15px;
cursor: pointer;
border: 1px solid var(--lighter-grey);
border-radius: 5px;
margin-bottom: 5px;
}
.subject-title {
font-size: 0.8rem;
letter-spacing: 2px;
}
.subject-details {
text-transform: capitalize;
color: var(--gray);
letter-spacing: 2px;
}
.active {
font-size: 1rem;
background-color: var(--lighter-grey);
border-left: 4px solid var(--gray);
padding-left: 12px;
}
.content-container {
background-color: var(--content-bg-grey);
}
So far as I've searched, I can't find a way to do this just yet. What would be the proper way to do it? Is there a bootstrap setting that will allow for this or do I need to use JS? I'm also using jQuery if this helps any.
Thanks!
just add this to your html code
<nav class="navbar navbar-expand-md navbar-dark bg-dark py-2">
<a class="navbar-brand" href="#">CDR</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Login</a>
</li>
<!-- this will appear only in small screen -->
<li class="nav-item dropdown d-md-none">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Subjects
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Mathematics</a>
<a class="dropdown-item" href="#">Science</a>
<a class="dropdown-item" href="#">English</a>
</div>
</li>
</ul>
</div>
</nav>
<div class="container-fluid flex-grow-1">
<div class="row h-100">
<!-- Sidebar -->
<!-- Collapse as a navbar dropdown in smaller screens -->
<!-- i was added two classes (d-md-block d-none) -->
<div class="col-lg-3 col-sm-4 sidebar d-md-block d-none">
<div class="sidebar-container mt-4 mx-2">
<h4 class="text-capitalize py-2">Subjects</h4>
<ul class="nav flex-column subjects">
<li class="subject" data-subject="mathematics">
<h5 class="subject-title mb-1">Mathematics</h5>
<h6 class="subject-details m-0">
<span class="teacher">Prof X.</span> |
<span class="room">Room 113</span>
</h6>
</li>
<li class="subject" data-subject="science">
<h5 class="subject-title mb-1">Science</h5>
<h6 class="subject-details m-0">
<span class="teacher">Prof Y.</span> |
<span class="room">Room 111</span>
</h6>
</li>
<li class="subject" data-subject="english">
<h5 class="subject-title mb-1">English</h5>
<h6 class="subject-details m-0">
<span class="teacher">Prof Z.</span> |
<span class="room">Room 130</span>
</h6>
</li>
</ul>
</div>
</div>
<!-- Content -->
<div class="col-lg-9 col-sm-8 content-container">
<div class="row h-100">
<div class="col-lg-9 col-md-9 col-sm-12 main-container"></div>
<div class="col-lg-3 col-md-3 d-none d-md-block announcement-container">uwu</div>
</div>
</div>
</div>
</div>