我有4个flexbox列,一切正常,但是当我向列添加一些文本并将其设置为较大的字体大小时,由于flex属性,它使得列比应该更宽.
我尝试使用word-break: break-word并且它有所帮助,但是当我将列调整到非常小的宽度时,文本中的字母被分成多行(每行一个字母),但是列的宽度不比一个字母大小小.
观看此视频 (一开始,第一列是最小的,但是当我调整窗口大小时,它是最宽的列.我只想总是尊重flex设置; flex size 1:3:4:4)
我知道,将字体大小和列填充设置为较小会有所帮助......但还有其他解决方案吗?
我不能用overflow-x: hidden.
.container {
display: flex;
width: 100%
}
.col {
min-height: 200px;
padding: 30px;
word-break: break-word
}
.col1 {
flex: 1;
background: orange;
font-size: 80px
}
.col2 {
flex: 3;
background: yellow
}
.col3 {
flex: 4;
background: skyblue
}
.col4 {
flex: 4;
background: red
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="col col1">Lorem ipsum dolor</div>
<div class="col col2">Lorem ipsum dolor</div>
<div class="col col3">Lorem ipsum dolor</div> …Run Code Online (Sandbox Code Playgroud)自从Firefox Nightly(35.0a1)的最新版本(?)发布以来,我一直遇到text-overflow: ellipsis一个Flexbox容器内部的问题flex-direction: row,每列的宽度为50%.
演示:
.container {
width: 300px;
background: red;
}
.row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.column {
flex-basis: 50%;
}
.column p {
background: gold;
/* Will not work in Firefox Nightly 35.0a1 */
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="row">
<div class="column">
<p>Captain's Log, Stardate 9529.1: This is the final cruise of the starship Enterprise under my command. This ship and her history will shortly …Run Code Online (Sandbox Code Playgroud)我有容器flex.我希望中间孩子占据整个空间,所以我设置它flex: 1.到现在为止还挺好.
下一个级别是中间孩子有2个孩子所以我也想设置它灵活(如果你失去了我,只是跳到片段)和第一个孩子我设置省略号样式.现在,省略号停止工作.
如果你点击按钮,你会发现短文的一切都很好;
有任何想法吗?
function toggle() {
var el = document.querySelector('.el');
el.textContent = el.textContent === 'short' ? 'long long long text' : 'short';
}Run Code Online (Sandbox Code Playgroud)
.wrapper {
display: flex;
width: 200px;
align-content: stretch;
padding: 5px;
min-width: 0;
border: 1px solid
}
.wrapper .child2 {
flex-grow: 1;
}
.flex {
display: flex;
min-width: 0;
}
.el {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.child1 {
background: red;
}
.child2 {
background: blue;
}
.child3 {
background: …Run Code Online (Sandbox Code Playgroud)