英文:
Shifting search box to right next to hrefs
问题
You can try using flexbox to achieve the desired layout. Modify your HTML and CSS like this:
HTML:
<div class="navbar">
<div class="navbar_logo">
<a href="index.html"><img src="images/logo_transparent2.png" /></a>
</div>
<div class="navbar_text">
<ul>
<li>
<a href="index.html">Home</a>
<a href="about.html">About</a>
<a href="contact.html">Contact</a>
</li>
</ul>
</div>
<div class="search_icon">
<form class="form-inline">
<button class="btn btn-outline-none my-2 my-sm-0" type="submit">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAACiklEQVR4nO2ZzWtTURDFf25ixSiIiO22FdutG8FFa2PpX+CytRQLotD/waILrXv3piCIyySk7VYXfrRd+rVx407blaI2FSNXbyAMk7SJM3kv+g4MhMA95x3umzsz90GGDKnEELAArABbwDZQi/EJ2ASKwFVgkBRiEqgAP4D6AWMPKAMTpABngLUOHr5VVIGRpEzMAV8MTDTiMzDbaxO32jzQa+AOMAWMAkdjjMX/7gJv2qxf6pWJ2y0e4AVQ6IDnAvA0KTNziugucA041AVfWHM9ckjeGRwTW+ZEOF7HDbjDybWj5MwwDpCn066RiQYuxnrTrFHBoU7IrQ+vkzVuKDrjlgIVQf68y5zYD4HzpdAqWbYde4I8vAZeKCgdwGkL4gVB/Ap/vBWa8xakK4I0FDtvLAvNBxakW4I0VGdvTAvNDQvSbUF6Fn+MCs2PFqSy6ubxR15ofvcwcgx/HFeq/D/xar23IN1MQbI/syAtCtIwT3jjntC871EQw1DkjXdC87IF6aDSooQm0gtTSpd90oq8rEyDXk2jzMmipcCE0l6Hyc4ai4rOOWuRqhCoGd9JFZTB6iEOGImFqVlox6iln1RG3XAzeQonzCpbX4uTXbeXD4vKToR4AuRwxJIi2uhQL3V4OsnEllEFBpIwU49D0XKszmOxAczH39Ox2Mk60S5K3jszo+SMV5SBw55mhpWLiU7jJ/AYWE/aDPHKpqR0AO3iG/AIOP+b4U8urO6zptILM8Tbjvk4Y2/EIzS0GF+BD/GqJzSAV4ATyvpUmflb5JSWqC5i1fs066WZtcxMAsj9bzuzDhyhDzBwgNOs598fPXbmJn2GnGKm70xoZvrWRHPOuH0szZCB1vgFpd/exdTtQfAAAAAASUVORK5CYII=" alt=""></button>
</form>
</div>
</div>
CSS:
.navbar{
display: flex;
align-items: center;
justify-content: space-between;
background-color: #99e6e6;
}
.navbar_logo img{
width: 230px;
height: 200px;
cursor: pointer;
}
.navbar_text{
margin-right: 40px;
}
.navbar_text ul li a{
margin-left: 20px;
font-size: 24px;
}
.navbar_text a:hover {
color: black;
transition: 0.5s;
}
.search_icon form {
display: flex;
align-items: center;
}
.form-control.mr-sm-2 {
margin-left: 10px;
}
This should position the search form next to the Home link. Remember to adjust the margins and spacing as needed.
英文:
I need to change search form with icon to left next to Home
HTML
<div class="navbar">
<div class="navbar_logo">
<a href="index.html"><img src="images/logo_transparent2.png" /></a>
</div>
<div class="navbar navbar-light ">
<form class="form-inline">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-none my-2 my-sm-0" type="submit"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAACiklEQVR4nO2ZzWtTURDFf25ixSiIiO22FdutG8FFa2PpX+CytRQLotD/waILrXv3piCIyySk7VYXfrRd+rVx407blaI2FSNXbyAMk7SJM3kv+g4MhMA95x3umzsz90GGDKnEELAArABbwDZQi/EJ2ASKwFVgkBRiEqgAP4D6AWMPKAMTpABngLUOHr5VVIGRpEzMAV8MTDTiMzDbaxO32jzQa+AOMAWMAkdjjMX/7gJv2qxf6pWJ2y0e4AVQ6IDnAvA0KTNziugucA041AVfWHM9ckjeGRwTW+ZEOF7HDbjDybWj5MwwDpCn066RiQYuxnrTrFHBoU7IrQ+vkzVuKDrjlgIVQf68y5zYD4HzpdAqWbYde4I8vAZeKCgdwGkL4gVB/Ap/vBWa8xakK4I0FDtvLAvNBxakW4I0VGdvTAvNDQvSbUF6Fn+MCs2PFqSy6ubxR15ofvcwcgx/HFeq/D/xar23IN1MQbI/syAtCtIwT3jjntC871EQw1DkjXdC87IF6aDSooQm0gtTSpd90oq8rEyDXk2jzMmipcCE0l6Hyc4ai4rOOWuRqhCoGd9JFZTB6iEOGImFqVlox6iln1RG3XAzeQonzCpbX4uTXbeXD4vKToR4AuRwxJIi2uhQL3V4OsnEllEFBpIwU49D0XKszmOxAczH39Ox2Mk60S5K3jszo+SMV5SBw55mhpWLiU7jJ/AYWE/aDPHKpqR0AO3iG/AIOP+b4U8urO6zptILM8Tbjvk4Y2/EIzS0GF+BD/GqJzSAV4ATyvpUmflb5JSWqC5i1fs066WZtcxMAsj9bzuzDhyhDzBwgNOs598fPXbmJn2GnGKm70xoZvrWRHPOuH0szZCB1vgFpd/exdTtQfAAAAAASUVORK5CYII=" alt=""></button>
</form>
</div>
<div class="navbar_text">
<ul>
<li>
<a href="index.html">Home</a>
<a href="about.html">About</a>
<a href="contact.html">Contact</a>
</li>
</ul>
</div>
</div>
CSS
.navbar{
display: flex;
align-items: center;
justify-content: space-between;
background-color: #99e6e6;
}
.navbar_logo img{
width: 230px;
height: 200px;
cursor: pointer;
}
.navbar_text{
margin-right: 40px;
}
.navbar_text ul li a{
margin-left: 20px;
font-size: 24px;
}
.navbar_text a:hover {
color: black;
transition: 0.5s;
}
.form-control.mr-sm-2{
float: right;
}
I tried to change with margin-left but i think there is way better solution like serach box somehow connected with navbar texts and moves with them
答案1
得分: 0
首先,你在主导航栏和表单中使用了 "navbar" 类。你应该将其从表单的 div 中移除。
关于你的问题,如果你想将搜索表单放置在菜单旁边,你可以在该 div 中使用 "margin-left:auto;" 来实现。
另外,你可以在 "form-inline" 中使用 flex 来使搜索栏与按钮居中,还可以在 ".btn" 类中使用 order:-1; 来使搜索按钮出现在输入框的左侧。
希望对你有所帮助。
英文:
First of all, you have used navbar class in main navbar and the form. You should remove it from the form div.
About your question, if you want to position your search form right next to the menu, you can do it using "margin-left:auto;" in the div.
Also you can use flex in the form-inline to center your search bar with the button, and use order:-1; in the .btn class to make the search button to appear in the left side of input.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.navbar{
display: flex;
align-items: center;
background-color: #99e6e6;
}
.navbar_logo img{
width: 230px;
height: 200px;
cursor: pointer;
}
.navbar_text{
margin-right: 40px;
}
.navbar_text ul li a{
margin-left: 20px;
font-size: 24px;
}
.navbar_text a:hover {
color: black;
transition: 0.5s;
}
.form-control.mr-sm-2{
justify-self:end;
}
.navbar-light{
margin-left:auto;
}
.form-inline{
display:flex;
}
.form-inline .btn{
order:-1;
}
.btn img{
width:30px;
height:30px;
}
<!-- language: lang-html -->
<div class="navbar">
<div class="navbar_logo">
<a href="index.html"><img src="images/logo_transparent2.png" /></a>
</div>
<div class="navbar-light">
<form class="form-inline">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-none my-2 my-sm-0" type="submit"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAACiklEQVR4nO2ZzWtTURDFf25ixSiIiO22FdutG8FFa2PpX+CytRQLotD/waILrXv3piCIyySk7VYXfrRd+rVx407blaI2FSNXbyAMk7SJM3kv+g4MhMA95x3umzsz90GGDKnEELAArABbwDZQi/EJ2ASKwFVgkBRiEqgAP4D6AWMPKAMTpABngLUOHr5VVIGRpEzMAV8MTDTiMzDbaxO32jzQa+AOMAWMAkdjjMX/7gJv2qxf6pWJ2y0e4AVQ6IDnAvA0KTNziugucA041AVfWHM9ckjeGRwTW+ZEOF7HDbjDybWj5MwwDpCn066RiQYuxnrTrFHBoU7IrQ+vkzVuKDrjlgIVQf68y5zYD4HzpdAqWbYde4I8vAZeKCgdwGkL4gVB/Ap/vBWa8xakK4I0FDtvLAvNBxakW4I0VGdvTAvNDQvSbUF6Fn+MCs2PFqSy6ubxR15ofvcwcgx/HFeq/D/xar23IN1MQbI/syAtCtIwT3jjntC871EQw1DkjXdC87IF6aDSooQm0gtTSpd90oq8rEyDXk2jzMmipcCE0l6Hyc4ai4rOOWuRqhCoGd9JFZTB6iEOGImFqVlox6iln1RG3XAzeQonzCpbX4uTXbeXD4vKToR4AuRwxJIi2uhQL3V4OsnEllEFBpIwU49D0XKszmOxAczH39Ox2Mk60S5K3jszo+SMV5SBw55mhpWLiU7jJ/AYWE/aDPHKpqR0AO3iG/AIOP+b4U8urO6zptILM8Tbjvk4Y2/EIzS0GF+BD/GqJzSAV4ATyvpUmflb5JSWqC5i1fs066WZtcxMAsj9bzuzDhyhDzBwgNOs598fPXbmJn2GnGKm70xoZvrWRHPOuH0szZCB1vgFpd/exdTtQfAAAAAASUVORK5CYII=" alt=""></button>
</form>
</div>
<div class="navbar_text">
<ul>
<li>
<a href="index.html">Home</a>
<a href="about.html">About</a>
<a href="contact.html">Contact</a>
</li>
</ul>
</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论