Fixing a navbar to the top - html

Hello I found a nice navbar I'd like to use; but I don't know how to make it stick to the top ?
I tried to add position:fixed to .navigation but it is somehow messing things up. The logo is hidden in full screen and the menu can't be find in mobile view.
Here is the snippet url :
https://codepen.io/anon/pen/NYazoj
(function($) { // Begin jQuery
$(function() { // DOM ready
// If a link has a dropdown, add sub menu toggle.
$('nav ul li a:not(:only-child)').click(function(e) {
$(this).siblings('.nav-dropdown').toggle();
// Close one dropdown when selecting another
$('.nav-dropdown').not($(this).siblings()).hide();
e.stopPropagation();
});
// Clicking away from dropdown will remove the dropdown class
$('html').click(function() {
$('.nav-dropdown').hide();
});
// Toggle open and close nav styles on click
$('#nav-toggle').click(function() {
$('nav ul').slideToggle();
});
// Hamburger to X toggle
$('#nav-toggle').on('click', function() {
this.classList.toggle('active');
});
}); // end DOM ready
})(jQuery); // end jQuery
// Navigation Variables
$content-width: 1000px;
$breakpoint: 799px;
$nav-height: 70px;
$nav-background: #fff;
$nav-font-color: #0c71c3;
$link-hover-color: #2581DC;
$nav-hover-font-color: #fff;
// Outer navigation wrapper
.navigation {
height: $nav-height;
background: $nav-background;
}
article {
height:2000px;
}
// Logo and branding
.brand {
position: absolute;
padding-left: 20px;
float: left;
line-height: $nav-height;
text-transform: uppercase;
font-size: 1.4em;
a,
a:visited {
color: $nav-font-color;
text-decoration: none;
}
}
// Container with no padding for navbar
.nav-container {
max-width: $content-width;
margin: 0 auto;
}
// Navigation
nav {
float: right;
ul {
list-style: none;
margin: 0;
padding: 0;
li {
float: left;
position: relative;
a,
a:visited {
display: block;
padding: 0 20px;
line-height: $nav-height;
background: $nav-background;
color: $nav-font-color;
text-decoration: none;
&:hover {
background: $link-hover-color;
color: $nav-hover-font-color;
}
&:not(:only-child):after {
padding-left: 4px;
content: ' ▾';
}
} // Dropdown list
ul li {
min-width: 190px;
a {
padding: 15px;
line-height: 20px;
}
}
}
}
}
// Dropdown list binds to JS toggle event
.nav-dropdown {
position: absolute;
display: none;
z-index: 1;
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}
/* Mobile navigation */
// Binds to JS Toggle
.nav-mobile {
display: none;
position: absolute;
top: 0;
right: 0;
background: $nav-background;
height: $nav-height;
width: $nav-height;
}
#media only screen and (max-width: 798px) {
// Hamburger nav visible on mobile only
.nav-mobile {
display: block;
}
nav {
width: 100%;
padding: $nav-height 0 15px;
ul {
display: none;
li {
float: none;
a {
padding: 15px;
line-height: 20px;
}
ul li a {
padding-left: 30px;
}
}
}
}
.nav-dropdown {
position: static;
}
}
#media screen and (min-width: $breakpoint) {
.nav-list {
display: block !important;
}
}
#nav-toggle {
position: absolute;
left: 18px;
top: 22px;
cursor: pointer;
padding: 10px 35px 16px 0px;
span,
span:before,
span:after {
cursor: pointer;
border-radius: 1px;
height: 5px;
width: 35px;
background: $nav-font-color;
position: absolute;
display: block;
content: '';
transition: all 300ms ease-in-out;
}
span:before {
top: -10px;
}
span:after {
bottom: -10px;
}
&.active span {
background-color: transparent;
&:before,
&:after {
top: 0;
}
&:before {
transform: rotate(45deg);
}
&:after {
transform: rotate(-45deg);
}
}
}
// Page content
article {
max-width: $content-width;
margin: 0 auto;
padding: 10px;
}
<section class="navigation">
<div class="nav-container">
<div class="brand">
Logo
</div>
<nav>
<div class="nav-mobile"><a id="nav-toggle" href="#!"><span></span></a></div>
<ul class="nav-list">
<li>
Home
</li>
<li>
About
</li>
<li>
Services
<ul class="nav-dropdown">
<li>
Web Design
</li>
<li>
Web Development
</li>
<li>
Graphic Design
</li>
</ul>
</li>
<li>
Pricing
</li>
<li>
Portfolio
<ul class="nav-dropdown">
<li>
Web Design
</li>
<li>
Web Development
</li>
<li>
Graphic Design
</li>
</ul>
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
</section>
<article>
<h2>Navigation</h2>
<p>Responsive Dropdown Navigation Bar.</p>
<p>Want to see how it's made? Read the tutorial!</p>
</article>

