如何在 2003 年之后没有在   HTML 中正确定位文本?我在前端工作中休息了很长时间



早在2003年,当我的模板被剪切到一个表中时,我就使用了;按照我想要的方式定位所有文本。

我知道这是一个新手问题,我可能应该参加一些初级css课程,但问题是——如何尽可能少地定位文本:

start at 0 px        start at 100px                                                       start at 300px

对于你在问题中发布的例子,我会这样做:

span {
display: inline-block;
}
span:nth-of-type(1) {
width: 99px;
}
span:nth-of-type(2) {
width: 199px;
}
<span>Start at 0px</span>
<span>Start at 100px</span>
<span>Start at 300px</span>

HTML

<div class="item start0">
   start at 0px
</div>
<div class="item start100">
   start at 100px
</div>
<div class="item start300">
   start at 300px
</div>

CSS

.item{
   float:left;
}
.start0{
    width:100px;
}
.start100{
    width:200px;
}
.start300{
    width:100px; // example
}

宽度是最好的选择。如果你要使用div,你需要向左浮动,否则div会被起球。

最新更新