在IE中填充文本输入...可能吗?

时间:2009-03-03 16:48:09

标签: html internet-explorer padding textinput

我有一个文本输入,搜索按钮绝对定位在它上面...为按钮腾出空间我使用了一些填充来保持文本不在按钮下面,这很好,它适用于Firefox,但不是IE。

实际上......在IE中,文本输入上的填充似乎不起作用。

他们有以下代码


<style type="text/css">
#mainPageSearch input {
    width: 162px;
    padding: 2px 20px 2px 2px;
    margin: 0;
    font-size: 12px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    background:#F3F3F3 url(form-shadow.png) repeat-x scroll left top;
    border-color:#C6C6C6 #C6C6C6 #E3E3E3;
    border-style:solid;
    border-width:1px;
    color:#666666;
}
#mainPageSearch {
    margin-bottom: 10px;
    position: relative; /* Lets me absolute position the button */
}
#mainPageSearchButton {
    display: block;
    position: absolute;
    top:0px;
    right: -2px;
    text-indent: -2000em;
    height: 22px;
    width: 22px;
    background: transparent url('images/searchBtn.png') top center no-repeat;
}
</style>


<form id="mainPageSearch" action="">
    <input type="text"/>
    <a id="mainPageSearchButton" href="#">Search</a>
</form>

我正在尝试做什么,或者我应该把它搞砸并处理搜索按钮下面的文字?

我知道我可以制作一个带有透明背景/边框的搜索框,并使用包含div来绘制样式...但这不是一个真正的选项,因为我必须在多少个地方更改它现场。

也许我会为这个文本输入创建一个新类,使其透明并将正常的文本输入样式分配给包含的div?你觉得怎么样?

编辑:抱歉,我应该包含doctype ...这里是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

另外,我遇​​到的问题是在IE 7中

9 个答案:

答案 0 :(得分:64)

尝试使用line-height

答案 1 :(得分:10)

我有这个问题,我也通过添加以下行来解决它

input 
{
    overflow:visible;
    padding:5px;
}

希望这有帮助吗?让我知道。

答案 2 :(得分:4)

尝试使用border-right代替padding-right。这对我有用。

答案 3 :(得分:4)

使输入透明并将样式放在容器div中:

http://jsfiddle.net/LRWWH/211/

HTML

 <div class="input-container">
 <input type="text" class="input-transparent" name="fullname"> 
 </div>

CSS

 .input-container {
    background:red;
    overflow:hidden;
    height: 26px;
    margin-top:3px;        
    padding:6px 10px 0px;
    width: 200px;
  }

 .input-transparent {
    background-color:transparent;
    border:none;
    overflow:hidden;        
    color:#FFFFF;
    width: 200px;
    outline:none;
  }

答案 4 :(得分:4)

只有css修复它

div.search input[type="text"] {
    width: 110px;
    margin: 0;
    background-position: 0px -7px;
    text-indent:0;
    padding:0 15px 0 15px;
}
/*ie9*/ div.search input[type="text"] {
    border-left: 25px solid transparent;
}
/*ie8*/ div.search input[type="text"] {
    border-left: 25px solid transparent;
    background-position-x: -16px;
    padding-left: 0px;
    line-height: 2.5em;
}

由于 Muhammad Atif Chughtai

答案 5 :(得分:3)

在应用填充/边距之前,你必须在'#mainPageSearch input'上使用float:left / right。

答案 6 :(得分:1)

我遇到了类似的问题 - IE正在填充输入字段,但没有使其变大,从而将文本推入其中。我通过设置输入的高度来修复它。试试吧。

答案 7 :(得分:0)

我在IE7中有以下工作。您定位的是什么版本?

<style type="text/css">

    input#test {
        padding: 10px;
    }

</style>


<input type="text" id="test" />

答案 8 :(得分:0)

宣布DOCTYPE怎么样?

在IE8中为我添加<!DOCTYPE html>填充作品。以下面的代码为例:

<!DOCTYPE html>
<html>
  <head>
    <style>
      #myInput {
        padding: 10px;
      }
    </style>
  </head>
  <body>
    <input id="myInput" value="Some text here!" />
  </body>
</html>