To make Header Stick to the top Of browsers following CSS will work:
.navigation {
height: $nav-height;
background: $nav-background;
position: fixed;
top:0;
right: 0;
left: 0;
}
here is JsFiddle For your reference

Related

How can I centralize the dropdown menu and shrink the distance between its submenus?

I am relatively new to web development. I am having some inconveniences with the esthetic of the page. I would like to know how can I centralize and make the submenus closer to the parent menu.
I've tried padding, along many other code I've read searching what helped others.
I've read and tried several times unsuccessfully
/* Dropdown menu */
nav ul {
padding: 0px;
margin: 100px;
margin-right: 0px;
margin-left: 0;
list-style: none;
position: relative;
font-size: 25px;
background-color: white;
cursor: pointer;
}
nav ul li {
display: inline-block;
padding: 0 20px 0 20px;
}
nav a {
display: block;
padding: 0 10px;
line-height: 60px;
font-size: 20px;
text-decoration: none;
background-color: #FFFFFF;
color: black;
}
/* Hide Dropdown by Default*/
nav ul ul {
display: none;
position: absolute;
}
/* hover */
nav a:hover {
background-color: #FFFFFF;
color: #A4E5E0;
border: 1px solid gray;
display: block;
position: absolute;
left: 0;
}
/* Display Dropdown on Hover */
nav ul li:hover > ul {
display: inherit;
}
/* First Tier Dropdown */
nav ul ul li {
width: 350px;
float: none;
display: list-item;
position: absolute;
border: 1px solid gray;
}
<body>
<div id="container" style="position:absolute">
<header>
<nav>
<ul>
<li>
Head Count
<ul>
<li class="nav-item">#Html.ActionLink("Agregar nuevo Head Count", "CreateHeadCount", "Home", new { area = "" }, null) </li>
<li class="nav-item">#Html.ActionLink("Editar Head Count", "EditHeadCount", "Home", new { area = "" }, null) </li>
<li class="nav-item">#Html.ActionLink("Actualizar Grupo", "UpdateAllHC", "Home", new { area = "" }, null) </li>
</ul>
</li>
<li>
SPH
<ul>
<li class="nav-item">#Html.ActionLink("SPH Acumulada", "GetSPH", "Home", new { area = "" }, null) </li>
<li class="nav-item">#Html.ActionLink("Missing SPH", "MissingSPH", "Home", new { area = "" }, null) </li>
</ul>
</li>
<li>
Work Orders
<ul>
<li class="nav-item">#Html.ActionLink("Returned work orders", "ReturnedWO", "Home", new { area = "" }, null) </li>
<li class="nav-item">#Html.ActionLink("Work orders without movement", "GetWOWithoutMov", "Home", new { area = "" }, null) </li>
</ul>
</li>
<li>
Weekly Efficiency
<ul>
<li class="nav-item">#Html.ActionLink("Add Weekly Efficiency", "DowngradeTierLevel", "Home", new { area = "" }, null)</li>
</ul>
</li>
</ul>
</nav>
</header>
</div>
</body>
Overall look
I create a codesandbox with a solution based on your code
Your main problem is the usage of position absolute everywhere and forgetting to set the position using top/left properties. Also margin at bad level mishelp you.
/* Dropdown menu */
nav ul {
padding: 0px;
/*margin: 100px; /*why ?*/
/*margin-right: 0px;
margin-left: 0;*/
list-style: none;
position: relative;
font-size: 25px;
background-color: white;
cursor: pointer;
}
nav ul li {
display: inline-block;
padding: 0 20px 0 20px;
position: relative;
}
nav a {
display: block;
padding: 0 10px;
line-height: 60px;
font-size: 20px;
text-decoration: none;
background-color: #ffffff;
color: black;
}
/* Hide Dropdown by Default*/
nav ul ul {
display: none;
position: absolute;
top: 100%;
left: 0;
}
/* hover */
nav a:hover {
background-color: #ffffff;
color: #a4e5e0;
border: 1px solid gray;
display: block;
/*position: absolute;*/ /* not needed */
left: 0;
}
/* Display Dropdown on Hover */
nav ul li:hover > ul {
display: inherit;
}
/* First Tier Dropdown */
nav ul ul li {
width: 350px;
float: none; /* remove it */
/*display: list-item;*/
/*position: absolute; /* ul must be absolute, not li*/
border: 1px solid gray;
}

