在这种情况下,我将只使用div元素,以及描述域的好类。您可以上下争论使用各种 HTML 元素来提供更好的意图语义含义,但例如在dialog元素的情况下,它不是用于在戏剧中的角色之间编写对话,但是它是有意的向用户显示一个对话框以进行交互。但是,您可以在 CSS 中根据您的心愿更改和设置该元素的样式这一事实非常棒 - 但我不建议您这样做。
原因很简单,除非您小心,否则您会为每个此类元素覆盖该行为和外观。假设这是一个剧作家的交互式应用程序,您可能希望在剧中除了“对话”之外还包括对话。
我提出这个解决方案:
.character{
display: block;
float: left;
}
.line{
margin-bottom: 20pt;
width: 400px;
margin-left: 50pt;
}
使用以下 HTML:
<div class="character">Jeff</div>
<div class="line">This sure is a nice website we've got now.</div>
<div class="character">Joel</div>
<div class="line"> It certainly is. By the way, working at FogCreek rocks.</div>
<div class="character">Jeff</div>
<div class="line">Of course it does. Have you played Rock Band yet?
<br/>It's a lot of fun.</div>
运行 JSFiddle:https ://jsfiddle.net/quz9cj2f/6/
现在你实际上可以实现一些标准的播放格式,我从这个地方删减了:http: //ptfaculty.gordonstate.edu/lking/CPF_play_formatting2.pdf
.play {
font-family: courier;
}
.play{
margin-top: 1in;
margin-left: 1.5in;
margin-right: 1in;
margin-bottom: 1in;
}
.character {
display: block;
margin-left: 4in;
text-transform: uppercase;
}
.direction:before{
margin-left: 2.75in;
content: "(";
}
.direction:after{
content: ")";
}
.line {
margin-bottom: .3in;
}
使用此 HTML:
<div class="play">
<div class="character">Jeff</div>
<div class="direction">JEFF is enthusiastic!</div>
<div class="line">This sure is a nice website we've got now.</div>
<div class="character">Joel</div>
<div class="direction">Jumping continuously</div>
<div class="line"> It certainly is. By the way, working at FogCreek rocks.</div>
<div class="character">Jeff</div>
<div class="line">Of course it does. Have you played Rock Band yet?
<br/>It's a lot of fun.</div>
</div>
工作 JSFiddle:https ://jsfiddle.net/quz9cj2f/9/
或者您可以全力以赴并使用 CSS 属性选择器并为元信息创建自定义属性:
.play {
font-family: courier;
}
.play{
margin-top: 1in;
margin-left: 1.5in;
margin-right: 1in;
margin-bottom: 1in;
}
.character {
display: block;
margin-left: 4in;
text-transform: uppercase;
}
.line[direction]:before{
margin-left: 2.75in;
content: "(" attr(direction) ")";
display: block;
}
.line {
margin-bottom: .3in;
}
现在您已经摆脱了额外的元素,并将元信息添加为属性 - 现在您可以很容易地将其从 JSON 或 XML 或其他交换格式的某种不错的数据结构转换为:
<div class="play">
<div class="character">Jeff</div>
<div direction="Enthusiastic" class="line">This sure is a nice website we've got now.</div>
<div class="character">Joel</div>
<div direction="Shaking his head" class="line"> It certainly is. By the way, working at FogCreek rocks.</div>
<div class="character">Jeff</div>
<div class="line">Of course it does. Have you played Rock Band yet?
<br/>It's a lot of fun.</div>
</div>
https://jsfiddle.net/quz9cj2f/11/