Bootstrap navbar positioning - html

I'm fairly new to bootstrap so don't really understand all the classes. I've been trying to play around with them for the past day or add my own new ones to get this to work but its no use.
Basically in the following index page I have an input field and search/submit button beside it. The search button however goes under the input, and I wish for it to be beside it. Anyone help?
<!-- Navigation -->
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="index.php">L'amour</a>
<button class="navbar-toggler navbar-toggler-right" 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">
<li class="nav-item float-left">
<a class="nav-link float-left" href="order.php">Contact Us</a>
</li>
<li class="nav-item float-left">
<a class="nav-link float-left" href="testimonials.php">Testimonial</a>
</li>
<li class="nav-item float-left">
<form method="post">
<div class="form-group">
<input class="form-control" type="text" name="search" placeholder="Search for wedding...">
<input method="post" name="submit" class="btn w_search form-control" type="submit" value="submit" >
</div>
</form>
<li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item ">
<a class="nav-link" href="order.php">Order Wesbite</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownBlog" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Account
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownBlog">
<a class="dropdown-item" href="signIn.php">Login</a>
<a class="dropdown-item" href="sign-up">Sign up</a>
<a class="dropdown-item" href="homeUser.php">Account details</a>
<a class="dropdown-item" href="logout.php">Logout</a>
</div>
</li>
</ul>
</div>
</div>
</nav>

A form example is shown in the Navbar documentation...
https://www.codeply.com/go/dFcxxvzjly
<li class="nav-item">
<form method="post" class="form-inline">
<input class="form-control" type="text" name="search" placeholder="Search for wedding...">
<input method="post" name="submit" class="btn w_search form-control" type="submit" value="submit">
</form>
</li>

Related

How to leave search bar out of the collapsed navbar bootstrap 5

I want my navbar to be the exact layout I have now, but when the navbar is collapsed I want the searchbar between the logo and toggle button, is there anyway to keep the remaining layout but still put the search bar between?
<nav class="navbar navbar-expand-lg" style="background-color: #121212">
<div class="container-fluid">
<a class="navbar-brand" href="#">Narton</a>
<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 class="collapse navbar-collapse" id="navbarNavAltMarkup">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Albums</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Artists</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Discover</a>
</li>
</ul>
<form class="d-flex w-100 p-2" role="search">
<input
type="text"
class="form-control"
placeholder="Search"
aria-label="Search"
aria-describedby="basic-addon1"
/>
</form>
<button type="button" class="btn btn-outline-secondary py-2">Login</button>
<ul class="navbar-nav sm-icons">
<a class="nav-link" href="https://twitter.com/"><i class="bi bi-twitter"></i></a>
<a class="nav-link" href="#"><i class="bi bi-instagram"></i></a>
<a class="nav-link" href="#"><i class="bi bi-tiktok"></i></a>
<a class="nav-link" href="#"><i class="bi bi-facebook"></i></a>
</ul>
</div>
</div>
</nav>
this is the html code for my navbar
css code for my Navbar (I only put in what I thought was necessary)
.sm-icons {
flex-direction: row;
}
.sm-icons .nav-link{
padding-right: 1em;
}

Page contents in Navbar not filling the screen:

Click here for image of problem
Basically I sourced the code from getbootstrap.com but the search bar and search button are not being right-aligned in the navbar. Have tried to selectively align the search option but to no avail. Would live it if anyone helped. Thank you.
Here is the code:
```
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</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 active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
```
You can give margin and padding to the linking icons/navigation items to occupy more space of the webpage.
Try enclose your items ul and form inside a div with d-flex
<div class="collapse navbar-collapse d-flex">
<div class="d-flex align-items-start">
<ul>
<li>...
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
<div class="d-flex ">
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</div>

Django + Bootstrap navbar button and search field issue

