gpt4 book ai didi

html - 如何在父 div 中定位文本 block ?

转载 作者:行者123 更新时间:2023-11-28 02:30:53 26 4
gpt4 key购买 nike

我在创建响应式布局时遇到问题。我想创建一个父 div,它将具有指定的最大宽度,例如1200 像素和七个文本 block ,它们将包含在其中并具有一定的最小宽度,例如150 像素。问题在于定位父 block 中的元素,我希望在高分辨率的第一行中看到四个文本 block ,在第二行中看到三个文本 block 。根据第一行决议的决议,将有三个文本 block ,第二行以相同方式出现,第三行有一个文本 block 。如果在第一行,第二行和第三行再次降低分辨率,将有两个文本 block ,第四个等。请帮助。

目前,我设法写了这样一段代码:

.parent{
max-width: 1500px;
position: relative;
margin: 0 auto;
border: 2px solid rgb(223, 113, 113);

}
.first, .third, .fifth, .seventh{
background-color: rgb(248, 125, 77);
border: 2px solid rgb(240, 85, 24);
border-radius: 5px;
float: left;
min-width: 300px;
max-width: 375px;
margin: 16px;
padding: 5px;
}
.second, .fourth, .sixth{
background-color: rgb(102, 189, 247);
border: 2px solid rgb(29, 154, 238);
border-radius: 5px;
float: left;
max-width: 375px;
min-width: 300px;
margin: 16px;
padding: 5px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Responsive layout</title>
<link rel="Stylesheet" type="text/css" href="style.css" />

</head>

<body>
<div class="parent">
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
<div class="fourth"></div>
<div class="fifth"></div>
<div class="sixth"></div>
<div class="seventh"></div>
</div>
</body>
</html>

最佳答案

你想要这样的东西吗?

.parent{
width:1200px;
position: absolute;
margin: 0px;
border: 2px solid rgb(223, 113, 113);

}
.first, .third, .fifth, .seventh{
background-color: rgb(248, 125, 77);
border: 2px solid rgb(240, 85, 24);
border-radius: 5px;
float: left;
margin: 16px;
padding: 5px;
}
.second, .fourth, .sixth{
background-color: rgb(102, 189, 247);
border: 2px solid rgb(29, 154, 238);
border-radius: 5px;
float: left;
margin: 16px;
padding: 5px;
}


.first, .third, .fourth, .second{
width: calc(25% - (3*15.5px));
}

.seventh, .fifth, .sixth{
width: calc(100% / 3 - (3*15.5px));
}

@media all and (max-width: 1215px) {
.parent{
width: 95%;
}
.first, .third, .fourth, .second{
width: calc(100% / 3 - (3*15.5px));
}

.fourth, .fifth, .sixth{
width: calc(100% / 3 - (3*15.5px));
}
.seventh{
width: 95%;
}
}

关于html - 如何在父 div 中定位文本 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50899834/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com