How to fix this dropdown navbar

I am writing a navigation bar with a dropdown option.
I have 2 problems: I can't get the dropdown to position properly under the menu, + also when I try to move the mouse to click on the elements in the dropdown submenu it closes as soon as I move.
Can anyone suggest a fix?
Thanks
On codepen:
https://codepen.io/-royqooe/pen/GRxaVbm
/* CSS section for home */
.navtop {
position: relative;
background-color: #333333;
height: 50px;
width: 100%;
border: 0;
}
.navtop div {
display: flex;
margin: 0 auto;
height: 100%;
}
.navtop div h1,
.navtop div a {
display: inline-flex;
align-items: center;
}
.navtop div h1 {
flex: 1;
font-size: 24px;
padding: 0;
margin: 0;
margin-left: 2%;
color: #f5f8ff;
font-weight: normal;
}
.navtop div a {
padding: 0 12px;
text-decoration: none;
color: #c1c4c8;
font-weight: bold;
}
.navtop div a i {
padding: 2px 8px 0 0;
}
.navtop div a:hover {
color: #66ccff;
}
/* sequel for home and navbar */
nav.navtop {
font-family: monospace;
}
.navtop>.navbar>ul {
list-style: none;
margin: 0;
padding-left: 0;
}
.navtop li {
display: block;
float: left;
padding: 0.5rem 0;
position: relative;
text-decoration: none;
transition-duration: 0.3s;
}
.navtop ul li ul {
background: red;
visibility: hidden;
opacity: 0;
min-width: 5rem;
position: absolute;
transition: all 0.5s ease;
margin-top: 1rem;
left: 0;
display: none;
}
.navtop ul li:hover>ul,
.navtop ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
.navtop ul li ul li {
clear: both;
width: 100%;
}
#media screen and (max-width: 760px) {
.topbar-text {
display: none;
}
}
<nav class="navlol navtop" role="navigation">
<div class="navbar">
<h1>Websitee Title</h1>
<ul>
<li><i class="fa-solid fa-file"></i><span class="topbar-text">Home</span></li>
<li>Two
<ul class="dropdownnn">
<li>Sub-1</li>
<li>Sub-2</li>
<li>Sub-3</li>
</ul>
</li>
<li class="navelements">Three</li>
<li><i class="fas fa-user-circle"></i><span class="topbar-text">Profile</span></li>
<li><i class="fas fa-sign-out-alt"></i><span class="topbar-text">Logout</span></li>
</ul>
</div>
</nav>
got an easy fix for you:
add this
.navtop li {
min-height:25px;
}
the issue is that that menu li was way shorter than the others to the sides due to the icons, even better maybe is instead adding this instead:
.navtop li {
height:100%
}
both worked for me
In the screenshot, the yellow color is the area that <li> element is covering. You can see there is a gap between <li> element and submenu. When you try to move the mouse to submenu, your cursor goes out of yellow area and the submenu hides.
The solution would be to position the submenu so it starts exactly after yellow area and make sure there is no gap. Apply margin-top of 0.5rem on submenu instead of 1rem.

Remove margin from subnavigation menu

