css怎么设置右对齐


本文摘自PHP中文网,作者藏色散人,侵删。

css设置右对齐的方法:1、通过使用cssposition属性来实现右对齐效果;2、通过float属性实现右对齐效果;3、通过text-align属性实现右对齐效果。

本文操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

通过css设置右对齐方法详解:

1、通过css的position属性实现右对齐

1

2

3

4

5

6

7

8

9

10

11

12

13

<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;

}

效果图:

4021a61c7c023604db0cadff3eb6139.png

2、通过float属性实现右对齐

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

<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" />

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>

效果图:

e10cf9fc2cd75293821bb5a54bb3fa7.png

3、通过text-align属性实现右对齐

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<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为什么加了top移动不了

css怎么去除li的点

css如何正确命名

css border-top-right-radius属性怎么用

css如何让图片自适应屏幕大小

css 如何设置带有正方形项目的列表

css中绝对定位什么意思

如何利用css实现只在设置的框内点击链接跳转

4种移动端适配方法

css实现元素横向滚动的方法

更多相关阅读请进入《css》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...