html - 搜索框内的搜索按钮

标签 html css

我想在搜索框内实现一个搜索按钮,我发现它很有用:Search button inside the search box like Bing

但是当我将代码放入我的站点时,它没有按预期方式显示,这是怎么回事?

这是代码

HTML

<input type="text" id="q" />
<input type="button" id="b" value="Search" />

CSS

#q, #b { 
   margin: 0 
}
#q { 
   padding 5px; 
   font-size: 2em; 
   line-height: 30px 
}
#b { 
   /* image replacement */
   text-indent: -99999px; 
   width: 30px; 
   height: 30px; 
   display: block;
   background: gray url(button.png) 0 0 no-repeat;
}

code

最佳答案

试试这个

#q, #b { 
   margin: 0 
   display:inline-block;
   float:left;
}
#q { 
   padding 5px; 
   font-size: 2em; 
   line-height: 30px; 
   border:none;
}
#b { 
   /* image replacement */
    margin-top:8px;
   width: 30px; 
   height: 30px; 
   background: gray url(button.png) 0 0 no-repeat;
}
.border {
   border:#ccc solid 1px; 
   width:390px;
}
.clear {
   clear:both;
}

<div class="border">
<input type="text" id="q" />
<input type="button" id="b" value="Search" />
    <div class="clear"></div>
</div> 

Check this out

关于html - 搜索框内的搜索按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18973353/

相关文章:

html - 在 <code> 中使用 <div> 可以吗?

javascript - 在 CSS 中使用 JavaScript

html - 可调整大小的导航栏和按钮 'a la' Forbes

html - 为什么内部div显示在容器div下面?

javascript - 使用 jQuery append HTML 对象时的唯一 ID

html - CSS 将多个列表项向右上方移动

html - 我怎样才能用CSS显示边框?

html - Facebook 评论框插件自动改变宽度

jquery - 禁用 textarea 调整大小处理程序 jQuery css

html - 使用 CSS 保持两列相同的高度