CSS 填充不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5926385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS Padding not Working?
提问by Tara
Why does the search box herenot have 15px padding to the right? This is the CSS:
为什么这里的搜索框右侧没有 15px 填充?这是CSS:
#element_right {
padding: 120px 15px 0px 0px;
color:#161514;
font-family:helvetica, sans-serif, Arial;
font-size: 13px;
background: #f4f4f4;
width: 270px;
height: 100%;
float: right;
}
I'm using Chrome
我正在使用 Chrome
采纳答案by slhck
This should work (if that's what you're really trying to achieve):
这应该有效(如果这是您真正想要实现的目标):
#element_right {
padding: 120px 35px 0px 0px;
color: #161514;
font-family: helvetica, sans-serif, Arial;
font-size: 13px;
background: #F4F4F4;
width: 270px;
height: 100%;
float: right;
}
回答by tytsim
To reach your effect, setting margin is a more suitable way.
为了达到您的效果,设置边距是一种更合适的方式。
Of course, it would be in conflict with the width as your child element with 280px of width break the entire structure.
当然,它会与宽度冲突,因为您的子元素宽度为 280px 会破坏整个结构。
I suggest you to remove the width in child element and make width effect at #element_right with a 295px of width the same with boxes below.
我建议您删除子元素中的宽度,并在 #element_right 处设置宽度效果,宽度为 295px,与下面的框相同。
So the search box's width and horizontal position would exactly be identical to the boxes below besides the border and box shadow.
因此,除了边框和框阴影之外,搜索框的宽度和水平位置将与下面的框完全相同。
EDIT:Delete misleading answer.
编辑:删除误导性的答案。
回答by CornflakesDK
Just check with opera, and your 15px padding works, you are just filling it with the search bar
只需检查歌剧,你的 15px 填充就可以了,你只是用搜索栏填充它
回答by David Fells
The width of the contents of the search div doesn't leave room for padding, Shrink your input to width:190px
搜索 div 内容的宽度不会为填充留出空间,将输入缩小到宽度:190px