首頁 >web前端 >前端問答 >css怎麼設定右對齊

css怎麼設定右對齊

藏色散人
藏色散人原創
2021-04-09 14:52:0529631瀏覽

css設定右對齊的方法:1、透過使用cssposition屬性來實現右對齊效果;2、透過float屬性實現右對齊效果;3、透過text-align屬性實現右對齊效果。

css怎麼設定右對齊

本文操作環境:windows7系統、CSS3&&HTML5版、Dell G3電腦。

透過css設定右對齊方法詳解:

1、透過css的position屬性實作右對齊

<h2>右对齐</h2>
<p>以下实例演示了如何使用 position 来实现右对齐:</p>
<div class="right">
  <p>元素右对齐</p>
</div>
css代码:
.right {
    position: absolute;
    right: 0px;
    width: 300px;
    border: 3px solid #73AD21;
    padding: 10px;
}

效果圖:

css怎麼設定右對齊

2、透過float屬性實作右對齊

<html>
<head>
<style type="text/css">
img 
{
float:right
}
</style>
</head>
<body>
<p>在下面的段落中,我们添加了一个样式为 <b>float:right</b> 的图像。结果是这个图像会浮动到段落的右侧。</p>
<p>
<img  src="/i/eg_cute.gif" / alt="css怎麼設定右對齊" >
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>
</body>
</html>

效果圖:

css怎麼設定右對齊

3、透過text-align屬性實作右對齊

<html>
<head>
<style type="text/css">
h1 {text-align: center}
h2 {text-align: left}
h3 {text-align: right}
</style>
</head>
<body>
<h1>这是标题 1</h1>
<h2>这是标题 2</h2>
<h3>这是标题 3</h3>
</body>
</html>

效果圖:

css怎麼設定右對齊

【推薦學習:css影片教學

以上是css怎麼設定右對齊的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn