I need help to align a logo on the left and navigation on the right using html and css.
I want it to be like this image >
I’ve been trying different ways to change my css format and it just wouldn’t work.
Here is my html and css
body
{
margin: 0;
padding: 0;
font-family: Hoefler Text;
background-color: rgb(233, 245, 248);
}
header{
margin: 3% 10% 3% 10%;
padding: 37px 161px;
align-items: center;
}
@media screen and { (max-width: 700px)}
.header {
width: auto;
float: none;
}
.main-nav{
font-family: Hoefler Text;
font-size: .8rem;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(0, 0, 0);
}
.main-nav li { float: left;}
.main-nav li a {
display:block;
color:#ffffff;
text-align: center;
padding:10px 12px;
text-decoration: none;
}
.main-nav li:hover{
background: #ADD8E6;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>*</title>
<link rel="stylesheet" href="*">
<link rel="shortcut icon" href="*"type="image/jpg">
</head>
<body>
<nav class="header">
<a href='*' ><img src='*' alt='logo'/></a>
<ul class="main-nav">
<li><a href="*">Home</a></li>
<li><a href="*"> Education</a></li>
<li><a href="*"> Experience</a></li>
<li><a href="*">Projects</a></li>
<li><a href="*">Contact Me</a></li>
</ul>
</nav>
</body>
</html>
2
Answers
You would like to make two blocks next to one another. It is possible to use an outside div block to your a and ul blocks and add a display: flex to the CSS. Then the size of your two inner block a and ul can be adjusted using percentage of width.
An elementary example of code is:
The same logic can be repeated for the ul block (making it a flex block with inner li blocks).
To solve this problem and align a logo on the left and links on the right of a nav bar you can use flexbox. Flexbox is preferable to trying to use floats, which is a somewhat antiquated way of doing layouts.
To accomplish this and make it look a bit nicer and be more semantic, I have modified your HTML slightly and renamed some of your classes. Take a look:
You can also check out my CodePen to play around with this example.