如图布局,A的高度固定了,再A的右边有BCD三块元素,要求css实现B块 靠上对齐,D块靠下对齐,C块自由发挥。
纯css可以实现吗?
<html>
<head>
<title>测试代码</title>
</head>
<body>
<div class="content">
<div class="c-left">
A
</div>
<div class="c-right">
<div>
B
</div>
<div>
C
</div>
<div>
D
</div>
</div>
</div>
</body>
</html>
<style>
body{
margin:50px;
background-color:#fff;
}
.content{
border: 1px solid #000;
display: flex;
justify-content: space-around;
//align-items: center;
height: 20rem;
}
.c-left {
line-height: 20rem;
}
.c-right {
display: flex;
flex-direction: column;
justify-content: space-between;
}
</style>
如果不用flex的话,可以用绝对定位
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<style>
.box {
position: relative;
width: 200px;
border: 1px solid #000;
padding: 15px;
}
.inner-box {
border: 1px solid #000;
}
.right {
position: absolute;
right: 15px;
width: 80px;
height: 50px;
}
.A {
width: 100px;
height: 200px;
}
.B {
top: 15px;
}
.C {
top: 80px;
}
.D {
bottom: 15px;
}
</style>
</head>
<body>
<div class="box">
<div class="inner-box A">A</div>
<div class="inner-box right B">B</div>
<div class="inner-box right C">C</div>
<div class="inner-box right D">D</div>
</div>
</body>
</html>
3 回答5.1k 阅读✓ 已解决
5 回答2k 阅读
2 回答1.9k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.4k 阅读
4 回答2.2k 阅读
3 回答2.1k 阅读
可以 flex布局