Hello i'm trying to remove the left and right "margin" (i don't know if it's the right word) , so all menu buttons can fit inside the bar.
I want all the menu to fit so if in the future i want to add/edit buttons i can do it.
I'm learning HTML/CSS and i kinda understand but i don't know how to remove this.
i tried previewing with chrome dev tools but it didn't help
thanks for the help i really appreciate it !
here's my code :
HTML file (with js script for dropdown)
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<link rel="stylesheet" type="text/css" href="header_test_2.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<title>CFTC - TEMPLATE HEADER AND FOOTER</title>
</head>
<body>
<header>
<section class="navigation">
<div class="nav-container">
<nav>
<div class="nav-mobile"><a id="nav-toggle" href="#!"><span></span></a></div>
<ul class="nav-list">
<li>
Connaitre la CFTC
<ul class="nav-dropdown">
<li>Histoire</li>
<li>Valeurs</li>
<li>Identité</li>
</ul>
</li>
<li>
Syndicat CFTC-FPT 34
<ul class="nav-dropdown">
<li>Organisation</li>
<li>Accueil</li>
<li>Rôle et définition</li>
</ul>
</li>
<li>
Vie Professionnelle
<ul class="nav-dropdown">
<li>Formation</li>
<li>Statut</li>
<li>Carrière</li>
<li>Temps de Travail</li>
<li>Congés</li>
</ul>
</li>
<li>
Vie Pratique
<ul class="nav-dropdown">
<li>Action Logement</li>
<li>Pensions Alimentaires impayées</li>
<li>Prime d'activité</li>
<li>Apprentissage</li>
</ul>
</li>
<li>Activités</li>
<li>Actualités</li>
<li>Presse</li>
<li>
Adhésion
<ul class="nav-dropdown">
<li>Les + adhérents</li>
<li>Espace adhérents</li>
<li>Nous rejoindre</li>
</ul>
</li>
<li>
Coordonnées
<ul class="nav-dropdown">
<li>Syndicat CFTC-FPT 34</li>
<li>UD34</li>
<li>Fédération CFTC FPT</li>
</ul>
</li>
</ul>
</nav>
</div>
</section>
, </header>
</body>
<script type="text/javascript">
(function($) { // Begin jQuery
$(function() { // DOM ready
// If a link has a dropdown, add sub menu toggle.
$('nav ul li a:not(:only-child)').click(function(e) {
$(this).siblings('.nav-dropdown').toggle();
// Close one dropdown when selecting another
$('.nav-dropdown').not($(this).siblings()).hide();
e.stopPropagation();
});
// Clicking away from dropdown will remove the dropdown class
$('html').click(function() {
$('.nav-dropdown').hide();
});
// Toggle open and close nav styles on click
$('#nav-toggle').click(function() {
$('nav ul').slideToggle();
});
// Hamburger to X toggle
$('#nav-toggle').on('click', function() {
this.classList.toggle('active');
});
}); // end DOM ready
})(jQuery); // end jQuery
</script>
</html>
And my CSS File
#font-face {
font-family: "oswald";
src: url("fonts\oswald.regular.ttf");
}
.navigation {
height: 70px;
background: #262626;
}
.brand a, .brand a:visited {
color: #fff;
text-decoration: none;
}
.nav-container {
max-width: 1000px;
margin: 0 auto;
}
nav {
float: none;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
float: left;
position: relative;
}
nav ul li a, nav ul li a:visited {
display: block;
padding: 0 10px;
line-height: 70px;
background: #028893;
color: #fff;
text-decoration: none;
font-family: oswald;
}
nav ul li a:hover, nav ul li a:visited:hover {
background: #1D71B8;
color: #fff;
}
nav ul li a:not(:only-child):after, nav ul li a:visited:not(:only-child):after {
padding-left: 4px;
content: ' ▾';
}
nav ul li ul li {
min-width: 190px;
}
nav ul li ul li a {
padding: 15px;
line-height: 20px;
}
.nav-dropdown {
position: absolute;
display: none;
z-index: 1;
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}
/* Mobile navigation */
.nav-mobile {
display: none;
/* position: absolute; */
top: 0;
right: 0;
background: #262626;
/* height: 70px; */
width: 70px;
}
#media only screen and (max-width: 798px) {
.nav-mobile {
display: block;
}
nav {
width: 100%;
padding: 70px 0 15px;
}
nav ul {
display: none;
}
nav ul li {
float: none;
}
nav ul li a {
padding: 15px;
line-height: 20px;
}
nav ul li ul li a {
padding-left: 30px;
}
.nav-dropdown {
position: static;
}
}
#media screen and (min-width: 799px) {
.nav-list {
display: block !important;
}
}
#nav-toggle {
position: absolute;
left: 18px;
top: 22px;
cursor: pointer;
padding: 10px 35px 16px 0px;
}
#nav-toggle span, #nav-toggle span:before, #nav-toggle span:after {
cursor: pointer;
border-radius: 1px;
height: 5px;
width: 35px;
background: #fff;
position: absolute;
display: block;
content: '';
transition: all 300ms ease-in-out;
}
#nav-toggle span:before {
top: -10px;
}
#nav-toggle span:after {
bottom: -10px;
}
#nav-toggle.active span {
background-color: transparent;
}
#nav-toggle.active span:before, #nav-toggle.active span:after {
top: 0;
}
#nav-toggle.active span:before {
transform: rotate(45deg);
}
#nav-toggle.active span:after {
transform: rotate(-45deg);
}
article {
max-width: 1000px;
margin: 0 auto;
padding: 10px;
}
That's were things are needed to be changed
change max-width
.nav-container {
max-width: 1200px;
margin: 0 auto;
}

