I have an img
(logo), a h1
(name of the site) and an ul (nav bar). Currently, the
imgand the
h1are on the same line (both aligned left) which is what I want. My
ulis one line down and i want it next to the
h1, aligned right. How can I do that? I've tried
display: inline-block;with
width: auto;` but that didn't work.
HTML:
<header>
<img src="/images/logo.png" alt="Logo" id="logo">
<h1>Title</h1>
<nav>
<ul>
<li><a href="index.html" class="nav-link">Home</a> |</li>
<li><a href="gallery.html" class="nav-link">Gallery</a> |</li>
<li><a href="about.html" class="nav-link">About</a></li>
</ul>
</nav>
</header>
And the CSS:
h1 {
display: inline-block;
width: auto;
}
ul {
list-style: none;
display: inline-block;
width: auto;
}
ul li {
display: inline;
}
I would really appreciate some help, been stuck at this for too long
You can do that with easily css grid, just add header and nav css classes
header {
display: grid;
grid-template-columns: repeat(2, auto) 1fr;
align-items: center;
}
nav {
justify-self: end;
}
h1 {
display: inline-block;
width: auto;
}
ul {
list-style: none;
display: inline-block;
width: auto;
}
ul li {
display: inline;
}
<header>
<img src="/images/logo.png" alt="Logo" id="logo">
<h1>Title</h1>
<nav>
<ul>
<li><a href="index.html" class="nav-link">Home</a> |</li>
<li><a href="gallery.html" class="nav-link">Gallery</a> |</li>
<li><a href="about.html" class="nav-link">About</a></li>
</ul>
</nav>
</header>