【发布时间】:2016-11-30 14:01:31
【问题描述】:
我尝试使用 flexbox,就像 flexbox 一样可以保持响应,但我很快发现在换行时不可能有选择地在行之间放置一个 div。
尝试通过 inline-block 而不是使用 flexbox 来实现,如果我忽略保持页面响应,它可以正常工作。但这就是问题的症结所在;我需要它保持响应。
无论行中有多少项目,它都应在所选(单击)图片所在行的行下方显示生物行。如果在不同的行中选择了图片,则将关闭原始 bio 行,并在新选择的图片行下方的行中重新打开。
这是我为 flexbox 管理的最接近的:
.container {
max-width: 1220px;
border: 5px solid black;
display: flex;
margin: 0 auto;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.item {
border-width: 1px;
border-style: solid;
border-color: black;
width: 200px;
height: 300px;
}
.one {
background: #B5AC01;
}
.two {
background: #ECBA09;
}
.three {
background: #E86E1C;
}
.four {
background: #D41E45;
}
.five {
background: #D41EFF;
}
.six {
background: #D4FF45;
}
body {
margin: 0px;
padding: 0px;
}
<div class="container">
<div class="item one"></div>
<div class="item two"></div>
<div class="item three"></div>
<div class="item four"></div>
<div class="item five"></div>
<div class="item six"></div>
<div class="item four"></div>
<div class="item five"></div>
<div class="item six"></div>
<div class="item one"></div>
<div class="item two"></div>
<div class="item three"></div>
</div>
这没有奏效,因为能够找到一行并在这些行之间插入一个 div 显然是一个难题。所以我改变了策略并尝试了 inline-block,结果发现虽然它不那么复杂,但它仍然很复杂。
.container {
max-width: 1220px;
border: 5px solid black;
margin: 0 auto;
font-size: 0;
}
.item {
display: inline-block;
width: 200px;
height: 300px;
margin: 0px;
padding: 0px;
border: 1px solid black;
font-size: 14pt;
color: white;
text-align: center;
line-height: 300px;
}
.bio {
height: 500px;
width: 100%;
background: #333;
color: white;
font-size: 24pt;
text-align: center;
line-height: 500px;
}
.selected {
box-shadow: inset 0 0 10px #000000;
font-weight: 800;
}
.row {
display: inline-block;
font-size: 0;
}
.subrow {
display: inline-block;
font-size: 0;
}
.one {
background: #B5AC01;
}
.two {
background: #ECBA09;
}
.three {
background: #E86E1C;
}
.four {
background: #D41E45;
}
.five {
background: #D41EFF;
}
.six {
background: #D4FF45;
}
body {
margin: 0px;
padding: 0px;
}
<div class="container">
<div class="row">
<div class="subrow">
<div class="item one">Pic</div>
<div class="item two">Pic</div>
<div class="item three selected">Clicked Pic</div>
</div>
<div class="subrow">
<div class="item four">Pic</div>
<div class="item five">Pic</div>
<div class="item six">Pic</div>
</div>
</div>
<div class="bio">
Bio goes here with pic
</div>
<div class="row">
<div class="subrow">
<div class="item four">Pic</div>
<div class="item five">Pic</div>
<div class="item six">Pic</div>
</div>
<div class="subrow">
<div class="item one">Pic</div>
<div class="item two">Pic</div>
<div class="item three">Pic</div>
</div>
</div>
</div>
运气不好。会喜欢仅 CSS/HTML 的解决方案,但如果有必要将其拉下来,我愿意接受 Javascript/jQuery。想法?在此先感谢您的时间。
编辑:有人在下面发布了一个解决方案,建议使用 offsetTop 跟踪 wrappage 以确定在哪里插入 bio 行。虽然它不是 CSS/HTML 唯一的解决方案,但它不是一个糟糕的解决方案。明天早上,当我睡得更多时,我将更多地尝试 JS 代码。
【问题讨论】:
-
那么你想要实现的是在每个偶数位置显示生物行?还是您希望它与同一行中的列元素一起使用?
-
如果您查看第二个代码 sn-p(更好的是,运行它),您会看到选择了一个“图片”,并且紧挨着该行下方的所选“图片”所在的位置,生物行显示。理想情况下(但尚未实现),如果在原始所选图片的同一行中选择了另一张图片,则生物行保持在同一位置。如果在不同的行中选择了一张图片,则简历将在所选图片下方的一行中关闭并打开。
-
所以只有一个生物行将被所有图片重复使用?给每张照片一个生物行怎么样?
-
正确,一次只显示一个生物行。如果在不同的行中选择了一张图片,则简介行会在之前的位置关闭,并在新选择的图片下方的一行中打开。
标签: javascript jquery html css flexbox