I’m new in CSS/HTML and I can’t make the design that I want.
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../css/header.css">
<link rel="stylesheet" href="../css/layout.css">
</head>
<body>
<div class="header">
<a href="index.html"><div class="logo"></div></a>
<input type="text" class="search-bar" placeholder="Type...">
</div>
</body>
</html>
CSS:
.logo {
width: 80px;
height: 80px;
background-image: url('../assets/images/logo.jpeg');
background-size: cover;
margin-right: 20px;
}
.search-bar {
width: 50%;
height: 50%;
border: 1px solid gray;
border-radius: 20px;
padding: 10px;
margin: 0 auto;
font-size: 1em;
}
Photo (I would like the logo to be centered, next to the search bar):
Thanks!
4
Answers
The problem was in the
Hope it helps someone!
You can use
display:flex
andjustify-content: center
in your.header
div to center the elements in the center; Add amargin-right
to the logo to give a space between the logo and search barI’m kinda new to web dev too, but this should work:
There are many ways to achieve your desired output. One of the ways using flex. You can also have a look at FLEX: A simple visual cheatsheet for flexbox.
Click on this CodePen to see the full code.
Besides, you can also have a look at the link below to see the issue & solution visually: StackOverFlow QA – Header in css not as expected
Happy coding 🙂