HTML中使文字各种居中对齐的方法(html,中对,web开发)

时间:2024-05-02 19:33:02 作者 : 石家庄SEO 分类 : web开发
  • TAG :

html文字居中代码具体示例如下:

<!DOCTYPE HTML><html lang="en"><head> <title>html文字居中测试</title> <meta charset="UTF-8"> <style type="text/css"> body{background: #ddd;} div{width:300px;height:180px;margin:10px auto;color:#fff;font-size:24px;} .box1{background: #71a879;text-align: center;} .box2{background: #6a8bbc;line-height: 200px;} .box3{background: #dea46b;text-align: center;line-height: 200px;} </style></head><body><div class="box1">html文字水平居中</div><div class="box2">html文字垂直居中</div><div class="box3">html文字水平上下居中</div></body></html>

以上代码效果在本地测试如下图:

HTML中使文字各种居中对齐的方法

那么通过本篇文章关于html文字居中的相关知识是否有更进一步的了解呢?其实这里我们主要记住这些关键点,在html中,让文字居中的css代码:

1、平水居中:text-align:center;

text-align 属性规定元素中的文本的水平对齐方式。

该属性通过指定行框与哪个点对齐,从而设置块级元素内文本的水平对齐方式。通过允许用户代理调整行内容中字母和字之间的间隔,可以支持值 justify;不同用户代理可能会得到不同的结果。

2、垂直居中:line-height:height;

line-height 属性设置行间的距离(行高)。

注释:不允许使用负值。

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:HTML中使文字各种居中对齐的方法的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:html文本换行如何实现下一篇:

3 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18