I know that there are similar questions, but I tried and searched hard and didn't find a solution for my problem. I am using Django + bootstrap to complete an exercise which include a navbar. The search button is stubbornly staying below the search field.
I would just like to align them, as in this example :
Here my code :
'''
</div>
<div class="collapse navbar-collapse justify-content-center">
<a class="navbar-brand" href="#">Navbar</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>
<form class="form-inline my-2 my-lg-0 col-3">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
<div class="collapse navbar-collapse justify-content-center" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
'''
Don't know if it's a naive issue, but I am really struggling and loosing time with it.
Many thanks
This is because the form-control class in the search input enforces a display: block;.
There are several solutions, depending of your needs: you can make the input inline, you can use flexbox behavior by adding the d-flex class to your form, or you can do something like that:
<form class="row g-3">
<div class="col-auto">
<input class="form-control" type="search" placeholder="Search">
</div>
<div class="col-auto">
<button type="submit" class="btn btn-outline-success mb-3">Search</button>
</div>
</form>
(btw, you can read the official docs about gutters if necessary)
Finally, please think about giving a runnable code snippet in your future questions :)

Boostrap 4.5.2 Navbar Dropdown appearing in Wrong Location

I have created a navbar using Boostrap 4.5.2. In my navbar, I want to have a dropdown that goes with the tab "browse". My browse tab has three options associated with it. When I click on the "browse" tab; my dropdown menu appears with the correct content but it appears at the very start of the navbar. Any help on fixing this issue would be greatly appreciated. Below I have attached my navbar code and a gif of what happens.
<div class="row d-flex align-items-center" id="top-bar">
<!--Website title-->
<div class="col-auto"><h1>My Website</h1></div>
<!--nav bar-->
<div class="col-auto">
<nav class="navbar navbar-expand-lg" id="nav">
<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 active">
<a class="nav-link" href="index.php">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="./about.php">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./advanced_search.html">Advanced Search</a>
</li>
<li class="nav-item nav-dropdown">
<a
class="nav-link dropdown-toggle"
href="#"
id="navbarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
Browse
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="./Part01_PostList.php"
>Posts</a
>
<a class="dropdown-item" href="./Part02_SinglePost.php?post_id=1"
>Images</a
>
<a class="dropdown-item" href="./Part03_SingleImage.php?image_id=1"
>Users</a
>
</div>
</li>
</ul>
</div>
</nav>
</div>
<!--Utility dropdown-->
<div class="nav-dropdown mx-auto" id="utility-nav">
<i class="fa fa-cog btn btn-secondary" type="button" id="utility-btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></i>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="./favorites-list.php">Favorites List</a>
<a class="dropdown-item" href="#">Account</a>
<a class="dropdown-item" href="#">Register</a>
<a class="dropdown-item" href="#">Login</a>
</div>
</div>
<!--Search bar-->
<div class="col-auto ml-auto">
<form action="./Part04_Search.php" method="POST" class="form-inline my-2 my-lg-0" id="search-bar">
<input
class="form-control mr-sm-2"
type="text"
name="title-alt"
placeholder="Search"
aria-label="Search"
/>
<button class="btn-primary" id="search-btn" type="submit">
Search
</button>
</form>
</div>
</div>
https://i.gyazo.com/49fd1ebe460510762a683ab9aff1349f.mp4
Your menu is over towards the left because in the list item, you’re using the class nav-dropdown, but that’s not a Bootstrap class. If you change it to dropdown (or dropleft or dropright), then the dropdown menu will be under the Browse button.
Was:
<li class="nav-item nav-dropdown">
Change to:
<li class="nav-item dropdown">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/js/bootstrap.bundle.min.js"></script>
<div class="row d-flex align-items-center" id="top-bar">
<!--Website title-->
<div class="col-auto">
<h1>My Website</h1>
</div>
<!--nav bar-->
<div class="col-auto">
<nav class="navbar navbar-expand-lg" id="nav">
<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 active">
<a class="nav-link" href="index.php">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="./about.php">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./advanced_search.html">Advanced Search</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Browse
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="./Part01_PostList.php">Posts</a>
<a class="dropdown-item" href="./Part02_SinglePost.php?post_id=1">Images</a>
<a class="dropdown-item" href="./Part03_SingleImage.php?image_id=1">Users</a>
</div>
</li>
</ul>
</div>
</nav>
</div>
<!--Utility dropdown-->
<div class="nav-dropdown mx-auto" id="utility-nav">
<i class="fa fa-cog btn btn-secondary" type="button" id="utility-btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></i>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="./favorites-list.php">Favorites List</a>
<a class="dropdown-item" href="#">Account</a>
<a class="dropdown-item" href="#">Register</a>
<a class="dropdown-item" href="#">Login</a>
</div>
</div>
<!--Search bar-->
<div class="col-auto ml-auto">
<form action="./Part04_Search.php" method="POST" class="form-inline my-2 my-lg-0" id="search-bar">
<input class="form-control mr-sm-2" type="text" name="title-alt" placeholder="Search" aria-label="Search" />
<button class="btn-primary" id="search-btn" type="submit">
Search
</button>
</form>
</div>
</div>

