Underlining the first 5 elements in css - html

I am beginner webdeveloper. I use my project in Bootstrap 4.
I have menu with underline animation. It's work fine.
I have this code (menu and css):
.navbar-light .navbar-nav .nav-link {
color: #ffffff;
font-size: 1rem;
font-family: "Now Medium";
margin-top: 7px;
}
#media (min-width: 994px) {
.navbar-light .navbar-nav .nav-link {
color: #ffffff;
font-size: 1rem;
font-family: "Now Medium";
margin-top: 7px;
display: inline;
position: relative;
overflow: hidden;
}
.navbar-light .navbar-nav .nav-link:after {
content: "";
position: absolute;
z-index: -1;
right: 0;
width: 0;
bottom: -5px;
background: #0ad3f1;
height: 2px;
transition-property: width;
transition-duration: 0.2s;
transition-timing-function: ease-out;
}
.navbar-light .navbar-nav .nav-link:hover:after,
.navbar-light .navbar-nav .nav-link:focus:after,
.navbar-light .navbar-nav .nav-link:active:after {
left: 0;
right: auto;
width: 100%;
}
}
<nav class="navbar navbar-expand-lg text-body px-md-0 pb-md-0 navbar-light w-100 pt-lg-0">
<a class="navbar-brand" href="/">
<img src="images/logo.svg" class="brand-logo pb-2 pt-3 pt-md-0" title="logo">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarmenu"
aria-controls="navbarmenu" aria-expanded="false" aria-label="Toggle navigation">
<span class="line"></span>
<span class="line"></span>
<span class="line"></span>
</button>
<div class="collapse navbar-collapse" id="navbarmenu">
<ul class="navbar-nav">
<li class="nav-item d-block d-lg-none d-xl-block text-center">
<a class="nav-link active" href="#">Start</a>
</li>
<li class="nav-item text-center">
<a class="nav-link" href="#">5</a>
</li>
<li class="nav-item text-center">
<a class="nav-link" href="#">4</a>
</li>
<li class="nav-item text-center">
<a class="nav-link nav-link-selected" href="#">3 </a>
</li>
<li class="nav-item text-center">
<a class="nav-link" href="#">2</a>
</li>
<li class="nav-item mx-xl-4 mb-2 mb-md-0 text-center">
<a class="nav-link order-visit" href="#">1</a>
</li>
<li class="nav-item text-center text-lg-right">
123
</li>
<li class="nav-item text-center d-inline-block d-lg-none language-box2">
abc
</li>
</ul>
</div>
</nav>
It's work fine, but I want underline animation for only first 4 elements in this menu.
I would like the current functionality to remain the same, but only for the first 4 items of my menu
How can I make it?
Please help me.

You haven't specified which selectors you want to emphasize, but I'm guessing it's navbar-nav li. I'll write you the rules for how to style the first 4 elements of many:
.navbar-nav li:nth-child(1),
.navbar-nav li:nth-child(2),
.navbar-nav li:nth-child(3),
.navbar-nav li:nth-child(4) {
/*here you specify the styles you need for underlining*/
}

Related

swap div position and margin-top dropdown menu

