【发布时间】:2019-03-02 05:20:07
【问题描述】:
我需要为每个弹性框设置不同的样式 <h1> 文本(文本对齐、字体大小等)。
我试图这样做,但它没有奏效。
我从这个网站上的答案中获取了代码 flexbox 代码,但我不确定程序员做了什么,例如我不知道.wrapper > .box-wrap > .box:last-child 是什么意思。
请您修改我的代码。谢谢。
.wrapper {
display: flex;
justify-content: space-between;
width: 100%;
}
.wrapper > * {
flex: 1;
margin: 5px;
}
.wrapper > .box-wrap {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.wrapper > .box-wrap > .box {
flex:1;
margin: 5px;
}
.wrapper > .box-wrap > .box:first-child {
margin-top: 0;
}
.wrapper > .box-wrap > .box:last-child {
margin-bottom: 0;
}
.box {
border: 1px solid;
}
.wrapper h1{
font-size:15px; font-style:italic; color:#555; text-align: left;
}
.box-wrap h1{
font-size:22px; color:#777; text-align:right;
}
.box h1{
font-size:32px; color:#CC000; text-align:right;
}
@media (max-width: 768px) {
.wrapper {
-webkit-flex-direction: column;
flex-direction: column;
}
.box h1, h1{
text-align:center;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content ="ie=edge">
<title>Test</title>
<style>
.wrapper {
display: flex;
justify-content: space-between;
width: 100%;
}
.wrapper > * {
flex: 1;
margin: 5px;
}
.wrapper > .box-wrap {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.wrapper > .box-wrap > .box {
flex:1;
margin: 5px;
}
.wrapper > .box-wrap > .box:first-child {
margin-top: 0;
}
.wrapper > .box-wrap > .box:last-child {
margin-bottom: 0;
}
.box {
border: 1px solid;
}
.wrapper h1{
font-size:15px; font-style:italic; color:#555; text-align: left;
}
.box-wrap h1{
font-size:22px; color:#777; text-align:right;
}
.box h1{
font-size:32px; color:#CC000; text-align:right;
}
@media (max-width: 768px) {
.wrapper {
-webkit-flex-direction: column;
flex-direction: column;
}
.box h1, h1{
text-align:center;
}
}
</style>
</head>
<body>
<div class="wrapper">
<div class="box">
<h1>Wrapper</h1>
</div>
<div class="box-wrap">
<div class="box">
<h1>Box-wrap</h1>
</div>
<div class="box">
<h1>Box</h1>
</div>
</div>
</div>
<header>
</body>
【问题讨论】:
-
我猜有些盒子继承了其中一个盒子的属性。