HTML & CSS - Navbar resizing when browser window is resized

Should be a common and not a rare question, but still I tried everything and nothing worked. So maybe this time somebody can help and this question will be for everyone to check their mistakes.

So I am making Car Service website, I am a bit of a beginner in both HTML and CSS.

This is the normal full screen mode of my browser and it looks fine:

This is the normal full screen mode of my browser and it looks fine

As soon as I resize my browser size this happens with navbar

enter image description here

HTML CODE:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
            <title>Home</title>
        <link href="style.css" rel="stylesheet" type="text/css">
    </head>
        <body>
            <header>
                <div class="container">
                        <img src="img/header.png" alt="logo" class="logo">
                    <nav>
                        <ul>
                            <li><a href="index.html">Home</a></li>
                            <li><a href="about.html">About</a></li>
                            <li><a href="services.html">Services</a>
                            <li><a href="registration.html">Registration</a>
                            <li><a href="contact.html">Contact</a></li>
                            <li><a href="profile.html">Profile</a></li>
                        </ul>
                    </nav>
                </div>
            </header>
        </body>

CSS CODE:

body{
margin: 0;
padding: 0;
background-color: black;
font-family: 'Work Sans', sans-serif;
font-weight: 300;
}

.container{
width: 80%;
margin: 0 auto;
}

header{
background-color: #25DE8B;
}
header::after{
content: '';
display: table;
clear: both;
}

.logo{
float: left;
padding: 10px 0;
}

nav{
float: right;
}

nav ul{
margin: 0;
padding: 0;
list-style: none;
}

nav li{
display: inline-block;
margin-left: 70px;
padding-top: 35px;
position: relative;
}

nav a{
color: #012b4f;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}

nav a:hover{
color: #28AA1A;
}

nav a::before{
content: '';
display: block;
height: 8px;
width: 0%;
background-color: #012b4f;
position: absolute;
top: 0;
transition: all ease-in-out 250ms;
}

nav a:hover::before{
width: 100%;
}

I need to change code so my navbar stays on its place in any case. Thanks for any help.

Upvotes: 1

Views: 1283

Answers (1)

Yahli
Yahli

Reputation: 119

you use px as your units. you should use % or something else that is relative to the size of the page. you can see more information in this link: https://www.w3schools.com/cssref/css_units.asp

Upvotes: 2

Related Questions