I'm creating a responsive website using Bootstrap 4. In desktop, things look good. However, in mobile, my logo stays in the center and the menu stays in the left. Here's my codepen.
This is what I need to achieve:
This is what I'm getting:
I am using this code according to Bootstrap's documentation.
This is my Navbar's code:
<nav class="navbar navbar-expand-lg nl-navbar navbar-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-
target="#navbarTogglerDemo02">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="service-main-landing.html">
<img src="images/logo-header.svg" alt="Logo Reebit" class="col-lg-7 col-md-4
col-sm-7 col-7"/>
</a>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link mr-3" href="#">Contactar un profesional</a>
</li>
<li class="nav-item active">
<a class="nav-link mr-4" href="#">Registrarme</a>
</li>
<li class="nav-item active">
<a class="nav-link mr-4" href="#">Iniciar sesión</a>
</li>
<button class="btn my-2 my-sm-0 nl-btn-nav-secondary" type="button" data-
toggle="modal" data-target="#registrationModal"
id="landingRegistrationNavBtn">Publicar servicio</button>
</ul>
</div>
</nav>
Switch your navbar-toggler position with navbar-brand.
<a class="navbar-brand" href="#">
<img src="https://via.placeholder.com/150" class="col-lg-7 col-md-4 col-sm-7 col-7">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02">
<span class="navbar-toggler-icon"></span>
</button>
Additional: Seems like you misunderstood Bootstrap's grid system. col should be direct child of row like this:
<div class="row">
<div class="col">
</div>
<div class="col">
</div>
</div>
Related
There was a problem with extra padding in the navbar after the site icon. Initially, the idea was to place links that are located to the left of the icon closer to the left edge using me-3, but then the icon of the site is shifted to the right, which I basically don’t need.Therefore, I have a question. Is it possible to make the same indents from the site icon and links without shifting this icon from the center or how to remove the indent between the icon and links on the right side of the navbar.
<nav class="navbar navbar-expand-lg navbar-dark fixed-top" id="scroll">
<div class="container-fluid">
<div class="collapse navbar-collapse order-1 order-lg-0 dual-collapse2" id="navbarNavAltMarkup">
<ul class="navbar-nav ms-auto">
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#articles">기사들</a>
</li>
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#mission">우리의 임무</a>
</li>
</ul>
</div>
<a class="navbar-brand order-0" href="#">
<img src="img/marslogo.png" alt="" width="30" height="30">
</a>
<div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="collapse navbar-collapse order-3 dual-collapse2" id="navbarNavAltMarkup"
>
<ul class="navbar-nav">
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#">사진들</a>
</li>
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#">문의하기</a>
</li>
</ul>
</div>
</div>
</nav>
So I can open the menu just fine with the nav button, but when it opens I cannot close it with the button. I added some JS to allow the user to close the menu whenever clicking outside of the menu or on the links and that works...but for some reason, you still can't close the menu when clicking the button itself. I also noticed the button seems to work on my native desktop, but the website I'm developing is on Shopify's platform...so not sure if Shopify is getting in the way or what.
Here is how the nav looks in index.html:
<header>
<nav class="navbar fixed-top navbar-light navbar-expand-lg">
<div class="container-fluid">
<a class="navbar-brand w-25 m-0" href="#">
<img class="img-fluid" src="{{ 'image.png' | file_img_url: 'master' }}" alt="logo" />
</a>
<button class="navbar-toggler me-5" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="d-flex nav navbar-nav">
<li class="nav-item mx-auto">
<a class="nav-link text-uppercase fw-bold" href="#results">Results</a>
</li>
<li class="nav-item mx-auto">
<a class="nav-link text-uppercase fw-bold" href="#testimonies">Testimonials</a>
</li>
<li class="nav-item mx-auto">
<a class="nav-link text-uppercase fw-bold" href="#howItWorks">How it works</a>
</li>
<!-- Currently hidding section on mobile (TEMPORARY ONLY) -->
<li class="nav-item mx-auto d-none d-lg-block">
<a class="nav-link text-uppercase fw-bold" href="#team">Our Team</a>
</li>
<a class="btn mx-auto contact-btn text-uppercase px-4" role="button" href="#Contact">contact us</a>
</ul>
</div>
</div>
</nav>
</header>
I am trying to add a Login button to my navbar in bootstrap, but when I add col-x to separate them equally, but they just cover 50% of the width of the navbar and nothing more. But when I use col-x outside then navbar it works perfectly.
The code
<!-- Navigation -->
<nav class="navbar navbar-dark navbar-expand-md bg-blue sticky-top">
<div class="container-fluid">
<div class="row">
<div class="col-4">
<a class="navbar-brand" href="#">
<h1 class="display-3">Petitions</h1>
</a>
</div>
<div class="col-4">
<button type="button" class="btn btn-primary btn-lg">
Get Started
</button>
</div>
<div class="col-4">
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarResponsive"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">Начало</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Цел на компанията</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">За компанията</a>
</li>
</ul>
</div></div>
</div>
</div>
</nav>
<!-- Navigation -->
I Think you want to make something like this:
<nav class="navbar navbar-dark navbar-expand-md sticky-top" style="background-color: #000000;">
<div class="container-fluid">
<div class="row" style="width: 100%; margin-left: 0px; margin-right: 0px;">
<div class="col-4">
<a class="navbar-brand" href="#">
<h1 class="display-3">Petitions</h1>
</a>
</div>
<div class="col-4">
<button type="button" class="btn btn-primary btn-lg">
Get Started
</button>
</div>
<div class="col-4">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">Начало</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Цел на компанията</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">За компанията</a>
</li>
</ul>
</div></div>
</div>
</div>
</nav>
Whenever I click on the hamburger menu icon it collapses with the nav-items! what should I do to fix this issue now?
Navbar
<header>
<div class="container-fluid">
<div class="row">
<div class="col-12 col-sm-12">
<nav class="navbar navbar-toggleable-md fixed-top d-flex justify-content-center">
<a class="navbar-brand animated heartBeat delay-.5s" href="#home"><img class="img-fluid logo"
src="./Assets/Logos/LogoMakr_8A9Y2n.png" alt=""></a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse"
data-target="#vesco-menu" aria-controls="vesco-menu" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"><i class="fas fa-bars"
style="color:#fff; font-size: 30px; "></i>
</span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="vesco-menu">
<div class="navbar-nav nav nav-pills animated fadeInRight delay-1s">
<a class="nav-item nav-link active" href="#home">Home <span
class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#project">portfolios</a>
<a class="nav-item nav-link" href="#skills">skills</a>
<a class="nav-item nav-link" id="downlink" href="./Assets/RESUME.docx"
download>Resume</a>
<a class="nav-item nav-link" href="#testimonials">Testimonials</a>
<a class="nav-item nav-link" href="#contact">CONTACT ME</a>
</div>
</div>
</nav>
</div>
</div>
</div>
</header>
In my machine it works fine, I think the problem is in your custom CSS but I show one class that not exist in bootstrap 4 so I suggest you to replace it.
Replace navbar-toggleable-md with navbar-expand-md
I basically have a pretty simple question, but my portfolio will look better if I can make this simple addition.
I want my NavBar in bootstrap to be in 3 columns, essentially like the image I've mocked up below.
I currently have the base bootstrap navBar setup with the default code like so:
<!-- Navigation -->
<nav class="navbar navbar-expand-lg bg-white fixed-top">
<div class="container">
<a class="nav-link" href="#">my name goes here</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="#">about</a></li>
<li class="nav-item"><a class="nav-link" href="#">resume</a></li>
</ul>
</div>
</div>
</nav>
I can make a weird version look right with messing with padding and stuff, but I dont want that. The hardest part for me is understanding the responsive version, and having the one link on the left (work) and two links on the right (about, resume) merge into one dropdown navigation and have the 'my name goes here' become the header above it on mobile.
Any help, or a point in the right direction would be great.
Also, it can be assumed my CSS is the base bootstrap CSS.
Thanks
UPDATE
<!-- Navigation -->
<nav class="navbar navbar-light navbar-expand-md bg-success justify-content-between">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-nav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse dual-nav w-50 order-1 order-md-0">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link pl-0" href="#">work <span class="sr-only">work</span></a>
</li>
</ul>
</div>
Colin Grant
<div class="navbar-collapse collapse dual-nav w-50 order-2">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="">about</a></li>
<li class="nav-item"><a class="nav-link" href="">resume</a></li>
</ul>
</div>
</div>
This seems to work perfectly, any tips for makign it better?
Thanks
Following is how I did it using bootstrap 4. When screen size is <992px right side of the navbar will collapse into a button.
<nav class="navbar navbar-expand-lg navbar-dark bg_color_primary sticky-top d-flex justify-content-between ">
<div class="navbar-nav col-4 align-items-start ">
<div class="text-white bg_color_primary_light rounded-circle p-2">
Work
</div>
</div>
<div class="col-4 d-flex justify-content-center">
<a class="navbar-brand text-white brand_name " href="">
BrandName
</a>
</div>
<button class=" navbar-toggler ml-auto align-items-end" 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 col-4 " id="navbarNavDropdown">
<div class="navbar-nav ml-auto ">
<a class="nav-item nav-link" href="">About</a>
<a class="nav-item nav-link" href="">Resume</a>
</div>
</div>
</nav>