为什么这些块在悬停时相互依赖?如何让它们独立悬停?截至目前,第一个list__item取决于第二个list__item。
.list {
display: flex;
flex-wrap: wrap;
align-items: stretch;
margin: 0;
padding: 0;
}
.list__item {
background: none;
border: 1px solid grey;
list-style: none outside;
display: flex;
flex-direction: column;
justify-content: center;
width: 23.72%;
margin: 0 0 20px 1.7%;
word-wrap: break-word;
}
.list__item:hover .list__descr {
display: block;
}
.list__name {
font-size: 14px;
color: #333;
font-weight: 700;
line-height: 1.286;
padding: 20px 8px;
height: 73px;
}
.list__descr {
display: none;
padding: 0 8px;
font-size: 12px;
color: #505050;
}
.list__descr-more {
font-size: 11px;
color: #787878;
line-height: 1.909;
padding-left: 10px;
padding-bottom: 10px;
}

<ul class="list">
<li class="list__item">
<div class="list__img">
</div>
<div class="list__title">
Lorem ipsum dolor sit amet, consectetur.
</div>
<p class="list__descr">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vitae, pariatur! Quasi sed eaque praesentium ea odio voluptatibus repudiandae commodi, ut cupiditate perferendis voluptate provident, nobis ullam doloribus accusantium omnis perspiciatis.</p>
<div class="list__descr-more">Lorem ipsum dolor.</div>
</li>
<li class="list__item">
<div class="list__img">
</div>
<div class="list__title">
Lorem ipsum dolor sit amet, consectetur.
</div>
<p class="list__descr">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vitae, pariatur! Quasi sed eaque praesentium ea odio voluptatibus repudiandae commodi, ut cupiditate perferendis voluptate provident, nobis ullam doloribus accusantium omnis perspiciatis.</p>
<div class="list__descr-more">Lorem ipsum dolor.</div>
</li>
</ul>
&#13;
答案 0 :(得分:2)
这是因为align-items: stretch
是默认并且 flex-items stretch
到填充 交叉轴上的 flex-container ,其高度由高度决定>“最高”一个。
因此,为了防止只是将值更改为flex-start
,然后保留其高度:
.list {
display: flex;
flex-wrap: wrap;
align-items: flex-start; /* modified */
margin: 0;
padding: 0;
}
.list__item {
background: none;
border: 1px solid grey;
list-style: none outside;
display: flex;
flex-direction: column;
justify-content: center;
width: 23.72%;
margin: 0 0 20px 1.7%;
word-wrap: break-word;
}
.list__item:hover .list__descr {
display: block;
}
.list__name {
font-size: 14px;
color: #333;
font-weight: 700;
line-height: 1.286;
padding: 20px 8px;
height: 73px;
}
.list__descr {
display: none;
padding: 0 8px;
font-size: 12px;
color: #505050;
}
.list__descr-more {
font-size: 11px;
color: #787878;
line-height: 1.909;
padding-left: 10px;
padding-bottom: 10px;
}
<ul class="list">
<li class="list__item">
<div class="list__img"></div>
<div class="list__title">
Lorem ipsum dolor sit amet, consectetur.
</div>
<p class="list__descr">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vitae, pariatur! Quasi sed eaque praesentium ea odio voluptatibus repudiandae commodi, ut cupiditate perferendis voluptate provident, nobis ullam doloribus accusantium omnis perspiciatis.</p>
<div class="list__descr-more">Lorem ipsum dolor.</div>
</li>
<li class="list__item">
<div class="list__img"></div>
<div class="list__title">
Lorem ipsum dolor sit amet, consectetur.
</div>
<p class="list__descr">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vitae, pariatur! Quasi sed eaque praesentium ea odio voluptatibus repudiandae commodi, ut cupiditate perferendis voluptate provident, nobis ullam doloribus accusantium omnis perspiciatis.</p>
<div class="list__descr-more">Lorem ipsum dolor.</div>
</li>
</ul>