简体   繁体   English

CSS位置问题

[英]CSS Position Problems

Evening, 晚间,

HTML: HTML:

<input type="text" class="search" value="Search"><input type="button" class="searchimg" value="Search" />

CSS: CSS:

input.search {
    font-size: 1em;
    color: #383838;
    margin: 7px 0 0 7px;
    padding: 3px;
    border: 1px solid #969696!important;
    background: #FEFEFE!important;
    height: 16px;
    width: 250px;
} 

input.searchimg { 
   text-indent: -99999px;
   width: 24px; 
   height: 24px; 
   display: inline;
   background: url(../images/search.jpg) 0 0 no-repeat;
   border: 0px;
   margin: 7px 0 0 0;
}

(search.jpg dimentions: 24x24px, 1px border is part of image, not CSS! http://img267.imageshack.us/img267/6779/searchr.png ) (search.jpg尺寸:24x24px,1px边框是图像的一部分,而不是CSS! http ://img267.imageshack.us/img267/6779/searchr.png)

Top version shows how it's supposed to render, the bottom picture is showing how it is actually rendering, in all broswers. 顶部版本显示了应该如何渲染,底部图片显示了在所有浏览器中的实际渲染。 It is 2px higher than it's supposed to be. 比预期高2像素。 I'm not really sure why it's doing this. 我不太确定为什么要这么做。

Thanks. 谢谢。

尝试删除行margin: 7px 0 0 7px;

Try vertical-align:top on input.search { ... } this should work because your input is affected by (previous?) inline styles. input.search { ... }上尝试vertical-align:top ,这应该可以工作,因为您的输入受(上一个?)内联样式的影响。

For the future: it's easier to operate on elements styled with display:inline-block and it's well supported in browsers (IE 7 needs an small hack, IE 6 should be dead already). 面向未来:使用display:inline-block样式化的元素更容易操作,并且在浏览器中得到很好的支持(IE 7需要一个小的技巧,IE 6应该已经死了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM