怎样让DIV中的内容居中

 时间:2026-02-15 05:01:02

1、先说文字居中。

此处是垂直居中,关键代码height:105px;line-height:105px;两个值要相等。

<div style=' height:105px;line-height:105px;overflow:hidden;border:1px solid #FF0099;' >居中</div>

怎样让DIV中的内容居中

2、文字横向居中,关键代码text-align:center

<div style=' height:105px;line-height:105px;overflow:hidden;border:1px solid #FF0099;text-align:center'>ju zhong</div>

怎样让DIV中的内容居中

3、图片居中,代码如下。

<div style=' height:105px;width:300px;line-height:105px;overflow:hidden;border:1px solid #FF0099;text-align:center'><img src="1.png" alt="" /></div>

怎样让DIV中的内容居中

4、效果如图;

可是垂直没居中。

怎样让DIV中的内容居中

5、图片垂直居中,关节代码display: table-cell; vertical-align:middle;

代码如下;

<div style=' height:105px;width:300px;line-height:105px;overflow:hidden;border:1px solid #FF0099;text-align:center ; display: table-cell; vertical-align:middle; '><img src="1.png" alt="" /></div>

怎样让DIV中的内容居中

6、看一下效果图吧。居中了。

怎样让DIV中的内容居中

  • css如何让div内的文字居中对齐
  • html页面单选框怎么实现
  • 如何让两个div并排显示
  • 怎么让div居中
  • css中如何实现button垂直居中
  • 热门搜索
    枫泾旅游 胡志明市旅游 青岛春节旅游攻略 云南省旅游网 云南旅游酒店 国内旅游哪里好玩 跟团旅游 安庆旅游景点大全 旅游支票 甘南旅游注意事项