Navbar creating empty space down and above when adding logo - html

I want to make the navbar with logo. but its creating empty space below when adding height or width.
is there any css property I can use?
it does not look good like this.
this is navbar without logo
this is navbar with logo:
html:
<section id="header">
<a class="name" href="#header"
>SYNCC
<img
src="images/logo.png"
alt=""
height="90"
class="logo-png"
/></a>
<div>
<ul id="navbar">
<li><a class="active" href="#hero">Home</a></li>
<li>Features</li>
<li>About Us</li>
<li>Contact</li>
<li>
<a href="#carouselExampleControls"
><i class="fa-solid fa-cart-shopping"></i
></a>
</li>
</ul>
</div>
</section>
css:
#header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 80px;
/* background: #e3e6f3; */
background: #E5E6EE;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.06);
z-index: 999;
position: sticky;
top: 0;
left: 0;
right: 30%;
}
#navbar {
display: flex;
align-items: center;
justify-content: center;
}
#navbar li {
list-style: none;
padding: 0 20px;
position: relative;
}
#navbar li a {
text-decoration: none;
font-size: 16px;
font-weight: 600;
color: #1a1a1a;
}
.name {
font-family: "DynaPuff", cursive;
text-decoration: none;
font-size: 25px;
font-weight: 400;
color: #1a1a1a;
position: relative;
top: 10px;
}
.name:hover,
.name a {
color: #088178;
transition: 0.3s ease;
}
.name a::after,
.name a:hover {
content: "";
width: 30%;
height: 2px;
background: #088178;
position: absolute;
bottom: -4px;
left: 20px;
}
#navbar li a:hover,
#navbar li a.active {
color: #088178;
transition: 0.3s ease;
}
#navbar li a.active::after,
#navbar li a:hover::after {
content: "";
width: 30%;
height: 2px;
background: #088178;
position: absolute;
bottom: -4px;
left: 20px;
}
tried using display : block;
I tried several ways to fix it.
any other way can use to make it correct.

Usally when this happens to me, I will just add top:--px; or bottom:--px; accordingly to make them line up.

Related

Problem in positioning in navigation bar using css

I am making a navbar of an e-commerce website and I want this little line to display like it is displayed below "Home", when the user is in that particular page.
When I write the code, this happens-
For some reason, that little bar, starts just after that Nav button ends.
body {
font-family: 'Montserrat', sans-serif;
width: 100%;
margin: 0;
background-color: #121212;
}
#header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 80px;
background: #121212;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.6);
}
#navbar {
display: flex;
align-items: center;
justify-content: space-between;
}
#navbar li {
list-style: none;
padding: 0 20px;
position: relative;
}
#navbar li a {
text-decoration: none;
font-size: 1rem;
font-weight: 600;
color: #ffffff;
transition: 200ms ease-in-out;
}
#navbar li a:hover,
#navbar li a.active {
color: #e50914;
}
#navbar li a.active::after {
content: "";
width: 60%;
height: 3px;
background: #e50914;
position: absolute;
bottom: -6px;
position: 0;
}
.logo {
width: 10rem;
}
<body>
<section id="header">
<img src="images/logo.png" class="logo">
<div>
<ul id="navbar">
<li><a class="active" href="why.html">Why Snap Smile</a></li>
<li>Solutions</li>
<li>Pricing</li>
<li>About</li>
<li>Gallery</li>
<li><i class="fa-solid fa-headset"></i></li>
</ul>
</div>
</section>
</body>
position: 0 is not a valid CSS property:value pair. You have the position set to absolute which is correct, but then you overwrite it with an invalid property. So I deleted it.
Next step is to give the ::after element the same left value as the padding on the #navbar li, et voila you have aligned active underline.
In order to get proper alignment with the text, you have to remember that the underline is taken out of the document flow with position: absolute, so it won't take account for the padding that the text is in. We have to manually add the same left-side padding value the text has as a left position on the underline.
#navbar li {
list-style: none;
padding: 0 20px; /* has left padding of 20px */
position: relative;
}
#navbar li a.active::after {
content: "";
width: 60%;
left: 20px; /* aligning manually with the same value */
height: 3px;
background: #e50914;
position: absolute;
bottom: -6px;
}
body {
font-family: 'Montserrat', sans-serif;
width: 100%;
margin: 0;
background-color: #121212;
}
#header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 80px;
background: #121212;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.6);
}
#navbar {
display: flex;
align-items: center;
justify-content: space-between;
}
#navbar li {
list-style: none;
padding: 0 20px;
position: relative;
}
#navbar li a {
text-decoration: none;
font-size: 1rem;
font-weight: 600;
color: #ffffff;
transition: 200ms ease-in-out;
}
#navbar li a:hover,
#navbar li a.active {
color: #e50914;
}
#navbar li a.active::after {
content: "";
width: 60%;
left: 20px;
height: 3px;
background: #e50914;
position: absolute;
bottom: -6px;
}
.logo {
width: 10rem;
}
<body>
<section id="header">
<img src="images/logo.png" class="logo">
<div>
<ul id="navbar">
<li><a class="active" href="why.html">Why Snap Smile</a></li>
<li>Solutions</li>
<li>Pricing</li>
<li>About</li>
<li>Gallery</li>
<li><i class="fa-solid fa-headset"></i></li>
</ul>
</div>
</section>
</body>
if you want a quick fix.
#navbar li a.active::after{
content: "";
width: 60%;
height: 3px;
background: #e50914;
position: absolute;
bottom: -6px;
position: 0;
transform:translate(-135px); // x and y controls
}