Trying to remove a white space from my page

As i'm making my first website there's this white space in my page i'm trying to remove but i can't , i tried the position and few settings but it doesn't seem to work , i even edited few of my already wroten code.
Any help will be good.
Thanks
See here
The github project
I have 2 files 1 for html and 1 for css for now
Here's my html file
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="Template_Header_Footer.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<title>Header Last version (sans responsive)</title>
</head>
<body>
<header>
<picture>
<source srcset="images/Logo.png" media="(max-width: 640px)">
<source srcset="images/Logo.png" media="(max-width: 1500px)">
<img id="logo" src="images/Logo.png" style"width:40%;">
</picture>
<picture>
<source srcset="images/paysage.jpg" media="(max-width: 640px)">
<source srcset="images/paysage.jpg" media="(max-width: 1500px)">
<img id="paysage" src="images/paysage.jpg" style"width:40%;">
</picture>
<p>Syndicat CTFC 34</p>
<center>
<h1>Syndicat Constructif, Partenaire du Dialogue Social<h1>
</center>
<section class="navigation">
<div class="nav-container">
<nav>
<div class="nav-mobile"><a id="nav-toggle" href="#!"><span></span></a></div>
<ul class="nav-list">
<li>
Connaitre la CFTC
<ul class="nav-dropdown">
<li>Histoire</li>
<li>Valeurs</li>
<li>Identité</li>
</ul>
</li>
<li>
Syndicat CFTC-FPT 34
<ul class="nav-dropdown">
<li>Organisation</li>
<li>Accueil</li>
<li>Rôle et définition</li>
</ul>
</li>
<li>
Vie Professionnelle
<ul class="nav-dropdown">
<li>Formation</li>
<li>Statut</li>
<li>Carrière</li>
<li>Temps de Travail</li>
<li>Congés</li>
</ul>
</li>
<li>
Vie Pratique
<ul class="nav-dropdown">
<li>Action Logement</li>
<li>Pensions Alimentaires impayées</li>
<li>Prime d'activité</li>
<li>Apprentissage</li>
</ul>
</li>
<li>Activités</li>
<li>Actualités</li>
<li>Presse</li>
<li>
Adhésion
<ul class="nav-dropdown">
<li>Les + adhérents</li>
<li>Espace adhérents</li>
<li>Nous rejoindre</li>
</ul>
</li>
<li>
Coordonnées
<ul class="nav-dropdown">
<li>Syndicat CFTC-FPT 34</li>
<li>UD34</li>
<li>Fédération CFTC FPT</li>
</ul>
</li>
</ul>
</nav>
</div>
</section>
</header>
</body>
<script type="text/javascript">
(function($) { // Begin jQuery
$(function() { // DOM ready
// If a link has a dropdown, add sub menu toggle.
$('nav ul li a:not(:only-child)').click(function(e) {
$(this).siblings('.nav-dropdown').toggle();
// Close one dropdown when selecting another
$('.nav-dropdown').not($(this).siblings()).hide();
e.stopPropagation();
});
// Clicking away from dropdown will remove the dropdown class
$('html').click(function() {
$('.nav-dropdown').hide();
});
// Toggle open and close nav styles on click
$('#nav-toggle').click(function() {
$('nav ul').slideToggle();
});
// Hamburger to X toggle
$('#nav-toggle').on('click', function() {
this.classList.toggle('active');
});
}); // end DOM ready
})(jQuery); // end jQuery
</script>
</html>
And that's my CSS Files :
#font-face {
font-family: "oswald";
src: url("fonts\oswald.regular.ttf");
font-family: "lato";
src: url("fonts\Lato-Regular.ttf");
font-family: "playfairdisplay";
src: url("fonts\PlayfairDisplaySC-Regular.otf");
}
.navigation {
height: 70px;
background: #028893;
}
.brand a, .brand a:visited {
color: #fff;
text-decoration: none;
}
.nav-container {
max-width: 1200px;
margin: 0 auto;
}
nav {
float: none;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
float: left;
position: relative;
}
nav ul li a, nav ul li a:visited {
display: block;
padding: 0 10px;
line-height: 70px;
background: #028893;
color: #fff;
text-decoration: none;
font-family: oswald;
}
nav ul li a:hover, nav ul li a:visited:hover {
background: #1a6066;
color: #fff;
}
nav ul li a:not(:only-child):after, nav ul li a:visited:not(:only-child):after {
padding-left: 4px;
content: ' ▾';
}
nav ul li ul li {
min-width: 190px;
}
nav ul li ul li a {
padding: 15px;
line-height: 20px;
}
.nav-dropdown {
position: absolute;
display: none;
z-index: 1;
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}
/* Mobile navigation */
.nav-mobile {
display: none;
/* position: absolute; */
top: 0;
right: 0;
background: #262626;
/* height: 70px; */
width: 70px;
}
#media only screen and (max-width: 798px) {
.nav-mobile {
display: block;
}
nav {
width: 100%;
padding: 70px 0 15px;
}
nav ul {
display: none;
}
nav ul li {
float: none;
}
nav ul li a {
padding: 15px;
line-height: 20px;
}
nav ul li ul li a {
padding-left: 30px;
}
.nav-dropdown {
position: static;
}
}
#media screen and (min-width: 799px) {
.nav-list {
display: block !important;
}
}
#nav-toggle {
position: absolute;
left: 18px;
top: 22px;
cursor: pointer;
padding: 10px 35px 16px 0px;
}
#nav-toggle span, #nav-toggle span:before, #nav-toggle span:after {
cursor: pointer;
border-radius: 1px;
height: 5px;
width: 35px;
background: #fff;
position: absolute;
display: block;
content: '';
transition: all 300ms ease-in-out;
}
#nav-toggle span:before {
top: -10px;
}
#nav-toggle span:after {
bottom: -10px;
}
#nav-toggle.active span {
background-color: transparent;
}
#nav-toggle.active span:before, #nav-toggle.active span:after {
top: 0;
}
#nav-toggle.active span:before {
transform: rotate(45deg);
}
#nav-toggle.active span:after {
transform: rotate(-45deg);
}
article {
max-width: 1000px;
margin: 0 auto;
padding: 10px;
}
/* Partie pour le logo et la photo et la phrase */
#logo {
float: left;
height: 350px;
width: 350px;
}
header p {
font-family: oswald;
font-size: 30px;
padding: 80px;
}
#paysage {
float: right;
height: 400px;
width: 1520px;
}
header h1 {
overflow: hidden;
border: 0px solid #01B2C0;
color: #FFFFFF;
background-color: #01B2C0;
font-size: 30px;
font-family: lato;
/* position: relative; */
bottom: 80px;
width: auto;
/* height: 33px; */
padding-top: 25px;
}
* {
margin: 0;
}
Seems that the height of logo is bigger than the banner height.Manage Logo Height.

