【发布时间】:2012-12-01 16:40:52
【问题描述】:
我目前正在设计一个带有 em 单位的网页。我想我并没有像我想象的那样理解它,因为在我尝试将两个单独的 span 标签与 margin-left 对齐时出现了问题。它们被放置在我的标题的左上角。使用 display:block 将它们放置在彼此之上。当我使用 margin-right 来对齐 span 标签时,较大的 span 和较小的标签没有正确对齐。我使用了相同的数字作为margin-right,但它们仍然搞砸了。
- 这是因为我使用的是 em 吗?
- 我该如何解决这个问题?
我将在下面粘贴我正在使用的代码,以便您了解我正在使用什么。希望我已经解释得够清楚了。
HTML
<div class="header1">
<span class="title">Title goes here</span>
<span class="subtitle">This is the subtitle</span>
</div>
CSS
body {
color: #333;
font-family: 'lucida grande', tahoma, verdana, arial, sans-serif;
font-size: 62.5%; /* 10px */
line-height: 1.28;
}
.main1 {
width: 96em;
/* horizontally center the website layout */
margin: 0 auto; margin-top: .8em;
text-Align: left; /* override body {text-align:center} */
}
div.header1 {
clear: both;
width: 100%;
height: 9em;
background: #ff0000;
color: #fff;
}
.title {
font: small-caps 700 3.7em "Goudy Old Style", Garamond, "Big Caslon", "Times New Roman", serif;
}
.subtitle {
font-weight: lighter;
font-size: 1.4em;
}
【问题讨论】:
-
您说您“使用 display:block 将其放置在另一个之上”,但这所做的只是将内联元素转换为块级元素。您需要使用
position: absolute;将它们放在一起。这样做,测试你有什么,然后回复你仍然有问题。 -
如果你使用
<hgroup>和<h2>Title</h2><h3>Subtitle</h3>会更有意义 -
另外,
display: block部分在哪里?margin-left:部分在哪里?您的代码中缺少它们!