行极元素与块级元素

300 阅读1分钟

行极元素

特点:多个元素展示在一行,不可以设置宽和高。

常见的行极元素:a span i

元素水平垂直都居中的方式:

text-align:center;

line-height=height;

<style>
 .wrap1{
        width:300px;
        height:300px;
        text-align: center;
        line-height: 300px;
        border: 1px solid;
    }
</style>
<body>
    <div class="wrap1">
        <span>hello world</span>
    </div>
</body>

#块极元素

特点:一个元素展示在一行,可以设置宽高。

常见的块极元素:div ul p li h1~h6

元素水平垂直都居中的方式:

margin:x auto;

X=父元素的高度/2-该元素的高度/2

<style>
 .wrap1{
        width:300px;
        height:300px;
        border: 1px solid;
}
.con{
     width: 100px;
     height: 100px;
     border: 1px solid;
     margin: 100px auto;
}
    
    
</style>


<body>
    <div class="wrap1">
       <div class="con">2222</div>
    </div>