【发布时间】:2019-07-27 00:05:27
【问题描述】:
我们有几个要用来显示一些文本的图块。在每个图块悬停时,我们希望显示一个隐藏的 <div> 元素。但是,我们发现在<a> 标签内使用时,文本溢出并且没有正确对齐。
问题:
我们如何防止文本在<a> 元素中溢出?
我们尝试过,但没有奏效
.flex__container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.flex__col {
border: 1px solid black;
padding: 16px;
margin: 16px;
position: relative;
}
.flex__link:hover > .flex__text__wrapper {
display: inline-block;
}
a {
text-decoration: none;
}
.flex__text__wrapper {
display: none;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: black;
color: white;
padding: 8px;
}
.flex__text {
display: flex;
align-items: flex-start;
}
<div class="flex__container">
<div class="flex__col">
<a href="#test" class="flex__link">
<div>Data Sheet</div>
<div>Progressively fabricate market-driven</div>
<div class="flex__text__wrapper flex__white bkg--black">
<div class="flex__text">
Compellingly plagiarize interoperable bandwidth whereas holistic content.
</div>
</div>
</a>
</div>
<div class="flex__col">
<a href="#test" class="flex__link">
<div>Data Sheet</div>
<div>methodologies rather than</div>
<div class="flex__text__wrapper flex__white bkg--black">
<div class="flex__text">
Single, Optimized System Improves Productivity
</div>
</div>
</a>
</div>
<div class="flex__col">
<a href="#test" class="flex__link">
<div>Data Sheet</div>
<div>resource sucking schemas. Energistically initiate</div>
<div class="flex__text__wrapper flex__white bkg--black">
<div class="flex__text">
Complete operational and commercial readiness.
</div>
</div>
</a>
</div>
<div class="flex__col">
<a href="#test" class="flex__link">
<div>Data Sheet</div>
<div>Seamlessly optimize empowered</div>
<div class="flex__text__wrapper flex__white bkg--black">
<div class="flex__text">
Maximize productivity and protect roaming and interconnection business profitability. Maximize productivity and protect roaming and interconnection business profitability. Maximize productivity and protect roaming and interconnection business profitability.
</div>
</div>
</a>
</div>
</div>
- 我们尝试在
flex__col元素上设置一个固定高度,但由于flex__text元素中的文本各不相同,因此很难找到合适的值。我们希望能够获得期望的结果,其中溢出的任何内容都不会显示,而不是像current output下所示的那样轻轻显示。
【问题讨论】:
-
考虑使用
text-overflow: ellipsis; -
@MarkSchultheiss 在什么元素上?
-
只需将
overflow:hidden添加到flex__text__wrapper -
跟进,这将在
<div class="flex__text">上,因为其中包含您希望应用省略号的文本 - 不确定如何处理包装文本,但这可能是一个新问题
标签: html css responsive-design flexbox