first question, how to swap two divs, i want the image on the left and the text next to it
https://codepen.io/madaffakiren/pen/PomedWx
2nd question, I want to lower the "dropdown" but when I do it with margin-top then the "dropdown" disappears on hover, how to assign this blind spot (https://i.imgur.com/8mpN8BL.png) to dropdown?
HTML:
<!-- ======== Navbar ======= -->
<nav class="navbar sticky-top navbar-expand-lg navbar-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="/"><img src="img/logo4.svg" width="120px" height="32px" alt="logo"></a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link " href="/" data-target=".navbar-collapse.show">XXX</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown"
data-target=".navbar-collapse.show">Sample</a>
<ul class="dropdown-menu">
<a class="dropdown-item" href="#">Sample</a>
<a class="dropdown-item" href="#">Sample</a>
</ul>
</li>
</li>
<li class="nav-item">
<a class="nav-link " href="#" data-target=".navbar-collapse.show">XXX</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" data-target=".navbar-collapse.show">XXX</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" data-target=".navbar-collapse.show">XXX</a>
</li>
</ul>
</div>
</div>
</nav>
CSS:
.navbar {
padding: 10px 0;
background-color: #37517e;
}
.navbar .nav-item {
margin: 0;
padding: 0;
}
.navbar .nav-item .nav-link {
font-size: 15px;
font-weight: 500;
color: #ffffff;
padding: 0;
margin-left: 35px;
transition: all 0.3s ease-in-out;
}
.navbar .nav-item .nav-link:hover {
transform: translateY(-3px);
color: #03b0d5;
}
.navbar .nav-item .dropdown-menu {
border: none;
margin: 20px 0;
background-color: blue;
}
.navbar .nav-item:hover .dropdown-menu {
display: block;
}

Bootstrap navbar-expand-md height increasing #768px - 992px

I'm having a slight problem with the navbar-expand-md. From 768px to 992px the navbar height increases and the navbar-brand gets pushed a little down. It's a minor issue, but it's really bugging me and I can't seem to solve this problem. My skills are not to proficient so I'm at the end of my wit and would appreciate any help. Thanks in advance - happy holidays, stay healthy.
The issue described above can be seen here:
https://jsfiddle.net/w3do6z74/
Navbar-code:
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">brandname</a>
<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" href="#"><img src="imgs/category_bar_history.png" class="category-bar">History</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><img src="imgs/category_bar_nature.png" class="category-bar">Nature</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><img src="imgs/category_bar_travel.png" class="category-bar">Travel & Food</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><img src="imgs/category_bar_arts.png" class="category-bar">Arts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><img src="imgs/category_bar_science.png" class="category-bar">Science</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><img src="imgs/category_bar_crime.png" class="category-bar">Crime</a>
</li>
<li class="nav-item">
<a class="nav-link nav-custom-link" href="#">HYPE</a>
</li>
</ul>
</div>
</div>
</nav>
Custom-Css:
.nav-custom-link {
font-weight: bold;
font-style: italic;
}
.navbar {
border-bottom: 1px solid black;
margin-bottom: 12px;
padding-top: 5px;
padding-bottom: 5px;
}
.navbar-brand {
font-family: 'Audiowide', cursive;
}
.category-bar {
padding-right: 4px;
}
.navbar-toggler {
padding: 0.2rem 0.55rem;
font-size: 1.1rem;
}
.navbar-toggler:focus {
box-shadow: 0 0 0 0;
}
If you check the CSS in dev tools, you can see that one of the things changing on the ul element is the bottom margin. It's 0.5rem by default and 0 if the minimum width is larger than 992px:
#media (min-width: 768px)
.navbar-expand-md .navbar-nav {
flex-direction: row;
}
.mb-2 {
margin-bottom: .5rem!important;
}
#media (min-width: 992px)
.mb-lg-0 {
margin-bottom: 0!important;
}
It's because you added mb-2 and mb-lg-0 classes to your ul element:
<ul class="navbar-nav me-auto mb-2 mb-lg-0"></ul>
To fix this, you can add mb-0 and remove mb-lg-0:
<ul class="navbar-nav me-auto mb-0"></ul>

Cannot make Bootstrap navbar transparent

I have been trying to make my navbar transparent but so far nothing has worked for me. Can someone teach me how to do it? I assume it has something to do with the space that it is taking up in regards to the body content, but I am not sure what can be done as I have already tried reversing the div tags to be outside of the body.
This is my desired result :
Fiddle : https://jsfiddle.net/zr1qh780/
My HTML :
<body>
<div id="container">
<!-- Navigation menu -->
<header>
<nav class="my-nav navbar navbar-light navbar-expand-lg">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-
target="#navbarsExample08" aria-controls="navbarsExample08" aria-expanded="false" aria-
label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-md-center" id="navbarsExample08">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="index.html" id="dropdown08" data-toggle="dropdown" aria-
haspopup="true" aria-expanded="false">ACTIVITÉS</a>
<div class="dropdown-menu" aria-labelledby="dropdown08">
<a class="dropdown-item" href="rafting.html">Rafting</a>
<a class="dropdown-item" href="canyoning.html">Canyoning</a>
<a class="dropdown-item" href="saut-parachute.html">Saut en parachute</a>
<a class="dropdown-item" href="soufflerie.html">Simulation de chute libre</a>
<a class="dropdown-item" href="saut-elastique.html">Saut à l’élastique</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">OFFRES</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ÉVÉNEMENTS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">À PROPOS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ESPACE HANDICAP</a>
</li>
<li class="nav-item">
<a class="nav-link contact" href="contact.html">CONTACT</a>
</li>
</ul>
</div>
<div class="hamburger">
<span style="font-size:30px;cursor:pointer;color: white;" onclick="openNav()">☰</span>
</div>
</nav>
</header>
<div id="myNav" class="overlay">
×
<div class="bar overlay-content">
ACTIVITÉS
OFFRES
ÉVÉNEMENTS
À PROPOS
ESPACE HANDICAP
CONTACT
</div>
</div>
My CSS:
.logo {
margin-right:5px;
}
.my-nav{
display: flex;
align-items: center;
justify-content: space-around;
padding: 8px;
}
.navbar-light .navbar-nav .nav-link {
color: white;
}
.navbar-nav > li {
padding-left:25px;
padding-right:45px;
float:none;
display:table-cell;
text-align:center;
font-size: 15px;
font-weight: 500;
}
.navbar-light .navbar-nav .nav-link:focus, .navbar-light .navbar-nav .nav-link:hover {
color: #fc3218;
}
.nav-link:active {
color: #fc3218;
}
.navbar {
background: grey
}
.dropdown-menu {
color: white;
background-color: #fc3218;
}
.dropdown-item {
color: white;
font-size: 14px;
}
.navbar-collapse {
flex-grow: 0.3;
}
Have you tried something like this?
navbar{
background-color: transparent;
}
If that doesn't work, add !important to break the predefined bootstrap styles
Set the opacity of the container for nav bar to 0.
Note: Place the elements of nav bar in different div otherwise the text in nav bar will also get effected.

Navbar Burger (Dropdown) pushes content down?

When my navbar collapses the burger menu shows up. Whenever I click on it all the content below gets pushed down and leaves me with a messed up homepage.
My Navbar:
<section class="nav-bar">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#"><img src="WildfireGraphic1.png" class="rounded float-left" alt="icon1"></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" id="navbarNav">
<ul class="navbar-nav ml-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="#">Film</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Info</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Über uns</a>
</li>
</ul>
</div>
</nav>
</section>
My CSS:
body{
text-align: justify !important;
}
#nav-bar{
position: fixed;
left: 0px;
top: 0px;
width: 100px;
}
.navbar-brand img{
height: 40px;
padding-left: 30;
}
.navbar-nav li{
padding: 0 10px;
}
.navbar-nav li a{
float: right;
text-align: left;
}
.nav-bar ul li a:hover{
color: #000000!important;
}
.navbar{
background: #fff;
}
.navbar-toggler{
border: none!important;
}
.nav-link{
color: #555!important;
font-weight: 600;
font-size: 16px;
}
I have tried using the Z-Index method but no luck so far. Maybe I did something wrong?
https://jsfiddle.net/Lqzs1jdw/8/
Thanks in advance.
You have just make a typo, change the # to . will fix the issue
Example:
.nav-bar{
position: fixed;
width: 100%;
}
https://jsfiddle.net/aslamb/sfoavupd/2/

