首页 > 汽车 >

前端工程师之CSS常用技巧大合集(2)

2019-02-14 22:52:50 网络整理 阅读:186 评论:0

.left {

float: left;

width: 300px;

height: 100px;

background-color: red;

}

.right {

float: right;

width: 300px;

height: 100px;

background-color: blue;

}

.center {

margin: 0px 300px 0px 300px;

background-color: black;

height: 100px;

}

</style>

</head>

<body>

<div class="father">

<div class="left">1</div>

<div class="right">2</div>

<div class="center">3</div>

</div>

</body>

</html>

缺点:会存在塌陷的问题

Flex布局<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Title</title>

<style type="text/css">

.father {

display: flex;

}

.left {

width: 300px

height: 100px;

background-color: red;

}

.center {

flex:1;

height: 100px;

background-color: black;

}

.right {

width: 300px;

height: 100px;

background-color: blue;

}

</style>

</head>

<body>

<div class="father">

<div class="left"></div>

<div class="center"></div>

<div class="right"></div>

</div>

相关文章