如何并排定位两个元素

时间:2014-01-18 15:10:50

标签: 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;
}

3 个答案:

答案 0 :(得分:1)

display: inline-block课程中使用headmenus

JSFIDDLE

答案 1 :(得分:1)

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} 

答案 2 :(得分:0)

更改CSS以包含display:inline-block。我相信可能会有这个伎俩