1. 程式人生 > 其它 >CSS(10)display和浮動

CSS(10)display和浮動

浮動

標準文件流

塊級元素 : 獨佔一行

h1~h6 p div 列表...

行內元素 : 不獨佔一行

span a img strong...

行內元素 可以被包含在 塊級元素中,反之,則不可以

display

也是一種實現行內元素排列的方式,但是我們很多情況通用float

block      塊元素
inline 行內元素
inline-block 是塊元素,但是可以內聯,在一行
none

程式碼:

html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>

<link rel="stylesheet" href="../display/style.css">

</head>
<body>

<div>
塊元素div
</div>

<span>
行內元素span
</span>

</body>
</html>

css:

/*
block 塊元素
inline 行內元素
inline-block 是塊元素,但是可以內聯,在一行
none
*/

div{
width: 100px;
height: 300px;
border: 2px solid #779dbd;
display: none;
}

span{
width: 100px;
height: 300px;
border: 2px solid #779dbd;
display: block;
}

浮動

html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>

<link rel="stylesheet" href="../浮動/style.css">

</head>
<body>

<div>
<img src="../浮動/resources/qqyzml.png" alt="">
</div>

<div>
<img src="../浮動/resources/王一博.jpg" alt="" width="200" height="500">
</div>

<div>
<img src="../浮動/resources/表情包.jpg" alt="">
</div>

</body>
</html>

css:

div{
width: 200px;
height: 500px;
border: 2px solid red;
}

div:nth-of-type(1){
display: inline-block;
float: left;
}

div:nth-of-type(2){
display: inline-block;
float: right;
}

div:nth-of-type(3){
display: inline-block;
float: left;
}