You need to take away the standard margin of body
:
body {
background: #f9f9eb;
margin: 0; ← ← ← ← ← ← ← ←
}
Also take out the padding
of <ul>
, which is the class .navigation
:
.navigation {
list-style: none;
margin: 0;
padding: 0; ← ← ← ← ← ← ← ←
background: #0b5eec;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
justify-content: center;
}
To div
that holds your search box is outside the nav
:
<nav>
...
</nav>
<div class="search-box">
...
</div>
Place at the end of nav
and insert styles into the CSS to center and give an upper margin of the menu:
.search-box{
text-align: center;
margin-top: 15px;
}
How does it look:
body {
background: #f9f9eb;
margin: 0;
}
nav{
background: #0b5eec;
}
.navigation {
list-style: none;
margin: 0;
padding: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
justify-content: center;
}
.search-box{
margin: 15px 15px 0;
}
.navigation a {
text-decoration: none;
display: block;
padding: 15px;
color: white;
}
.navigation a:hover {
background: #000;
text-decoration: underline;
}
<header>
<nav>
<ul class="navigation">
<li>
<div class="search-box">
<label>
<input name="search-box" value="Search..."/>
</label>
</div>
</li>
<li><a href="#">Index</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Gallery</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
Thank you so much for your help. Really forgotten to put the class in the div here in the file, but not in the link I passed rsrs Well this is right in the margin 0 of the body. I always get distracted by this. When the ul padding hadn’t noticed this. If you don’t give the padding, there’s a space in the left corner. If I change Justify-content to flex-end, then this padding would not be necessary, but to the left is accurate. The only problem is still the search text box issue. I want it to stay inside the u,. be it in the right or left corner and not out of context.
– Momo Deviluke
That’s exactly what I wanted as shown in the answer?
– Sam
Almost this. Only part of the text box was missing as I explained above. I want the search box to be inside the box model like the links. Be it in the left or right corner. It is out of content as if starting a new box model.
– Momo Deviluke
Look now.....
– Sam
Perfect. Thank you very much. If you don’t mind, could you explain to me about the changes? 1. You removed the ul background and passed it to Nav; .
– Momo Deviluke
That’s right. The background should be on Nav and not UL. Then I centered the search box and put a margin above and to the right so it doesn’t stick to the links.
– Sam
Thank you very much indeed. 1. You said that the background has to be in Nav and not in ul . Any technical/semantic explanation? 2. Finally, I think it really ends my doubts. If I want to position the search box for the beginning or the end of the box how would I do? I tried to modify the margin, but I changed the configuration of the central links, which I don’t want. I tried the align-item for flex-start and it didn’t work. Align-content has no effect when flexbox has only one line. Any suggestions?
– Momo Deviluke
It is because the blue background was only in UL. And this was affecting only UL and not Nav. You position the box by changing the position of the LI where it is. In the case of my example, I put as first LI.
– Sam