html - 如何并排放置两个元素

标签 html css

我有这个代码:

<div class="headmenus">
    <ul>
    <li><a href="index.php">HOME</a></li>
    <li><a href="about.php">ABOUT US</a></li>
    <li><a href="search.php">COURSES</a></li>
    <li><a href="vacancies.php">VACANCIES</a></li>
    <li><a href="contact.php">CONTACT US</a></li>  
    <li></li>           
    </ul>
 </div>
 <div class="searchform2">
    <form action="search.php#goto1" method="get" id="headersearch">
       <input type="hidden" name="p" value="0" />
       <input type="text" name="keyword" id="headerkeyword" placeholder="Search any keyword" value="" />
       <input type="submit" value="SEARCH" class="but1" />
    </form>
 </div>

我希望 headmenus 和 searchform2 并排放置。 现在,我在新的一行中获取了 searchform2。

这是 CSS:

.searchform2 {
    float: right;
    display: inline;
    clear: left;
    width:auto !important;
    border:2px solid #616566;
}
.searchform2 input {
    border:2px solid #616566;
    float: left;
}
.searchform2 .but1 {
    background: url("images/search.png") no-repeat scroll 8px 9px #89AB20;
    border: 0 none !important;
    color: #FFFFFF !important;
    float: right !important;

    display: inline;
    font-weight: bold;
    padding: 6px 12px 6px 23px !important;
    width: auto !important;
    font-family: Arial;
    font-size: 12px;
    height: 30px;
    margin-right: 0 !important;
    cursor:pointer;
}

这是 headmenus css:

.headmenus {
    background: none repeat scroll 0 0 #0086B2;
    display: inline;
    float: left;
    margin: 0;
    width: 100%;
}
.headmenus ul {
    border-bottom: 1px solid #FFFFFF;
    border-top: 1px solid #FFFFFF;
    display: inline;
    float: left;
    font-family: 'texgyreadventorregular';
    font-size: 14px;
    margin: 0;
    padding: 0;
    width: 100%;
}
.headmenus ul li {
    border-right: 1px solid #FFFFFF;
    color: #FFFFFF;
    display: inline;
    float: left;
    list-style-type: none;
    padding: 0;
    text-align: center;
    width: 13.35%;
}

.headmenus ul li a {
    color: #FFFFFF;
    display: inline;
    float: left;
    font-family: 'texgyreadventorregular';
    font-size: 14px;
    list-style-type: none;
    text-align: center;
    width: 100%;
    padding:5px 0px;
}
.headmenus ul li:last-child {
    border-right: 0 none;
    float: right;
    width: auto; !important
}

.headmenus ul li:hover {
    background: #89ab20;
    cursor: pointer;
}
.headmenus ul li.active {
    background: #89ab20;
}

最佳答案

Simple just add one class on headmenus ( float:left; ) and remove (clear:left) on .searchform2, just copy paste below new/updated code:

.searchform2 {
float: right;
display: inline;
width:auto !important;
border:2px solid #616566;
}
.searchform2 input {
border:2px solid #616566;
float: left;
}
.searchform2 .but1 {
background: url("images/search.png") no-repeat scroll 8px 9px #89AB20;
border: 0 none !important;
color: #FFFFFF !important;
float: right !important;

display: inline;
font-weight: bold;
padding: 6px 12px 6px 23px !important;
width: auto !important;
font-family: Arial;
font-size: 12px;
height: 30px;
margin-right: 0 !important;
cursor:pointer;
}

.headmenus { float:left} 

关于html - 如何并排放置两个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21205889/

相关文章:

html - 使用 CSS 制作箭头

javascript - Safari 7 上的必应 map 问题

javascript - 在页面加载时激活 jQuery img 和文本操作

javascript - 如果具有样式绝对位置的 div 重叠在其上,如何阻止在特定位置可编辑的内容

javascript - 如何在滚动网站时显示我的文字

javascript - 单击前进和后退浏览器按钮时保留 javascript 数据

javascript - 下拉菜单在移动设备上变形(Google Nexus 5)

css - SCSS 变量作为@extend 类

jquery - 使用 JQuery 更改其他部门的事件类

jquery - Bootstrap 3 下拉菜单 : on Hover and on Click