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 在所有浏览器上都能接触到,即我想在所有浏览器上删除 headmenus 和 searchform2 之间的空格。

这是 CSS:

.searchform2 {
    float: right;
    display: inline;
    width:auto !important;
    border:2px solid #616566;
}
.searchform2 input {
    border:2px solid #616566;
    float: left;
/*  margin-right: 15px;
    padding: 4px;
    width: auto;
    height:26px;
*/}
.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: 74.3%;
}
.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:hover {
    background: #89ab20;
    cursor: pointer;
}
.headmenus ul li.active {
    background: #89ab20;
}
.headmenus ul li:last-child {
    border-right: 0 none;
    float: right;
    width: auto; !important
}

现在发生的事情是 headmenus,当我调整它的宽度时,我可以确保它接触到输入文本框但是当我切换浏览器时我需要重新编辑那个宽度属性

最佳答案

您应该删除 .headmenus ul li 中的 border-right: 1px solid #FFFFFF;。然后按钮将彼此相邻,没有间隙。参见 this fiddle举个例子(为了可见性,元素是灰色的)。

*{box-sizing: border-box; -moz-box-sizing: border-box; 负责在所有浏览器中将其并排显示。查看this article from Paul Irish如果您对 box-sizing 属性感兴趣。

您需要确保您的 .searchform2 具有 width:25.6% !important; 以确保它填满所有空白区域。

关于html - 如何删除所有浏览器上两个并排元素之间的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21206140/

相关文章:

html - 内联 block : cannot display elements horizontally

html - 使用内联 block 时,包含宽度为 50% 的 UL 的 Div 将无法正确排列

javascript - 为什么 HTML Canvas 中的对象在放大时不显示

php - 如何将 PHP 网页转换为 PDF?

php - 如何在下拉菜单中显示图像

html - 绘制框和每个框的宽度被忽略,一般间距不起作用

css - 无法将我的 DIV 彼此对齐

css - GWT FlowPanel 不添加小部件

javascript - 如何使用 jquery 为动态创建的文本框添加事件

javascript - php中条件语句后的模态框