html - flex-box 如何制作更具响应性的“盒子”
问题描述
我希望这些盒子反应更快,并始终保持 1:1 的比例。当我将 min-width 设置为 .box1、.box2 时,它们总是占据 .box 的整个宽度!就像他们对身高没有反应一样?
我不想让盒子成为弹性项目的全宽(或高度),因为我希望它们之间有一些空间,而且我不希望它们溢出它们的 .box 容器,..(我想把它们放在里面)
我知道我可以使用媒体查询来调整 .box1,.box2,.box3, .. 但还有其他方法吗?
.grid {
width: 100%;
height: 100%;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
//margin:0 -40px;
}
/*first two children*/
.grid>.box:not(:last-child) {
background: grey;
width: 50%;
}
.box1,
.box2,
.box3 {
border: 2px solid #111;
width: 100px;
height: 100px;
transform: rotate(-45deg);
text-align: center;
}
.box1,
.box2 {
margin: 0 auto;
}
.box p {
position: relative;
color: white;
}
<div class="wrapper">
<div class="grid">
<div class="box">
<div class="box1">
<p>Here is something !</p>
</div>
</div>
<div class="box ">
<div class="box2"></div>
</div>
<div class="box ">
<div class="box3"></div>
</div>
</div>
</div>
解决方案
我没有得到你的完整查询,但如果你想在不手动调整高度的情况下做出方形响应,那么使用 padding hack
.box1,
.box2,
.box3{
width: 100%;
height: 0;
padding-bottom: 50%;
postition:relative
background: red;
}
推荐阅读
- ios - 如何在 iOS 中预加载 UIWebView?
- python - tensorflow多标签分类mnist
- javascript - 如何在 html 上从 nodejs 调用函数?
- r - 漂亮打印数据框时如何增加列之间的空间?
- javascript - 我如何在反应中显示错误;我从 redux 得到数组错误?
- c++ - 模板参数提取和修改
- php - 是否可以在一个 php 标签之间放置一半的 while 循环,另一半在另一个 php 标签中,就像我在那里展示的那样?
- java - java中的加权中位数
- c++ - 使用集合交集的意外向量行为
- android - 斜角连接角设计 android 按钮形状