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;
}
Related
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.
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
}
I was able to find an html and css code to start creating my footer.
I was able to make it look a bit the way I want as seen in the following code:
However, I wanna be able to center all three headers and I can't seem to find how...
* {
margin: 0;
padding: 0;
}
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;600;700&display=swap');
body {
line-height: 1.5;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.textDecoration {
text-decoration: none;
color: inherit;
}
.container {
max-width: 100%;
margin: 0px;
}
.row {
display: flex;
flex-wrap: wrap;
}
ul {
list-style: none;
}
.footer {
background-color: #24262b;
padding: 0px 0;
width: 100%;
}
.footer-col {
width: 25%;
padding: 0 15px;
}
.footer-col h4 {
font-size: 18px;
color: #ffffff;
text-transform: capitalize;
margin-bottom: 35px;
font-weight: 500;
position: relative;
}
.footer-col h4::before {
content: '';
position: absolute;
left: 0;
bottom: -10px;
background-color: red;
height: 2px;
box-sizing: border-box;
width: 50px;
}
.footer-col ul li:not(:last-child) {
margin-bottom: 10px;
}
.footer-col ul li a {
font-size: 16px;
text-transform: capitalize;
color: #ffffff;
text-decoration: none;
font-weight: 300;
color: #bbbbbb;
display: block;
transition: all 0.3s ease;
}
.footer-col ul li a:hover {
color: #ffffff;
padding-left: 8px;
}
.footer-col .social-links a {
display: inline-block;
height: 40px;
width: 40px;
background-color: rgba(255, 255, 255, 0.2);
margin: 0 10px 10px 0;
text-align: center;
line-height: 40px;
border-radius: 50%;
color: #ffffff;
transition: all 0.5s ease;
}
.footer-col .social-links a:hover {
color: #24262b;
background-color: #ffffff;
}
<p>In this example, we remove the bullets from the list, and its default padding and margin.</p>
<ul>
<li>Home</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
<footer class="footer">
<div class="container">
<div class="row">
<div class="footer-col">
<h4>Terms & Conditions</h4>
</div>
<div class="footer-col">
<h4><a class="textDecoration" href="#privacy">Privacy and Policy</a></h4>
</div>
<div class="footer-col">
<h4>Follow Us</h4>
<div class="social-links">
</div>
</div>
<div class="footer-col">
<div class="social-links">
<h3><img src="https://i.ibb.co/Lp1sB0M/face4.png"></a>
<img src="https://i.ibb.co/XVzFjBR/ig3.png"></a>
<img src="https://i.ibb.co/vVRq5dz/tw2.png"></a>
<img src="https://i.ibb.co/8j8dWcG/yt2.png"></a>
</h3>
</div>
</div>
</div>
</footer>
Any hints you can provide me to achieve this?
What would you recommend for social network icons for the footer?
It makes sense to put all h4's in a single footer-col div together because you want them grouped in the center. So you can do that, then add display: flex; to footer-col and use justify-content: center; to center them. Then you can add a gap to space them out. I also added display: flex; on your social-links to allow them to flex to stay on the same line.
* {
margin: 0;
padding: 0;
}
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;600;700&display=swap');
body {
line-height: 1.5;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.social-links {
display: flex;
}
.textDecoration {
text-decoration: none;
color: inherit;
}
.container {
max-width: 100%;
margin: 0px;
}
.row {
display: flex;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
}
ul {
list-style: none;
}
.footer {
background-color: #24262b;
padding: 0px 0;
width: 100%;
}
.footer-col {
display: flex;
width: 100%;
justify-content: center;
gap: 2em;
}
.footer-col h4 {
font-size: 18px;
color: #ffffff;
text-transform: capitalize;
margin-bottom: 35px;
font-weight: 500;
position: relative;
}
.footer-col h4::before {
content: '';
position: absolute;
left: 0;
bottom: -10px;
background-color: red;
height: 2px;
box-sizing: border-box;
width: 50px;
}
.footer-col ul li:not(:last-child) {
margin-bottom: 10px;
}
.footer-col ul li a {
font-size: 16px;
text-transform: capitalize;
color: #ffffff;
text-decoration: none;
font-weight: 300;
color: #bbbbbb;
display: block;
transition: all 0.3s ease;
}
.footer-col ul li a:hover {
color: #ffffff;
padding-left: 8px;
}
.footer-col .social-links a {
display: inline-block;
height: 40px;
width: 40px;
background-color: rgba(255, 255, 255, 0.2);
margin: 0 10px 10px 0;
text-align: center;
line-height: 40px;
border-radius: 50%;
color: #ffffff;
transition: all 0.5s ease;
}
.footer-col .social-links a:hover {
color: #24262b;
background-color: #ffffff;
}
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<p>In this example, we remove the bullets from the list, and its default padding and margin.</p>
<ul>
<li>Home</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
<footer class="footer">
<div class="container">
<div class="row">
<div class="footer-col">
<h4>Terms & Conditions</h4>
<h4><a class="textDecoration" href="#privacy">Privacy and Policy</a></h4>
<h4>Follow Us</h4>
</div>
<div class="social-links"><img src="./img/face4.png">
<img src="./img/ig3.png">
<img src="./img/tw2.png">
<img src="./img/yt2.png">
</div>
</div>
</div>
</footer>
</body>
</html>
I would like to move the navigation buttons a little bit to the left and separate it from the last button which's Sign Up, at the same time, I need to move the logo a little bit to the right.
body {
margin: 0;
}
header {
background-color: rgb(212, 209, 209);
display: flex;
flex-wrap: wrap;
/* so navbar will go under logo on small smartphones */
align-items: baseline;
padding: 0.5rem;
justify-content: space-between;
}
.logo {
width: 100px;
margin-top: 16px;
cursor: pointer;
}
.nav {
display: flex;
gap: 1rem;
padding: 0;
}
.link {
background: none;
border: none;
text-decoration: none;
color: #777;
font-family: inherit;
font-size: inherit;
cursor: pointer;
padding: 0;
}
.link:hover {
color: black;
}
.dropdown {
position: relative;
}
.dropdown-menu {
position: absolute;
}
#signup {
padding: 10px 25px;
background-color: rgba(0, 136, 169, 1);
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease 0s;
}
<header>
<img class="logo" src="images/new logo.png" alt="logo">
<nav class="nav">
<div class="dropdown">
<button class="link">Information</button>
<div class="dropdown-menu">Dropdown Content</div>
</div>
Pricing
<button class="link">Login</button>
<button class="link" id="signup">Sign Up</button>
</nav>
</header>
Just add a margin-left to your logo to move it more to the right. If you want more space between the last button and the rest of the content you can also add a margin-left to the .link:last-child If you want elements to space apart then use margin. margin: auto will distribute all remaining space within flexbox and css-grid (just as a side note for the future):
.logo {
margin-left: 25px;
}
.link:last-child {
margin-left: 30px;
}
/* original CSS */
body {
margin: 0;
}
header {
background-color: rgb(212, 209, 209);
display: flex;
flex-wrap: wrap;
/* so navbar will go under logo on small smartphones */
align-items: baseline;
padding: 0.5rem;
justify-content: space-between;
}
.logo {
width: 100px;
margin-top: 16px;
cursor: pointer;
}
.nav {
display: flex;
gap: 1rem;
padding: 0;
}
.link {
background: none;
border: none;
text-decoration: none;
color: #777;
font-family: inherit;
font-size: inherit;
cursor: pointer;
padding: 0;
}
.link:hover {
color: black;
}
.dropdown {
position: relative;
}
.dropdown-menu {
position: absolute;
}
#signup {
padding: 10px 25px;
background-color: rgba(0, 136, 169, 1);
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease 0s;
}
<header>
<img class="logo" src="images/new logo.png" alt="logo">
<nav class="nav">
<div class="dropdown">
<button class="link">Information</button>
<div class="dropdown-menu">Dropdown Content</div>
</div>
Pricing
<button class="link">Login</button>
<button class="link" id="signup">Sign Up</button>
</nav>
</header>
body {
margin: 0;
}
header {
background-color: rgb(212, 209, 209);
display: flex;
flex-wrap: wrap; /* so navbar will go under logo on small smartphones */
align-items: inherit;
padding: 15px 4%;
justify-content: space-between;
}
.logo {
margin-left: 20px;
cursor: pointer;
}
.nav {
display: flex;
gap: 1rem;
padding: 0;
}
.link {
background: none;
border: none;
text-decoration: none;
color: #777;
font-family: inherit;
font-size: inherit;
cursor: pointer;
padding: 0;
}
.link:hover {
color: black;
}
.link:last-child {
margin: auto;
}
.dropdown {
position: relative;
}
.dropdown-menu {
position: absolute;
}
#signup {
padding: 10px 25px;
background-color: rgba(0,136,169,1);
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease 0s;
}
If you want to move the logo to the right and signup to the left seperated from other navigation buttons then since its the first and last child, just use:
header:first-child{
float: right;
}
header:last-child{
float: left;
}
To adjust the middle buttons, just give a little bit of margin to position it correctly
give them all a little bit of margin in your css file. That's all I can tell you without seeing your CSS file
Here is what I see for my website:
website
As the image is below Navigation Bar, I want this to center vertically in my responsive website, similar to this website: https://www.ownhour.co.kr/#;
I have added width and height as 100% in internal image stylesheet and added margin and block in external CSS. After inspecting with the mobile version, it seems like the image is sitting at the top with a huge gap at the bottom.
Here is what I see for my website:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="monday.css">
<title>J[a]son</title>
</head>
<body>
<nav>
<div class = "logo">
<h4>J[a]son</h4>
</div>
<ul class = "nav-links">
<li>
HOME
</li>
<li>
PHOTOGRAPHY
<ul class="sub-menu">
<li>Colour</li>
<li>Black</li>
</ul>
</li>
<li>
CODING
</li>
<li>
ABOUT
</li>
</ul>
<div class= "burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="testing.js"></script>
<img class="main_car" src="Photos/main_car.jpg" alt="car" width="100%" height="100%"/>
<!--<p>June, 2020. Sunshine Coast, BC, Canada </p>-->
</body>
</html>
CSS
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
nav {
display: flex;
justify-content: space-between;
/*padding-right: 2em;*/
padding-left: 2em;
padding-top: 2em;
padding-bottom: 1.5em;
align-items: center;
min-height: 8vh;
background-color: black;
/*font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;*/
font-family: 'Poppins', sans-serif;
}
.logo {
color: rgb(240, 235, 235);
font-size: 20px;
text-transform: uppercase;
letter-spacing: 5px;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: white;
text-decoration: none;
letter-spacing: 1px;
font-weight: bold;
font-size: 11px;
/*padding: 5px 5px;*/
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: white;
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
#media screen and (max-width:950px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
padding-right: 2em;
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relative;
}
}
.nav-active {
transform: translate(0%);
}
The question is how to center the car image and remain responsive.
As I understand it (and this may need adjustment for your particular case) the requirement is for the car image to fill space but not leave a huge gap underneath before the footers are reached.
To do this in this case I've set the body element to flex so that once it's decided what is needed space-wise for the navbar and footer it can fill the remaining space with the car.
I initially tried to do this with object-fit: contain and object-position: center within a wrapper around the car img. However, I could not make this work and instead I've removed the car image and set it as a background to a div instead and allowed this div to fill up any remaining space on the screen.
Here's the snippet.
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
display: flex;
flex-direction: column;
height: 100vh;
}
nav {
display: flex;
justify-content: space-between;
/*padding-right: 2em;*/
padding-left: 2em;
padding-top: 2em;
padding-bottom: 1.5em;
align-items: center;
min-height: 8vh;
background-color: black;
/*font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;*/
font-family: 'Poppins', sans-serif;
}
.logo {
color: rgb(240, 235, 235);
font-size: 20px;
text-transform: uppercase;
letter-spacing: 5px;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: white;
text-decoration: none;
letter-spacing: 1px;
font-weight: bold;
font-size: 11px;
/*padding: 5px 5px;*/
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: white;
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
#media screen and (max-width:950px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
padding-right: 2em;
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relative;
}
}
.nav-active {
transform: translate(0%);https://ahweb.org.uk/car.png
}
.main_car_wrapper {
background-image: url(https://ahweb.org.uk/car.png);
background-repeat: no-repeat no-repeat;
background-position: center center;
background-size: contain;
width: 100%;
flex: 1 1 auto;
}
</style>
<nav>
<div class = "logo">
<h4>J[a]son</h4>
</div>
<ul class = "nav-links">
<li>
HOME
</li>
<li>
PHOTOGRAPHY
<ul class="sub-menu">
<li>Colour</li>
<li>Black</li>
</ul>
</li>
<li>
CODING
</li>
<li>
ABOUT
</li>
</ul>
<div class= "burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="testing.js"></script>
<div class="main_car_wrapper">
</div>
And some more footer stuff here
<p>June, 2020. Sunshine Coast, BC, Canada </p>
UPDATED
Can use with code like
margin-left: -50px;
margin-right: -50px;
width:100px;
in
.main_car img {
position: absolute;
top: 50%;
left: 50%;
margin-left: [-50% of your image's width];
margin-top: [-50% of your image's height];
}
I'm added css like this
.main_car
{
position: relative;
}
.main_car img
{
position: absolute;
top: 50%;
left: 50%;
margin-left: [-50% of your image's width];
margin-top: [-50% of your image's height];
}
Then will get output like this
Centered Image
body {
background-color: black;
/*rgb(241, 233, 233);*/
}
* {
margin: 0px;
padding: 0px;
}
.main_car
{
position: relative;
}
.main_car img
{
position: absolute;
top: 50%;
left: 50%;
margin-left: -50px;
margin-right: -50px;
width:100px;
}
#media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
#media screen and (max-width:950px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
padding-right: 2em;
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relaative;
}
}
<div class="main_car">
<img src="https://www.gravatar.com/avatar/efb780ba8c3560a06d4c1a1825b1e800?s=32&d=identicon&r=PG" alt="car">
</div>