How to slide line in css?

https://imgur.com/a/V2W5jTZ (If you can't see the image)
When I click on one heading the line should appear, but when I click on another heading I want the line to slide to the next heading.
I have already created the same menu navigator for each heading(page), and I just display line under the page that's open
Ex:
Heading code
<p class="content">
About Us
Position
Commerical Projects
Residential Projects
</p>
After setting all the same css, i have used hr in this way:
hr{
position: absolute;
top: 100px;
right: 168px;
width: 240px;
border-color: red;
}
p a {
font-family: sans-serif;
text-decoration: none;
color: gray;
position: relative;
margin: 10px 0;
display: inline-block;
padding: 12px 10px;
}
p a::after {
content: "";
background: blue;
height: 1px;
position: absolute;
bottom: 0;
transition: .16s all 0.025s;
}
p a::after {
left: 100%;
right: 0;
}
p a:hover ~ a::after {
left: 0;
right: 100%;
}
p a:hover::after {
left: 0;
right: 0;
}
<p class="content">
About Us
Position
Commerical Projects
Residential Projects
</p>
try this :)
I'd recommend writing a css class with the desired style which you would apply to an
you will need some java-script to apply the class to the element when clicked but here's an example to get you started
https://www.w3schools.com/howto/howto_js_active_element.asp
You can use pseudo css classes to show underline for a active element(anchor tag).
There are different states of pseudo classes like active, hover, focus etc
Most probably you can use focus class to solve your problem. (active and hover can also be used to handle different scenarios )
Here is an example to solve your problem
a {
text-decoration: none;
}
a:focus {
border-bottom: 1px solid red;
}
also instead of text-decoration: underline; you may use border-bottom: 1px solid red; which is more clear under line.
Here is full css code which may help you to better understand the solution :
/*To hide the default behaviour of <a> tag*/
a {
text-decoration: none;
}
/***By using text-decoration: underline;***/
/* a:active, a:focus, a:hover {
text-decoration: underline;
} */
/***To handle different cases***/
/* a:active, a:focus, a:hover {
border-bottom: 1px solid red;
} */
/***Final solution - to handle your requirement***/
a:focus {
border-bottom: 1px solid red;
}
You can also use the commented code by uncommenting it check different scenarios.
You can check this link for details on how to build it: https://codepen.io/arjunamgain/pen/lGALt
This should be good enough to achieve the desired functionality. Instead of the red background in the css section just use a border rule, like:
border-bottom: 4px solid #d90000;
You can use something like this
$(document).ready(function() {
var $slider = $('nav .slider'),
width = $('nav ul li').width;
$slider.width(width);
});
$(window).resize(function() {
var $slider = $('nav .slider'),
width = $('nav ul li').width,
$isActive = $('nav ul li.isactive'),
isX = $isActive.position().left,
isW = $isActive.width();
$slider.width(width);
$('nav ul li').each(function() {
var x = $(this).position().left,
w = $(this).width();
$(this).on({
mouseenter: function() {
$slider.css({
left: x,
width: w
});
},
mouseleave: function() {
$slider.css({
left: isX,
width: isW
});
}
});
});
}).resize();
*,
*:before,
*:after {
box-sizing: border-box;
}
a {
color: #ea3830;
text-decoration: none;
}
nav {
position: relative;
width: 100%;
max-width: 960px;
min-width: 400px;
height: 50px;
margin: 25px auto;
border-bottom: 3px solid #eee;
text-align:center;
}
nav .slider {
position: absolute;
bottom: 0;
width: 25%;
height: 3px;
box-shadow: 0 3px #ea3830;
transition: all 0.3s ease-in-out;
}
nav ul {
padding: 0;
height: 50px;
display: flex;
flex-flow: row nowrap;
justify-content: space-around;
align-items: center;
}
nav ul li {
width: 25%;
height: 50px;
flex: 25%;
line-height: 50px;
list-style: none;
}
nav ul li a {
padding: 0 25px;
display: block;
font-weight: 600;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav>
<div class='slider'></div>
<ul>
<li class='isactive'>
<a href='#'>Index</a>
</li>
<li>
<a href='#'>About</a>
</li>
<li>
<a href='#'>Work</a>
</li>
<li>
<a href='#'>Contact</a>
</li>
</ul>
</nav>
Here you go man try this :)
* {
box-sizing: border-box;
}
body {
font: 300 100% 'Helvetica Neue', Helvetica, Arial;
}
.container {
width: 50%;
margin: 0 auto;
}
ul li {
display: inline;
text-align: center;
}
a {
display: inline-block;
width: 25%;
padding: .75rem 0;
margin: 0;
text-decoration: none;
color: #333;
}
.two:hover ~ hr {
margin-left: 25%;
}
.three:hover ~ hr {
margin-left: 50%;
}
.four:hover ~ hr {
margin-left: 75%;
}
hr {
height: .25rem;
width: 25%;
margin: 0;
background: tomato;
border: none;
transition: .3s ease-in-out;
}
<div class="container">
<ul>
<li class="one">About Us</li><!--
--><li class="two">Position</li><!--
--><li class="three">Commerical Projects</li><!--
--><li class="four">Residential Projects</li>
<hr />
</ul>
</div>