如何使DIV中的内容居中

 时间:2024-10-12 07:25:03

只需要加上paddi艘绒庳焰ng元素,内容四周便会留下空白,实现水平垂直居中的效果

css代码如下:

.颊俄岿髭demo{

width: 200px;

border: 1px solid red;

padding: 20px;

}

HTML代码如下:

<div class="demo">

this is a test of margin

this is a test of margin

this is a test of margin

this is a test of margin

this is a test of margin

</div>

效果是这样的:

如何使DIV中的内容居中

扩展资料:

关于上述中div设置具体高度

1、内容只有一行

设置div的line-height和div的高度一样即可。

2、内容不确定有几行

这时候需要在div中再加一层结构,用p标签或者div都可以。

css代码如下:

.demo{

position: absolute;

width: 200px;

height: 200px;

border: 1px solid red;

}

p{

position: absolute;

width: 150px;

top: 50%;

left:50%;

transform: translate(-50%,-50%);

border: 1px solid black;

}

  • 怎么让div居中
  • html图片如何居中
  • 怎样在html网页中插入视频
  • 如何设置DIV的背景颜色
  • html轮播图怎么制作
  • 热门搜索
    讲文明手抄报内容 精美手抄报 一年级手抄报内容 小学生环保手抄报资料 红旗渠精神手抄报 小学四年级手抄报大全 熊猫手抄报 健康小报手抄报 孝德手抄报内容 关于祖国风光的手抄报