How to center a simple navbar?

I've been struggling for hours to center my nav bar.
Here it is :
[[1]: https://i.stack.imgur.com/Wi2RD.png][1]
As you can see, the nav elements are slightly to the left, and not centered to the body. (the body is perfectly centered).
Here's my code :
header {
display: flex;
justify-content: space-between;
align-items: center;
background: linear-gradient(0deg, rgba(164, 174, 228, 0.05), rgba(164, 174, 228, 0.05)), #080B1C;
}
.logohome {
position: relative;
width: 350px;
display: flex;
}
.nav__links a,
.overlay__content a {
font-family: "Montserrat", sans-serif;
font-weight: 500;
color: #edf0f1;
text-decoration: none;
}
.nav__links {
list-style: none;
display: flex;
}
.nav__links li {
margin-right: 18rem;
}
.nav__links li a {
transition: color 0.3s ease 0s;
}
.nav__links li a:hover {
color: #A4AEE4;
}
.NP {
position: absolute;
margin-right: 4.6rem;
right: 0;
color: #24252a;
font-family: "Montserrat";
font-weight: 700;
font-style: normal;
font-size: 20px;
display: flex;
justify-content: center;
align-items: center;
z-index: 1;
}
.profile {
border-radius: 50%;
margin-right: 4rem;
width: 50px;
transition: background-color 0.3s ease 0s;
z-index: 0;
}
.dropbtn {
position: absolute;
margin-left: 4.5rem;
bottom: 2px;
width: 25px;
background-color: transparent;
color: white;
font-size: 16px;
border: none;
cursor: pointer;
}
And the html :
<header>
<img href="google.com" class="logohome" src="images/logo.png"><br><br>
<nav>
<ul class="nav__links">
<li>Mes Favoris </li>
<li>Accueil</li>
<li>Mes Statistiques</li>
<img src="/images/navstate.png" class="navstate">
</ul>
</nav>
<a class="cta" href="#"></a>
<img src="/images/iconeprofile.png" class="profile">
<div class="NP">NP
<div class="dropdown">
</div>
<img src="/images/drop.png" onclick="myFunction()" class="dropbtn">
<div id="myDropdown" class="dropdown-content">
Mon profil
Nous contacter
Déconnexion
</div>
</div>
</header>
what parameters should I change or implement to make it works simply nice? (I don't want to do super responsive bar, but just clean, the purpose is a web app)
This will fix it. All your elements except the last one will have margin-right. Also don't forget to reset ul margin and padding if needed.
.nav__links {
list-style: none;
display: flex;
margin: 0;
padding: 0;
}
.nav__links li:not(:last-child) {
margin-right: 18rem;
}

Push a div to the right

I'm coding a menu in french but I need to move all the buttons (Home, About us...) to the right.
I tried with float: right; but it doesn't work.
Here is my Result :
My Result
The <a> Home, Informations, etc.. are in a div. It's this div that i want to push right !
My Objective :
My Objective
My Code:
/*
==============================
NAVBAR
==============================
*/
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #9ebd11/*55d6aa*/
;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
/*padding: 10px 0;*/
}
nav {
float: right;
}
nav #navbar-ul {
margin: 0;
padding: 0;
list-style: none;
}
nav .navbar-li {
display: inline-block;
margin-left: 70px;
padding-top: 23px;
position: relative;
}
nav .navbar-button {
color: #444;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav .navbar-button:hover {
color: #000;
}
nav .navbar-button::before {
content: '';
display: block;
height: 5px;
background-color: #444;
position: absolute;
top: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
nav .navbar-button:hover::before {
width: 100%;
}
nav #register-li {
/*display: inline-block;*/
margin-left: 70px;
padding-top: 23px;
position: relative;
}
nav #register-button {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav #login-li {
/*display: inline-block;*/
margin-left: 70px;
padding-top: 23px;
position: relative;
}
nav #login-button {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
ul {
list-style-type: none;
}
nav,
.container {
display: flex;
}
.connection {
line-height: 2;
}
<header>
<div class="container">
<h1 class="logo">
<img src="images/Logo/logo_gp_.png" width="100" alt="Description de l'image">
</h1>
<nav>
<ul id="navbar-ul">
<li class="navbar-li">Home</li>
<li class="navbar-li">Informations</li>
<li class="navbar-li">About us</li>
</ul>
<ul class="connection">
<li>S'inscrire</li>
<li>Se connecter</li>
</ul>
</nav>
</div>
</header>
Thanks
Float won't work because your container is a flex-container.
Just use:justify-content:space-between`
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #9ebd11/*55d6aa*/
;
}
nav #navbar-ul {
margin: 0;
padding: 0;
list-style: none;
}
nav .navbar-li {
display: inline-block;
padding-top: 23px;
position: relative;
}
nav .navbar-button {
color: #444;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav .navbar-button:hover {
color: #000;
}
nav .navbar-button::before {
content: '';
display: block;
height: 5px;
background-color: #444;
position: absolute;
top: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
nav .navbar-button:hover::before {
width: 100%;
}
nav #register-li {
/*display: inline-block;*/
margin-left: 70px;
padding-top: 23px;
position: relative;
}
nav #register-button {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav #login-li {
position: relative;
}
nav #login-button {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
ul {
list-style-type: none;
}
nav,
.container {
display: flex;
justify-content: space-between;
}
.connection {
line-height: 2;
}
<header>
<div class="container">
<h1 class="logo">
<img src="images/Logo/logo_gp_.png" width="100" alt="Description de l'image">
</h1>
<nav>
<ul id="navbar-ul">
<li class="navbar-li">Home</li>
<li class="navbar-li">Informations</li>
<li class="navbar-li">About us</li>
</ul>
<ul class="connection">
<li>S'inscrire</li>
<li>Se connecter</li>
</ul>
</nav>
</div>
</header>
Bootstrap's "Container" class has a max-width of something like 1800px(not certain of exact px count).
Try using "container-fluid". This should allow the nav items to move to the far right but will probably move your logo to the far left because of your .logo float-left css.
You can give the logo a margin-left that works for you.
Edit: I just noticed you've defined your own .container class in the css. And margin set to 0 auto. This is going to center your content within the container class and give you max width of 80% so your content won't reach the far right side of the browser unless you set this items to "position:absolute" and then give them the necessary margins.
Try changing your nav class from:
nav{
floaf: right;
}
to:
nav{
position: absolute;
right: 20px;
top: 0px;
}
This should force your nav element to position it's right 20px left of the parent elements right. Tested in chrome.
remove the float: right from your .nav and add float:left from .logo
Now add display:flex to your .logo and for your container add:
.container{
justify-content: space-between;
}
I have not tested this. Let me know if this is what you wanted.

How can I fix an image link that's not working?

I am trying to get an image for the navbar of my page to link back to my site's homepage. I have tried using the code below, but for some reason only the top of the image is clickable. I have inspected it and tried for ages but I cannot find anything that looks out of place or has incorrect syntax.
Is there anything I can do to fix this problem?
nav {
height: 85px;
position: fixed;
top: 0px;
left: 0px;
width: 100%;
background: none;
padding-left: 60px;
padding-right: 60px;
user-select: none;
transition: 0.5s ease-in-out;
z-index: 100;
}
nav img {
height: 70px;
margin-top: 5px;
}
nav a:hover {
color: var(--primary) !important;
transition: 0.15s;
}
nav img {
margin: 0px;
}
nav .responsive-nav {
display: none;
}
nav .right {
position: fixed;
top: 27px;
right: 60px;
width: 100%;
text-align: right;
height: 85px;
text-transform: uppercase;
}
nav .right ul {
position: fixed;
top: 27px;
right: 60px;
width: 100%;
height: 85px;
margin-top: 0px;
}
nav .right li {
margin-top: 7px;
}
nav .right a {
text-decoration: none;
color: #ffffff;
font-size: 16px;
margin-left: 20px;
}
nav h1 a {
text-decoration: none;
color: #ffffff;
transition: 0.15s;
}
nav h1 a:hover {
color: var(--primary);
transition: 0.15s;
}
nav .menu {
display: none;
position: fixed;
top: 18px;
right: 30px;
font-size: 25px;
border: 2px solid var(--primary);
border-radius: 5px;
padding: 5px;
color: var(--primary);
cursor: pointer;
}
<nav>
<img src="https://www.gsr-technology.co.uk/wp-content/uploads/2015/10/partner-logo-placeholder.jpg" />
<div class="right">
<ul>
<li>Home</li>
<li>Services</li>
</ul>
</div>
<i class="fas fa-bars menu"></i>
</nav>
In above code nav .right and nav .right ul both have width: 100%; remove that and try it will done and whole image will be clickable.

Menu focus or active not responding as expected

Using pure css, I have a menu image that when :hover, the background-color changes as expected. When the user clicks, a menu pop out opens and so now, that initial menu image should be active. However, it is not staying the color needed even with my styling set for :active or :focus.
Image as when hover:
When the cursor moves off that image and to the menu items, that background-color does not stay the intended cover. That image:
My code for the html and css is:
#menu {
position: relative;
}
#menu_img:hover,
#menu_img:active,
#menu_img:focus {
background-color: #008272;
cursor: pointer;
}
#menu_items {
position: absolute;
top: 0%;
opacity: 0;
transition: all 0.5s;
display: none;
background-color: #002F33;
color: #ffffff;
height: 600px;
width: 18%;
z-index: 2;
left: 0px;
}
#menu_items > a {
font-size: 18px;
color: #ffffff;
margin-top: 15px;
margin-bottom: 15px;
padding-left: 20px;
}
#menu_items > a:hover {
text-decoration: none;
}
#menu_items.menu_items_toggle {
opacity: 1;
top: 100%;
display: inline-block;
}
<div id="menu" style="background-color: #002F33; height:50px;">
<span id="span_img_container" class="navIcon" style="width: 50px;"><img id="menu_img" src="assets/images/icon_hamburger.png"></span>
<div id="menu_items">
Moneyball Website
<br>
Moneyball Tool
<br>
Moneyball Stream Channel
<br>
</div>
<span style="color: #ffffff; font-size: 22px; padding-left:15px; padding-top: 26px; position: relative; top: 5px; left: -5px;">Moneyball Tool</span>>
</div>
Any ideas on this? Much appreciated!
I suggest it's because the icon is outside menu_items. You can try something like this:
nav {
background: #333;
color: white;
min-height: 2.75em;
position: relative;
}
nav h1 {
line-height: 2.75rem;
margin: 0 0 0 3.5rem;
}
nav menu {
line-height: 2.75;
left: 0;
margin: 0;
padding: 0;
position: absolute;
top: 0;
width: 2.75em;
}
nav menu:before {
box-shadow: 11px 0 0 -10px rgba(255, 255, 255, 0.6);
content: "☰";
display: block;
line-height: 2.75;
text-align: center;
transition: backround-color 200ms;
width: 2.75em;
}
nav menu li {
background: #333;
list-style: none;
max-height: 0;
overflow: hidden;
padding: 0 1em;
transition: max-height 200ms;
}
nav menu li:hover {
background-color: black;
}
nav menu:hover {
width: auto;
}
nav menu:hover:before {
background-color: green;
box-shadow: none;
}
nav menu:hover li {
max-height: 2.75em;
}
<nav>
<menu>
<li>
<a>First menu link</a>
</li>
<li>
<a>Second menu link</a>
</li>
<li>
<a>Third menu link</a>
</li>
<li>
<a>Fourth menu link</a>
</li>
</menu>
<h1>Page title</h1>
</nav>