CSS:具有提交按钮样式的输入字段

标签 css

我目前正在使用一个输入字段来搜索我的页面。但是我遇到了一些 css 样式问题。我在输入字段中放置了提交按钮,它是一个放大镜的图像。问题是按钮不会通过跨浏览器留在原处。在 Firefox 中看起来不错,但在其他浏览器中看起来很糟糕。

如何让提交按钮始终位于输入字段内? EXAMPLE

谢谢!

与对象相关的 CSS

<style>
.search-input {
    padding: 0 5px 0 22px;
    border: 2px solid #DADADA;
    height: 30px;
    font-size: 12px;
    line-height: 30px;
    border-radius: 25px;
    -moz-border-radius: 25px;
    -webkit-border-radius: 25px;

    background: #FFF; /* old browsers */

}

.search-input li {
list-style: none outside none;
}


.search-submit {
    width: 13px;
    height: 13px;
    border: none;
    background: url(http://webprolearner2346.zxq.net/css-test2/images/mag-glass.png) no-repeat;
    display: block;
    position: absolute;
     right: 170px;
    text-indent: -9999em;
    top: 60px;
}

.search{
    float: right;
    margin-right: 30px;
    margin-top: 35px;
}
</style>

HTML

<div id="header">
<div class="search"><input type="text" class="search-input" name="search" value="Search"/><input type="submit" class="search-submit" /></div>
</div>

最佳答案

使用我遇到的这种更好的方法。它运行良好,并使用 Web 开发人员工具进行了测试。干杯@!!!

HTML

<div id="header">
    <form id="search">
        <input id="searchField" type="text" />
        <input id="searchSubmit" type="submit" value="" />
    </form>
</div>

CSS

#search{
    float: right;
    margin-right: 30px;
    margin-top: 35px;
}


#searchField{
    border: 1px solid #FFEDE8;
    float: left;
    height: 20px;
    padding-right: 25px;
    width: 140px;}


#searchSubmit{
    background: url("http://webprolearner2346.zxq.net/css-test2/images/mag-glass.png") no-repeat scroll 0 0 transparent;
    border: medium none;
    cursor: pointer;
    height: 20px;
    margin-left: -22px;
    margin-top: 5px;
    width: 20px;
}

关于CSS:具有提交按钮样式的输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11912647/

相关文章:

html - div底部的元素

jquery - 滚动多个像素时将位置更改为固定 (jQuery)

html - 为H1设置多种背景颜色

html - 如何使用 html 在 iframe 中定位图像?

CSS Float 属性使 DIV 不可点击

html - 设置嵌套的 html 元素可见

javascript - angularJs检查是否输入了输入

java - javaFX中具有不同大小节点的TreeTableView

html - 在 div 宽度 :100% leaving some margin in all sides 内居中文本框

html - 在 HTML 表格中使用 CSS 交叉