在 CSS 中有很多方法可以让块元素右对齐。下面我们来一一了解。
① 使用 float: right;
<p>使用 float: right; 让块元素右对齐:</p>
<pre>
.right{
float: right;
} <p>使用 text-align: right; 让块元素右对齐(前提是该块元素内文本为左对齐):</p>
<pre>
.right{
text-align: right;
} <p>使用 margin-left 为负值 让块元素右对齐:</p>
<pre>
.right{
margin-left: -50px; /* 50px 为该块元素的宽度 */
} <p>使用 position: absolute; 让块元素右对齐。</p>
<pre>
.right{
position: absolute;
right: 0;
}