<nav class="navbar">
<ul class="navbar__list">
<li class="navbar__brand">
<img src="imgs/logo.webp" alt="logo" class="navbar__brand--logo" />
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Home</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">About</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Performance</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Get started</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">News</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Contact</a>
</li>
<div class="navbar__buttons">
<li class="navbar__item">
<a class="navbar__link" href="#">Sign up</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Login</a>
</li>
</div>
</ul>
</nav>
In the above code , I want the div with the class navbar__buttons to be floated to the right side and aligned vertically with the other navbar__item items .
what I already Have :
here is my css
width: 100%;
&__item {
display: inline-block;
font-weight: 700;
transform: translateY(-1rem);
&:not(:last-child) {
margin-right: 2rem;
}
}
&__brand {
display: inline-block;
margin-right: 2rem;
width: 14rem;
&--logo {
width: 100%;
}
}
&__buttons {
display: inline-block;
float: right;
}
I want the div with class navbar__buttons to be floated right and in the same row as the rest of the navbar items
Note : I'm using css/scss
Flexbox
ul {
list-style-type: none;
display: flex;
}
li {
padding: .25em;
}
li:nth-last-child(2) {
margin-left: auto;
}
<nav class="navbar">
<ul class="navbar__list">
<li class="navbar__brand">
<img src="imgs/logo.webp" alt="logo" class="navbar__brand--logo" />
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Home</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">About</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Performance</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Get started</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">News</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Contact</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Sign up</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Login</a>
</li>
</ul>
</nav>
You can achieve the layout you're looking for using flex CSS properties on your elements.
First, I'd tweak your HTML slightly by moving navbar__buttons outside of navbar__list:
<nav class="navbar">
<ul class="navbar__list">
<li class="navbar__brand">
<img src="http://placekitten.com/200/100" alt="logo" class="navbar__brand--logo" />
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Home</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">About</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Performance</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Get started</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">News</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Contact</a>
</li>
</ul>
<ul class="navbar__buttons">
<li class="navbar__item">
<a class="navbar__link" href="#">Sign up</a>
</li>
<li class="navbar__item">
<a class="navbar__link" href="#">Login</a>
</li>
</ul>
</nav>
This will allow you to utilize the flex properties as I outline below.
Displaying your navbar as flex allows you to utilize justify-content: space-between;, which essentially distributes the navbar's children evenly on the line, with the first element on the left and the last element on the right, thus pushing your navbar__buttons to the right side:
.navbar {
width: 100%;
display: flex;
justify-content: space-between;
}
From there, your navbar__buttons links would be aligned to the top (aka not aligned with your other nav links). So, you need to also add a few flex properties to your navbar__buttons:
.navbar__buttons {
display: flex;
align-items: flex-end;
}
Displaying navbar_buttons as flex allows you to use align-items: flex-end;, which aligns it's children to the bottom of the container, aligning them with the rest of your nav links.
Here's a working codepen example based on your code: https://codepen.io/mmshr/pen/eaOWPW
Related
Should this div not display my two rows one on top of the other? or am I missing something?
the rows called 'tabs' and 'main' are displaying side-to-tide within the column('main' on the left), rather than tabs on top main below
Content div:
<div class='row content'>
<div class='col-12' style='display:flex; flex-direction:column; justify-content: center;'>
<div class='row tabs' style='align-items: flex-start; width:100%; '>
<ul class="nav nav-tabs" style='display:flex; flex-direction:row; position:absolute; right:0;'>
<li class="nav-item">
<a class="nav-link active" href="#">Posts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Replies</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Media</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">More</a>
</li>
</ul>
</div>
<div class='row main' style='min-height:100px; width:100%;'>{{user.username}} 's profile </div>
</div>
</div>
CSS:
.content{
width: 103.5%;
min-height:50%;
display:flex;
flex-direction: column;
justify-content: center;
align-items:center;
background-color: #F3D5AE;
}
.tabs{
position: relative;
top:0%;
}
If I'm understanding correctly you really just want something like shown below. I'd suggest getting more familiar with the different utility classes bootstrap provides to avoid repetitive (and in many cases unnecessary) styles since your usage of flex and position etc isn't correct and could make your output cleaner in the process. Cheers
.example {
background-color: #F3D5AE;
}
.example2 {
padding: 1rem;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class='row example'>
<div class='col-12'>
<ul class="nav nav-tabs justify-content-end">
<li class="nav-item">
<a class="nav-link active" href="#">Posts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Replies</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Media</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">More</a>
</li>
</ul>
<div class="col-12 example2">
{{user.username}}'s profile
</div>
</div>
</div>
How do I make the words stay on same line?:
This is my cshtml - they share the same class.
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Reservations" asp-action="Index">Reservations</a>
</li>
<li class="nav-item">
<span class="nav-text text-dark">Hello #User.Identity.Name!</span>
</li>
align-self will help to make text center of its height.
ul {
display: flex;
justify-content: space-between;
list-style: none;
align-items: center;
}
li.nav-item {
align-self: center;
}
<ul>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Reservations" asp-action="Index">Reservations</a>
</li>
<li class="nav-item">
<span class="nav-text text-dark">Hello #User.Identity.Name!</span>
</li>
</ul>
Looking at the screen shot of the website you will see there is a large spacing between the first row and second row of menu items. I want to make this spacing as low as possible.
Here is the relevant css:
.gva-navigation {
width: 100%;
/* Spans the width of the page */
height: 50px;
margin: 0;
/* Ensures there is no space between sides of the screen and the menu */
z-index: 99;
/* Makes sure that your menu remains on top of other page elements */
position: relative;
}
#wrap {
height: 50px;
padding: 0;
margin: 0;
position: absolute;
/* Ensures that the menu doesn’t affect other elements */
#border-right: 1px solid #54879d;
}
.gva-navigation li {
height: 25;
width: auto;
/* Each menu item is 150px wide */
#float: left;
/* This lines up the menu items horizontally */
#text-align: center;
/* All text is placed in the center of the box */
list-style: none;
/* Removes the default styling (bullets) for the list */
padding: 0;
margin: 0;
}
.gva-navigation a {
display: block;
}
.gva-navigation>ul>li>ul {
display: none;
}
.gva-navigation>ul>li:hover>ul {
display: inline;
}
<div class="gva-navigation">
<ul id="wrap" class="clearfix gva_menu gva_menu_main">
<li class="menu-item menu-item--collapsed">
<a target="_self" href="en/Mission_and_Vision.html">
Mission and Vision</a>
</li>
<li class="menu-item menu-item--expanded">
<a target="_self" href="#">
Departments <span class="icaret nav-plus fa fa-angle-down"></span> </a>
<ul class="menu sub-menu" style="margin-top: -30px;">
<li class="menu-item">
</li>
<li class="menu-item">
<a target="" href="en/Economics.html">
ECONOMICS/ISLAMIC ECONOMICS</a>
</li>
<li class="menu-item">
<a target="" href="en/Finance.html">
FINANCE/ISLAMIC FINANCE</a>
</li>
<li class="menu-item">
<li class="menu-item menu-item--expanded">
<a target="" href="en/Training.html">
TRAINING </a>
</li>
<li class="menu-item mune-item--expanded">
<a target="" href="en/Information_Center.html">
INFORMATION CENTER </a>
</li>
<li class="menu-item mune-item--expanded">
<a target="" href="en/JOURNAL_OF_NEW_ECONOMICS.html">
JOURNAL OF NEW ECONOMICS </a>
</li>
</ul>
</li>
<li class="menu-item menu-item--expanded">
<a target="" href="#">
Teaching & Performance <span class="icaret nav-plus fa fa-angle-down"></span></a>
<ul class="menu sub-menu" style="margin-top: -30px;">
<li class="menu-item">
<a target="" href="en/Teaching_Approaches.html">
Teaching Approaches</a>
</li>
<li class="menu-item">
<a target="" href="en/Midway_Approach.html">
Midway Approach</a>
<li class="menu-item">
<a target="" href="en/Graduates_Profile.html">
Graduates Profile</a>
</li>
</ul>
</li>
<li class="menu-item menu-item--expanded">
<a target="_self" href="#">
Admissions <span class="icaret nav-plus fa fa-angle-down"></span> </a>
<ul class="menu sub-menu" style="margin-top: -30px;">
<li class="menu-item">
<a target="" href="en/students.html">
Admission Requirements <span class="icaret nav-plus fa fa-angle-down"></span></a>
<ul class="menu sub-menu">
<li class="menu-item">
<a target="" href="en/3_Tracks_for_BA_Holders.html">
3 Tracks for BA Holders</a>
</li>
<li class="menu-item">
<a target="" href="en/Grades.html">
Grades</a>
</li>
<li class="menu-item">
<a target="" href="en/Language_Requirements.html">
Language Requirements</a>
</li>
<li class="menu-item">
<a target="" href="en/Admission_Course_Requirements.html">
Admission Course requirements</a>
</li>
</ul>
</li>
<li class="menu-item">
<a target="" href="https://obs.asbu.edu.tr/oibs/ogrenci/login.aspx">
Applications and Deadlines </a>
</li>
<li class="menu-item">
<a target="" href="https://www.asbu.edu.tr/tr/akademik-takvim">
International Students </a>
</li>
<li class="menu-item">
<a target="" href="en/student-work-forms.html">
Apply </a>
</li>
</ul>
</li>
<li class="menu-item menu-item--expanded">
<a target="_self" href="#">
Student <span class="icaret nav-plus fa fa-angle-down"></span> </a>
<ul class="menu sub-menu" style="margin-top: -30px;">
<li class="menu-item">
<a target="" href="en/students.html">
For Students </a>
</li>
<li class="menu-item">
<a target="" href="https://obs.asbu.edu.tr/oibs/ogrenci/login.aspx">
Student Information System </a>
</li>
<li class="menu-item">
<a target="" href="https://www.asbu.edu.tr/tr/akademik-takvim">
Academic Calendar </a>
</li>
<li class="menu-item">
<a target="" href="en/student-work-forms.html">
Student Work Forms </a>
</li>
</ul>
</li>
<li class="menu-item menu-item--expanded">
<a target="_self" href="#">
Course Requirements<span class="icaret nav-plus fa fa-angle-down"></span> </a>
<ul class="menu sub-menu" style="margin-top: -30px;">
<li class="menu-item">
<a target="" href="en/MA_and_PHD_in_Economics.html">
MA & PHD IN ECONOMICS/ISLAMIC ECONOMICS <br> (DOUBLE MAJOR)</a>
</li>
<li class="menu-item">
<a target="" href="en/MA_and_PHD_in_Finance.html">
MA & PHD IN FINANCE/ISLAMIC<br>FINANCE<br>(DOUBLE MAJOR)</a>
</li>
</ul>
</li>
<li class="menu-item menu-item--expanded">
<a target="_self" href="#">About <span class="icaret nav-plus fa fa-angle-down"></span></a>
<ul class="menu sub-menu" style="margin-top: -30px;
left: -100px;">
<li class="menu-item" style="display: inline-block">
<a target="_self" href="#">
Founding Stage<span class="icaret nav-plus fa fa-angle-down"></span> </a>
<ul class="menu sub-menu">
<li class="menu-item">
<a target="" href="en/background.html" style="white-space: nowrap;">
Background </a>
</li>
<li class="menu-item">
<a target="" href="en/objectives.html">
Objectives </a>
</li>
<li class="menu-item">
<a target="" href="en/name.html">
Name </a>
</li>
<li class="menu-item">
<a target="" href="en/approach.html">
Approach </a>
</li>
</ul>
</li>
<li class="menu-item">
<a target="_self" href="en/Faculty.html">
Faculty </a>
</li>
<li class="menu-item">
<a target="" href="https://asbu.edu.tr/tr/iletisim-bilgileri">
Contact Information </a>
</li>
<li class="menu-item">
<a target="" href="en/contact.html">
Contact Form </a>
</li>
<li class="menu-item">
<a target="" href="https://asbu.edu.tr/tr/ulasim">
Transportation </a>
</li>
<li class="menu-item">
<a target="" href="https://asbu.edu.tr/tr/contact/bilgi_edinme">
Getting Information </a>
</li>
<li class="menu-item">
<a target="_self" href="en/Stages_of_Implementation.html">
Stages of Implementation </a>
</li>
<li class="menu-item">
<a target="" href="en/Organisational_Chart.html">
Organisational Chart </a>
</li>
</ul>
</li>
<li class="menu-item menu-item--collapsed">
<a target="_self" href="en/Annotated_List_of_Courses.html">
Annotated List of Courses </a>
</li>
</ul>
</div>
How to reduce vertical spacing between top menu items and other menu items that wrap to the second line or row?
please, try to add this to your css:
#wrap {
height: 50px;
padding: 0;
margin: 0;
position: absolute; /* Ensures that the menu doesn’t affect other elements */
#border-right: 1px solid #54879d;
line-height:12px
}
You just need to change a line in your CSS. You have height: 25;, make it height: 25px. Try this code.
.gva-navigation li {
height: 25px;
}
I am trying to create a responsive navbar for mobile, but I am having trouble getting the link containers to resize properly. I also cannot seem to get the text to center itself vertically. I have tried using auto padding and margins in both cases, but they don't seem to be doing anything. I am using Bootstrap.
My questions are:
How do I center the text vertically within its container?
How do I get the width of each link's container to be the width of the text
How do I then get the spacing between each container to be the same, so that all together they fill the width of the screen?
HTML
<div class="container" id="nav-container-mobile">
<ul class="list-unstyled list-inline text-center d-flex" id="nav-list-mobile">
<li class="list-inline-item text-center nav-link-horizontal" id="nav-profile-link-mobile">
<a class="nav-link" href="#Profile">
<div class="nav-link-container-mobile">Profile</div>
</a>
</li>
<li class="list-inline-item text-center nav-link-horizontal" id="nav-experience-link-mobile">
<a class="nav-link" href="#Experience">
<div class="nav-link-container-mobile">Experience</div>
</a>
</li>
<li class="list-inline-item text-center nav-link-horizontal" id="nav-skills-link-mobile">
<a class="nav-link" href="#Skills">
<div class="nav-link-container-mobile">Skills</div>
</a>
</li>
<li class="list-inline-item text-center nav-link-horizontal" id="nav-project-link-mobile">
<a class="nav-link" href="#project">
<div class="nav-link-container-mobile">Projects</div>
</a>
</li>
<li class="list-inline-item text-center nav-link-horizontal" id="nav-contact-link-mobile">
<a class="nav-link" href="#Contact">
<div class="nav-link-container-mobile">Contact</div>
</a>
</li>
</ul>
</div>
CSS
#nav-container-mobile {
position: absolute;
width: 100%;
height: 70px;
padding: 0;
background: #292929;
z-index: 5;
}
#nav-list-mobile {
width: 100%;
height: 100%;
margin: 0;
vertical-align: middle;
}
.nav-link-horizontal {
height: 100%;
width: 15vw;
min-width: 50px;
}
.nav-link-container-mobile {
padding: auto;
height: 100%;
overflow-wrap: break-word;
}
.nav-link {
color: #aeaeae;
}
Any help or advice is appreciated.
JSFiddle
It would be simpler to use the Bootstrap 4 Nav Fill or Justify, and then just change the background color and other styles as needed.
https://www.codeply.com/go/WsWHHIfRlh
<div class="navbar navbar-expand navbar-dark" id="nav-container-mobile">
<div class="container-fluid">
<ul class="navbar-nav nav-fill w-100">
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">Experience</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Skills</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Projects</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
#nav-container-mobile {
width: 100%;
height: 70px;
padding: 0;
background: #292929;
z-index: 5;
}
.nav-link {
color: #aeaeae;
}
I'm making a dropdown menu in bootstrap.
Now I use in the li a a element where is described to toggle the dropdown menu.
But I actually want to put what is in the a element in to the li...
Because the whole li has to be clickable.
Hope you guys have I tip for me. ;)
<ul class="list-group">
<li class="list-group-item">
<a class="dropdown-toggle" data-toggle="dropdown">
Applicatie Ontwikkeling
</a>
<ul class="dropdown-menu">
<li class="list-group-item">HTML</li>
<li class="list-group-item">CSS</li>
<li class="list-group-item">jQuery</li>
</ul>
</li>
<li class="list-group-item">Netwerk Beheer</li>
<li class="list-group-item">Server Beheer</li>
</ul>
please apply 'dropdown' class to the li where you wants to add dropdown like this.
<ul class="list-group">
<li class="list-group-item dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">
Applicatie Ontwikkeling
</a>
<ul class="dropdown-menu">
<li class="list-group-item">HTML</li>
<li class="list-group-item">CSS</li>
<li class="list-group-item">jQuery</li>
</ul>
</li>
<li class="list-group-item">Netwerk Beheer</li>
<li class="list-group-item">Server Beheer</li>
You can just make the a tag take full width and then the entire li becomes clickable.
.dropdown-toggle{
display:inline-block;
width: 100%;
cursor: pointer;
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<ul class="list-group">
<li class="list-group-item">
<a class="dropdown-toggle" data-toggle="dropdown">
Applicatie Ontwikkeling
</a>
<ul class="dropdown-menu">
<li class="list-group-item">HTML</li>
<li class="list-group-item">CSS</li>
<li class="list-group-item">jQuery</li>
</ul>
</li>
<li class="list-group-item">Netwerk Beheer</li>
<li class="list-group-item">Server Beheer</li>
</ul>