我想要达到上载图片中提到的预期结果。这是两种视图的解释:
我一直希望区域A和区域C之间的边距为20px。如果屏幕尺寸发生变化,则区域C应填满间隙(如视图2所示),使区域A和区域C之间的边距始终保持20px。当前,每当屏幕尺寸发生变化时,区域A和区域C之间的间隙就会增大或减小我不希望它由C区填充。
index.html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>Learn</title>
<link href = "styles.css" rel = "stylesheet">
</head>
<body>
<div style="text-align:center;">
<div class="boxA">
<h2>A</h2>
<div class="boxD"><h2>D</h2></div>
<div class="boxD"><h2>D</h2></div>
</div>
<div class="boxB">
<h2>B</h2>
</div>
<div class="boxC">
<h2>C</h2>
</div>
</div>
</body>
</html>
styles.css
html, body {
margin:0;
padding:0;
width:100%;
height:100%;
}
body, h2{
margin: 0;
}
.boxA{
width: 500px;
height: 580px;
background-color: #006400;
margin-top: 20px;
margin-right: 20px;
display: inline-block;
margin-bottom: 0px;
}
.boxB{
width: 300px;
height: 350px;
background-color: blue;
display: inline-block;
}
.boxC{
width: 100%;
background-color: yellow;
margin-top: 20px;
position:absolute;
bottom: 0px;
}
.boxD{
width:220px;
display: inline-block;
background-color: red;
margin-left:20px;
float:left;
}
注意:我想仅通过CSS来实现。没有Java语言。
该flexbox
属性在这里派上用场。在Mozilla Developer Network或CSS-Tricks上了解有关它的更多信息。
的CSS3弹性盒,或Flexbox的,是提供用于一个页面,使得元件的行为可预测当页面布局必须适应不同的屏幕尺寸和不同的显示装置上的元件的配置的布局模式。对于许多应用程序,柔性盒模型提供了一种对块模型的改进,因为它不使用浮点数,也不会使用弹性容器的边距随其内容的边沿收缩。
我复制了您提供的图像,并将内容与页脚的比例设置为4:1(或值的80%至20%)。请查看下面的代码,并确保检查出全屏版本以确保其正常运行,或者检查此JSFiddle。您可以根据需要更改值,但主要部分是这样的:
.wrapper {
display: flex;
flex-direction: column;
align-items: stretch;
align-content: stretch;
justify-content: flex-start;
}
它会在各种子元素中重复出现,以适应需要。
body,
html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.wrapper {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: stretch;
align-content: stretch;
justify-content: flex-start;
}
.container {
display: flex;
flex-flow: row wrap;
height: 80%;
width: 100%;
background: lightgray;
}
.green {
display: flex;
flex-flow: row wrap;
margin: 20px;
width: 60%;
background: lightgreen;
}
.box {
width: calc(50% - 50px);
margin: 20px;
background: darkgreen;
box-sizing: border-box;
}
.blue {
margin: 20px;
width: 30%;
max-height: 50%;
background: blue;
}
.footer {
height: 20%;
background: lightblue;
}
<div class="wrapper">
<div class="container">
<div class="green">
a
<div class="box">d</div>
<div class="box">d</div>
</div>
<div class="blue">
b
</div>
</div>
<div class="footer">
c
</div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句