如何删除表单元素之间的空白区域

时间:2014-09-30 11:49:03

标签: html css

如何删除搜索input boxgo button之间的空白区域?我已经为代码示例准备了jsfiddle。链接 - jsFiddle

截图:
enter image description here
HTML:

<div class="blablabla">
<form id="search_mini" action="#" method="get">
    <div class="form-search">
        <!--<label for="search"></label>-->
        <input id="search" value="SEARCH" type="text" name="q" class="input-text" maxlength="128" autocomplete="off">
        <button type="submit" title="GO" class="button"><span><span>GO</span></span>
        </button>
        <div id="search_autocomplete" class="search-autocomplete" style="display: none;"></div>
    </div>
</form>

CSS:

#search_mini {
    width: 268px;
}
.form-search input {
    border-color: #7d7c7c;
    height: 30px;
    width: 150px;
    padding:0;
}
.form-search button.button {
    background: url(../images/bg.gif) 0 0 repeat-x;
    font-size: 12px;
    text-align: center;
    padding: 0;
    height: 36px;
    min-width: 84px;
}

提前谢谢你。

6 个答案:

答案 0 :(得分:0)

建议只是这样一个按钮,然后她与表格DEMO

一起
<form class="form-wrapper cf">
    <input type="text" placeholder="search" required>
    <button type="submit">GO</button>
</form>


.cf:before, .cf:after{
    content:"";
    display:table;
}

.cf:after{
    clear:both;
}

.cf{
    zoom:1;
}    


.form-wrapper {
    width: 450px;
    padding: 15px;
    margin: 150px auto 50px auto;
    background: #444;
    background: rgba(0,0,0,.2);
    border-radius: 10px;
    box-shadow: 0 1px 1px rgba(0,0,0,.4) inset, 0 1px 0 rgba(255,255,255,.2);
}



.form-wrapper input {
    width: 330px;
    height: 20px;
    padding: 10px 5px;
    float: left;    
    font: bold 15px 'lucida sans', 'trebuchet MS', 'Tahoma';
    border: 0;
    background: #eee;
    border-radius: 3px 0 0 3px;      
}

.form-wrapper input:focus {
    outline: 0;
    background: #fff;
    box-shadow: 0 0 2px rgba(0,0,0,.8) inset;
}

.form-wrapper input::-webkit-input-placeholder {
   color: #999;
   font-weight: normal;
   font-style: italic;
}

.form-wrapper input:-moz-placeholder {
    color: #999;
    font-weight: normal;
    font-style: italic;
}

.form-wrapper input:-ms-input-placeholder {
    color: #999;
    font-weight: normal;
    font-style: italic;
}    


.form-wrapper button {
    overflow: visible;
    position: relative;
    float: right;
    border: 0;
    padding: 0;
    cursor: pointer;
    height: 40px;
    width: 110px;
    font: bold 15px/40px 'lucida sans', 'trebuchet MS', 'Tahoma';
    color: #fff;
    text-transform: uppercase;
    background: #d83c3c;
    border-radius: 0 3px 3px 0;      
    text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3);
}   

.form-wrapper button:hover{     
    background: #e54040;
}   

.form-wrapper button:active,
.form-wrapper button:focus{   
    background: #c42f2f;
    outline: 0;   
}

.form-wrapper button:before { 
    content: '';
    position: absolute;
    border-width: 8px 8px 8px 0;
    border-style: solid solid solid none;
    border-color: transparent #d83c3c transparent;
    top: 12px;
    left: -6px;
}

.form-wrapper button:hover:before{
    border-right-color: #e54040;
}

.form-wrapper button:focus:before,
.form-wrapper button:active:before{
        border-right-color: #c42f2f;
}      

.form-wrapper button::-moz-focus-inner { 
    border: 0;
    padding: 0;
}    

答案 1 :(得分:0)

您可以尝试margin-left

&#13;
&#13;
#search_mini {
  width: 268px;
}
.form-search input {
  border-color: #7d7c7c;
  height: 30px;
  width: 150px;
  padding: 0;
}
.form-search button.button {
  background: url(../images/bg.gif) 0 0 repeat-x;
  font-size: 12px;
  text-align: center;
  padding: 0;
  height: 36px;
  min-width: 84px;
  margin-left: -4px;/* put as your need */
}
&#13;
<div class="blablabla">
  <form id="search_mini" action="#" method="get">
    <div class="form-search">
      <!--<label for="search"></label>-->
      <input id="search" value="SEARCH" type="text" name="q" class="input-text" maxlength="128" autocomplete="off">
      <button type="submit" title="GO" class="button"><span><span>GO</span></span>
      </button>
      <div id="search_autocomplete" class="search-autocomplete" style="display: none;"></div>
    </div>
  </form>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

float:left添加到.form-search input element

示例:http://jsfiddle.net/2nwp36nj/2/

#search_mini {
    width: 268px;
}
.form-search input {
    border-color: #7d7c7c;
    height: 30px;
    width: 150px;
    padding:0;
    float: left;
}
.form-search button.button {
    background: url(../images/bg.gif) 0 0 repeat-x;
    font-size: 12px;
    text-align: center;
    padding: 0;
    height: 36px;
    min-width: 84px;
}
<div class="blablabla">
    <form id="search_mini" action="#" method="get" _lpchecked="1">
        <div class="form-search">
            <!--<label for="search"></label>-->
            <input id="search" value="SEARCH" type="text" name="q" class="input-text" maxlength="128" autocomplete="off">
            <button type="submit" title="GO" class="button"><span><span>GO</span></span>
            </button>
            <div id="search_autocomplete" class="search-autocomplete" style="display: none;"></div>
        </div>
    </form>
</div>

答案 3 :(得分:0)

使用float左边的两个元素输入和按钮也需要给按钮的宽度。它看起来像是在下面的代码中工作。

http://jsfiddle.net/2nwp36nj/3/

#search_mini {
    width: 368px;
}
.form-search input, .form-search button {
    border-color: #7d7c7c;
    height: 30px;
    width: 150px;
    padding:0;
    float: left;
}
.form-search button.button {
    background: url(../images/bg.gif) 0 0 repeat-x;
    font-size: 12px;
    text-align: center;
    padding: 0;
    height: 36px;
    min-width: 84px;
}

答案 4 :(得分:0)

只需将其添加到您的元素中:

.form-search input,
.form-search button.button
{
    display: block;
    float: left;
}

你的空间实际上是由空白造成的。

答案 5 :(得分:0)

另一个有效的解决方案:您必须在input代码和button代码之间插入评论。像这样:

<input id="search" value="SEARCH" type="text" name="q" class="input-text" maxlength="128" autocomplete="off"><!--
--><button type="submit" title="GO" class="button"><span><span>GO</span></span>