Can't get bootstrap 4 navbar buttons to look right, when collapsed

Is there a way to either style the buttons in my navbar only when its collapsed or change the buttons to text when collapsed, cause right now it looks fine normally, but when collapsed, the buttons are placed right underneath each other and are not the same width.
It's the last 2 buttons and searchbar that i need to somehow style or set margin for.
i have tried looking in the bootstrap documentation and guides on w3schools, but haven't been able to find any real solutions.
Sorry if this is not asked the correct way or i'm missing something, it's my first post.
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<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 active" href="/">Hjem</a>
</li>
<li class="nav-item">
<a class="nav-link " href="?page=new">Ny kunde</a>
</li>
<li class="nav-item">
<a class="nav-link " href="?page=allcustomers">Vis alle kunder</a>
</li>
<li class="nav-item">
<a class="nav-link " href="?page=settings">Opsætning</a>
</li>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item mr-sm-2">
<a class="btn btn-secondary navbar-btn btn-block" href="?page=invoice">Quick faktura</a>
</li>
<li class="nav-item mr-sm-2">
<form class="form-inline">
<div class="input-group">
<input type="text" class="form-control" placeholder="Søg" aria-label="Søg" name="search" aria-describedby="Søg">
<div class="input-group-append">
<button class="btn btn-secondary navbar-btn" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button>
</div>
</div>
</form>
</li>
<li class="nav-item">
<a class="btn btn-danger navbar-btn btn-block" href="?page=logout">Log ud</a>
</li>
</ul>
</div>
</div>
</nav>
A simple solution is to add the flex-row (flex-direction: row) class to the 2nd navbar-nav. This will allow the buttons and form to always layout horizontally (inline) in a row at all screen widths.
<ul class="navbar-nav flex-row">
<li class="nav-item mr-sm-2">
<a class="btn btn-secondary navbar-btn btn-block" href="?page=invoice">Quick faktura</a>
</li>
<li class="nav-item mr-sm-2">
<form class="form-inline">
<div class="input-group">
<input type="text" class="form-control" placeholder="Søg" aria-label="Søg" name="search" aria-describedby="Søg">
<div class="input-group-append">
<button class="btn btn-secondary navbar-btn" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button>
</div>
</div>
</form>
</li>
<li class="nav-item">
<a class="btn btn-danger navbar-btn btn-block" href="?page=logout">Log ud</a>
</li>
</ul>
https://www.codeply.com/go/Wbc4kRGCtO
Try this :
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<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 active" href="/">Hjem</a>
</li>
<li class="nav-item">
<a class="nav-link " href="?page=new">Ny kunde</a>
</li>
<li class="nav-item">
<a class="nav-link " href="?page=allcustomers">Vis alle kunder</a>
</li>
<li class="nav-item">
<a class="nav-link " href="?page=settings">Opsætning</a>
</li>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item mr-sm-2">
<a class="btn btn-secondary navbar-btn btn-block" href="?page=invoice">Quick faktura</a>
</li>
<li class="nav-item mr-sm-2">
<form class="form-inline">
<div class="input-group">
<input type="text" class="form-control" placeholder="Søg" aria-label="Søg" name="search" aria-describedby="Søg">
<div class="input-group-append">
<button class="btn btn-secondary navbar-btn" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button>
</div>
</div>
</form>
</li>
<li class="nav-item">
<a class="btn btn-danger navbar-btn btn-block" href="?page=logout">Log ud</a>
</li>
</ul>
</div>
</div>
</nav>
There are specific ways to apply styles to the Bootstrap elements using their classes and stuff, but you can allways create a css file with the classes names and stylizing them from there if you feel like it.
It's not the rigth way, there are a bunch of ways you should try that are more correct thant this, but it works.