This is my navigation bar (uses Bootstrap 4):
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<nav class="navbar navbar-expand-lg navbar-light bg-light rounded-bottom" style="height: 60px;">
<a class="navbar-brand text-blue font-weight-bold nav-link">Car Shop</a>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
Cars
Engine
<button type="submit" class="btn" name="create" style="background-color: #ffec00!important; position: absolute; margin-right: 0px; right: 15px; top: 11px;">Log Out</button>
</div>
</div>
</nav>
So except the main title Cars Shop, there are three more items:
Cars (aligned from the left)
Engine (aligned from the left)
Log Out button (in the top right corner)
On desktop it looks good, but when I switch to mobile (or resize window appropriately), the three items disappear completely. Is there any way to make this navbar a bit more user friendly?
As far ad I understand the problem is that you are using a collapsed navbar without the ability to open it after it collapses. I fixed it like this for a collapsed menu (you will need to change up your style a bit to make it look good):
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<nav class="navbar navbar-expand-lg navbar-light bg-light rounded-bottom" style="height: 60px;">
<a class="navbar-brand text-blue font-weight-bold nav-link">Car Shop</a>
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<i class="fa fa-angle-double-down"></i>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<div class="navbar-collapse collapse" id="navbarSupportedContent">
Cars
Engine
<button type="submit" class="btn" name="create" style="background-color: #ffec00!important; position: absolute; margin-right: 3em; right: 15px; top: 11px;">Log Out</button>
</div>
</div>
</nav>
I would also recommend doing the CSS in a separate file if you aren't already and maybe try to use em, vh, vw instead of px.
Related
I have created navigation bar as follows:
<nav class="navbar navbar-expand-lg navbar-light bg-light rounded-bottom">
<a class="navbar-brand text-white font-weight-bold nav-link">Car Shop</a>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
Cars
Tools
<button type="submit" class="btn">Pay</button>
</div>
</div>
</nav>
Right now, all the elements are visually sorted from the left side of the screen. That is fine, except for the Pay button, which I would like to have in the right corner of the navigation bar. I tried doing so by adding
style="margin-right: 0px;
to it, but this doesn't seem to be working (it remains at the same place). Can you see my problem?
I used position: absolute; for your class called btn and made it 5px from the top and the right. You can adjust as you would like, but the top and right styling only works if you tell the html that the position is absolute.
.btn {
right: 5px;
top: 5px;
position: absolute;
}
<nav class="navbar navbar-expand-lg navbar-light bg-light rounded-bottom">
<a class="navbar-brand text-white font-weight-bold nav-link">Car Shop</a>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
Cars
Tools
<button type="submit" class="btn">Pay</button>
</div>
</div>
</nav>
I'm making a web page but I'm having a hard time making it responsive and fit my desires.
I'm making a login page with an alert box, the alert will only appear if the user types a wrong password or email.
What I want to happen is for the main div (flex-3) content to be centered on the page and when the alert (flex-2) appears for the page to not have a scroll wheel, so flex-3 kinda has to calculate the remaining height of the page and be centered, and obviously all of this has to work no matter the device resolution.
I tried doing this with flex div but the closest I got made so the alert increased the total height of the page, so it would have a scroll wheel with no content at the bottom.
html,
body {
color: #fff;
height: 100%;
min-height: 100%;
}
.flex-1 {
flex: 1;
background-color: red;
}
.flex-2 {
display: flex;
background-color: green;
}
.flex-3 {
display: flex;
background-color: black;
}
<html>
<head>
<!-- import bootstrap css -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<!-- import jquery and bootstrap -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
</head>
<body class="d-flex flex-column">
<header>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<a class="navbar-brand" href="#">
<img src="" class="d-inline-block align-top" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id='navbarNav'>
<ul class="navbar-nav navbar-right">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
</ul>
</div>
</nav>
</header>
<main class="flex-1">
<div class="flex-2 d-flex alert-test">
<h1>TEST</h1>
</div>
<div class="flex-3 d-flex justify-content-center align-items-center">
<h1>TEST</h1>
</div>
</main>
</body>
</html>
This is how I made your solution working.
Added display: flex; flex-direction: column; to flex-1 to make the 2nd point working.
Added flex-grow: 1 to flex-3 class to make the dive stretch in remaining area.
Only by adding display: flex to the parent class flex-1, the flex grow property of child class, flex-3 works.
Hope this is the solution that you are looking for.
html,
body {
color: #fff;
height: 100%;
min-height: 100%;
}
.flex-1 {
display: flex;
flex-direction: column;
flex: 1;
background-color: red;
}
.flex-2 {
display: flex;
background-color: green;
}
.flex-3 {
display: flex;
flex-grow: 1;
overflow: auto;
background-color: black;
}
<!-- import bootstrap css -->
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
/>
<!-- import jquery and bootstrap -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<body class="d-flex flex-column">
<header>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<a class="navbar-brand" href="#">
<img src="" class="d-inline-block align-top" alt="" />
</a>
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarNav"
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div
class="collapse navbar-collapse justify-content-end"
id="navbarNav"
>
<ul class="navbar-nav navbar-right">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
</ul>
</div>
</nav>
</header>
<main class="flex-1">
<div class="flex-2 d-flex alert-test">
<h1>flex-2 TEST</h1>
</div>
<div class="flex-3 d-flex justify-content-center align-items-center">
<h1>flex-3 Test</h1>
</div>
</main>
</body>
I'm using a Bootstrap 4 navbar and added a left-border of a different color for design purposes.
This has the unforunate side-effect of causing the container of the navbar to not be lined up with the container of the main content.
I'm trying to offset the inner container 80px to compensate for the border, but when I try adjusting the position it obviously messes up the rest of the layout.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.navbar {
border-left: 80px solid red;
}
.navbar .container {
left: 80px; /* something like this */
}
</style>
</head>
<body>
<div class="content-wrapper">
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand"
href="/">Site</a>
<button class="navbar-toggler collapsed"
type="button"
data-toggle="collapse"
data-target="#mainMenu"
aria-controls="navbarsExampleDefault"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="icon-bar top-bar"></span>
<span class="icon-bar middle-bar"></span>
<span class="icon-bar bottom-bar"></span>
</button>
<div class="collapse navbar-collapse"
id="mainMenu">
<div class="form-inline ml-auto">
<label class="sr-only"
for="search-text">Search</label>
<div class="input-group mr-2 mb-2 mb-sm-0">
<input type="text"
class="form-control"
id="search-text"
placeholder="search...">
<div class="input-group-append">
<a href="/search/"
type="button"
id="search-button"
class="btn btn-light">
<i class="fas fa-search"></i>
</a>
</div>
</div>
<a href="/account/login"
class="btn btn-outline-light">log in</a>
<a href="/account/signup"
class="btn btn-info ml-2">sign up</a>
</div>
</div>
</div>
</nav>
<div class="container">
<ol class="breadcrumb my-4">
<li class="breadcrumb-item active">Bread crumbs</li>
</ol>
<h1>and some content</h1>
</div>
</body>
</html>
CodePen
You can add padding-right: 80px; to .navbar to push it back.
Not sure if I understood correctly but you can try:
.navbar {
border-left: 80px solid red;
}
.navbar .container {
left: 80px; /* something like this */
margin-left:0px !important
}
I want to center align the navigation links from Bootstrap but since I'm not using the list structure, all solutions don't work.
<section id="menuNavigation">
<div class="container-fluid">
<nav class="navbar navbar-expand-lg">
<button class="navbar-toggler" type="´button" data-toggle="collapse" data-target="#navbarHeader">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarHeader">
<ul class="navbar-nav">
Uniongs
Sobre
Seja Assinante
Blog
Publicidade
</ul>
</div>
</nav>
</div>
</section>
I tried everything: text-center, text-align: center, justify-content-center and nothing works.
Your HTML is invalid. ul can only have li as children. Try using a div instead.
Then use the flexbox helper classes available to you in BS4.
<div class="navbar-nav d-flex justify-content-center">
Then we just make the menu full width by adding flex:1. The reason the list items wouldn't center is because the menu was not full width and itself, left aligned.
View in Full Page mode.
.navbar-nav {
flex: 1;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<section id="menuNavigation">
<div class="container-fluid">
<nav class="navbar navbar-expand-lg">
<button class="navbar-toggler" type="´button" data-toggle="collapse" data-target="#navbarHeader">
<span class="navbar-toggler-icon">Toggle</span>
</button>
<div class="collapse navbar-collapse " id="navbarHeader">
<div class="navbar-nav d-flex justify-content-center">
Uniongs
Sobre
Seja Assinante
Blog
Publicidade
</div>
</div>
</nav>
</div>
</section>
Just CSS code added. hope this help you.
.navbar-nav {
text-align: center;
width: 100%;
float: left;
display: inline-block;
}
.nav-link {
float: none;
display: inline-block;
padding:0 10px;
}
<section id="menuNavigation">
<div class="container-fluid">
<nav class="navbar navbar-expand-lg">
<button class="navbar-toggler" type="´button" data-toggle="collapse" data-target="#navbarHeader">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarHeader">
<ul class="navbar-nav">
Uniongs
Sobre
Seja Assinante
Blog
Publicidade
</ul>
</div>
</nav>
</div>
</section>
In my project, I have implemented bootstrap in order to create a navbar. This works successfully, and the navbar is fully responsive.
When the screen reaches a certain size, the hamburger icon appears which allows users to select navbar options.
After a user presses the hamburger icon, I want a little box/div to appear directly below. I have performed a media query so that the box does not appear when the hamburger icon disappears.
However what I want to implement is that when the user rescales the window, I want the div box to move along with the hamburger icon.
Here is my existing code:
<nav style="height: 80px;" class="navbar navbar-expand-lg navbar-dark bg-dark">
<img src="{% static 'myicon.png' %}" style="margin-left: -15px;" width="99px" height="91px" class="navbar-brand bIcon" alt="Image of scissors and comb">
<div class="navbar-brand" style="width: 1px; left: 100px; bottom: 1px; position: absolute; height: 77px; border: 1px solid #454545;"></div>
<span class="navbar-brand" style="position: absolute; top: 16px; left: 125px; font-size: 26px; letter-spacing: 1px;" >Test</span>
<button style="margin-top: -16px;" 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">
// HERE IS THE DIV/BOX I AM TALKING ABOUT =>
<div class="collapseBox" style="width: 100px; margin-left: 100px; height: 100px; border: 1px solid white;"></div>
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Sign Up <span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>
Does anybody know how to implement this functionality?
Thank you.
A few things I did:
your navigation has the class navbar-expand-lg which means that burger menu disappears on sizes lg and above... so we assigned the class d-lg-none to our div collapseBox
you wanted this div directly under the burger menu, so we get position:absolute for this
next, the burger menu has a margin of 16px to its right (due to margin on the nav element), so we move our div to the right by 16px;
the height of the nav is 80px, so we move our div down by 80px also
working snippet below:
.collapseBox {
width: 100px;
margin-left: 100px;
height: 100px;
background-color: pink;
border: 1px solid red;
position: absolute;
right;
right: 16px;
top: 80px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<nav style="height: 80px;" class="navbar navbar-expand-lg navbar-dark bg-dark">
<img src="{% static 'myicon.png' %}" style="margin-left: -15px;" width="99px" height="91px" class="navbar-brand bIcon" alt="Image of scissors and comb">
<div class="navbar-brand" style="width: 1px; left: 100px; bottom: 1px; position: absolute; height: 77px; border: 1px solid #454545;"></div>
<span class="navbar-brand" style="position: absolute; top: 16px; left: 125px; font-size: 26px; letter-spacing: 1px;">Test</span>
<button style="margin-top: -16px;" 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">
// HERE IS THE DIV/BOX I AM TALKING ABOUT =>
<div class="collapseBox d-lg-none"></div>
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Sign Up <span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>