Html 试图在我的<;h2>;及<;ul>;元素
我试图减少h2和ul元素之间的空间。 但这似乎是不可能的利润,ul元素似乎不允许有这种利润。 这需要一些技巧吗?因为我在尝试利润,但它不起作用 我的html:Html 试图在我的<;h2>;及<;ul>;元素,html,css,Html,Css,我试图减少h2和ul元素之间的空间。 但这似乎是不可能的利润,ul元素似乎不允许有这种利润。 这需要一些技巧吗?因为我在尝试利润,但它不起作用 我的html: <div id="page"> <div id="info"> <h2>List 1</h2> <ul> <li><strong>List Item 1
<div id="page">
<div id="info">
<h2>List 1</h2>
<ul>
<li><strong>List Item 1</strong> this is the content 1</li>
<li><strong>List Item 2</strong> this is the content 2</li>
<li><strong>List Item 3</strong> this is the content 3</li>
</ul>
<h2>List 2</h2>
<ul>
<li><strong>List Item 1</strong> this is the content 1</li>
<li><strong>List Item 2</strong> this is the content 2</li>
<li><strong>List Item 3</strong> this is the content 3</li>
</ul>
</div>
</div>
使用CSS重置。这基本上意味着在应用自己的样式之前重置所有默认填充、边距和其他基本属性 浏览器会给标签一个默认的边距,不同浏览器的边距会有所不同,所以你最好自己重新设置它们 至少您应该在CSS的顶部放置这样的内容:
*{margin:0;padding:0}
环顾四周,你会发现一个像样的预先制作的CSS重置。下面是一个流行的由以下人员制作的:
在CSS的顶部包含这一点,您就不必担心默认浏览器样式会妨碍您。从我所看到的(仅使用您提供的代码),您没有考虑浏览器的默认设置。如果您没有使用Eric Meyers重置。简言之,它会将所有浏览器中的所有设置都设置回零,以便站点有一个起点
但如果您不想使用或无法使用此重置css文件,则需要显式定义设置。在您的情况下,需要为每个元素添加以下内容,并删除当前存在的间隙:
#page ul
{
list-style:none;
background:pink;
margin-top: 0; /*override the default browser setting for the UL element*/
}
如果您不希望H2和UL之间有任何空格,请将H2元素的边距底部更改为等于0。我希望这就是您在本期中所寻找的。“ul元素似乎不允许有这样的余量”——这是错误的。使用浏览器的DOM检查器工具找出不需要的间距的来源。对于我的情况,只需要主体{lineheight:1;}
/* 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;
}
#page ul
{
list-style:none;
background:pink;
margin-top: 0; /*override the default browser setting for the UL element*/
}