bootstrap hover moving all the links

I'm playing around with bootstrap and I have some problem. I created a navigation with few links and I want bottom border to appear when I hover the link. I made it and now, when I hover, links are "moving" to the top, even though I didn't give them any margin or padding...
Here is JSFiddle with the example, you need to resize the window of outcome to be able to see entire menu.
https://jsfiddle.net/zhzmz6fa/
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<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="#">O nas</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Opis</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Kontakt</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Archiwum</a>
</li>
</ul>
</div>
.navbar {
font-family: sans-serif;
background-color: orangered;
}
.navbar-toggler {
border: none;
}
.nav-item {
padding-left: 1.5rem;
}
.nav-link:hover,
.nav-link:active {
border-bottom: 2px solid black;
transition: border-bottom .5s;
}
Borders count extra in the calculation of width. So if you have
width: 50px;
border-right: 1px solid black;
The element will be 51px wide.
This is also what happens with your code. The solution would be to always give it a border, but have it transparent.
.nav-link {
border-bottom: 2px solid transparent;
}
An alternative to border is a pseudoelement.
Style it as you need, set it's opacity to 0. On :hover, or :active change the opacity to 1.
.navbar {
font-family: sans-serif;
background-color: orangered;
}
.navbar-toggler {
border: none;
}
.nav-item {
padding-left: 1.5rem;
}
.nav-link {
position: relative;
}
.nav-link:after {
content: '';
position: absolute;
left: 0;
right: 0;
display: block;
height: 2px;
opacity: 0;
background: black;
}
.nav-link:hover:after,
.nav-link:active:after {
opacity: 1;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-light fixed-top">
<img src="http://via.placeholder.com/250x100" class="navbar-brand">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<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="#">O nas</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Opis</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Kontakt</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Archiwum</a>
</li>
</ul>
</div>
</nav>