Css 如何在div中的元素上使用忽略填充
我让文本和Css 如何在div中的元素上使用忽略填充,css,positioning,padding,Css,Positioning,Padding,我让文本和在一个div中垂直交替,并在div中添加了左侧填充,但我不希望单词之间的水平规则受到填充的影响 有办法排除他们吗 .menuoptions { height:30px; width:225px; color:#666; line-height:30px; font-weight:bold; padding-left:10px; } 我尝试了.menuoptions hr{…}并添加了负数填充,但没什么令人惊讶的是,它没有起作用 示例:您
在一个div中垂直交替,并在div中添加了左侧填充
,但我不希望单词之间的水平规则受到填充的影响
有办法排除他们吗
.menuoptions {
height:30px;
width:225px;
color:#666;
line-height:30px;
font-weight:bold;
padding-left:10px;
}
我尝试了.menuoptions hr{…}
并添加了负数填充,但没什么令人惊讶的是,它没有起作用
示例:您只需使用负数
左边距
.menuoptions hr {
margin-left: -10px;
}
这是因为您尚未重置自定义属性。像
,
等。默认情况下,有一些填充和边距,当您添加属性时,它会相应地填充
如果浏览器之间存在这种不一致,我建议您使用CSS重置
这将使您的所有差异正常化,并使您的页面在所有浏览器中具有一致的一致性
代码:
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
希望这能有所帮助。您不能排除它们本身,负数填充是不允许的,但您可以在
或者,您可以使用ul
,这是正确的方法:
<ul>
<li>Firewalls</li>
<li class="sep"></li>
<li>Security In Education</li>
<li class="sep"></li>
<li>SSL VPN Encryption</li>
<li class="sep"></li>
<li>Wireless Access Points</li>
</ul>
你真的应该使用一个合适的菜单ul/li
结构,然后使用边框底部
,我可以试试看它是如何工作的啊,我离它太近了!为什么负边距可以,但不可以填充?这仅仅是因为盒子模型的性质;填充将内容进一步推到框内,远离内边缘(本质上是框本身的一部分),而边距将框周围的其他内容推离外边缘。如果你这样想的话,负填充毫无意义:)关于盒子模型的更多信息,你可以在上查看这篇文章。更多信息,供将来参考Hanks Nathan,我将确保在将来使用它仍然没有回答这个问题,尽管答案将是OP想要的补丁,因为CSS重置将解决他的问题@纪元
<ul>
<li>Firewalls</li>
<li class="sep"></li>
<li>Security In Education</li>
<li class="sep"></li>
<li>SSL VPN Encryption</li>
<li class="sep"></li>
<li>Wireless Access Points</li>
</ul>
ul {
list-style:none;
margin:0;
padding:0;
color:#666;
font-weight:bold;
width: 300px;
}
ul > li {
padding:5px;
}
ul > li.sep {
height:1px;
border-bottom: 1px solid #aaa;
padding:0;
}