[英]HTML Left and Right Align Elements
為此,我做到了這一點:
<table style="width:100%;">
<tr>
<td style="width:50%;text-align: left;">left</td>
<td style="width:50%;text-align: right;">right</td>
</tr>
</table>
如何在不使用表格的情況下以最簡單的方式(最少標記)實現此目的? 我只想將2個元素對齊到最左邊和右邊。
有數百個2列布局,但它們更符合頁面布局,看起來有點過分。
一些html:
<div class="left">left</div>
<div class="right">right</div>
一些CSS:
.left, .right {
width: 50%; /* Floated elements technically need a width specified. */
}
.left {
float: left;
}
.right {
float: right;
}
像這樣的東西:
CSS
<style type="text/css">
#primary {
width: 100%;
}
.secondary {
width: 50%;
}
.leftcolumn {
float: left;
text-align: left;
}
.rightcolumn {
float: right;
text-align: right;
}
</style>
HTML
<div id="primary">
<div class="secondary leftcolumn">
<p>This will be on the left</p>
</div>
<div class="secondary rightcolumn">
<p>This will be on the right</p>
</div>
</div>
雖然我將leftcolumn
和rightcolumn
更改為每個將包含的內容特定的內容(支持CSS的語義命名方法而不是結構)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.