如何截断方向列flexbox子元素内的字符串 [英] How to truncate string inside a direction column flexbox child

查看:113
本文介绍了如何截断方向列flexbox子元素内的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了来自csstricks的文章, https://css-tricks.com/flexbox-truncated-text/

I went over the article from csstricks, https://css-tricks.com/flexbox-truncated-text/

我的问题是当.flex-parent具有flex-direction: column;属性时如何使其工作.

My question how to make it work when the .flex-parent has flex-direction: column; property.

感谢帮助!

推荐答案

这实际上只是重新安排某些属性的问题,但是自然地,此答案取决于项目的需求.

This really is just a matter of rearranging some properties, but naturally this answer depends on the projects needs.

这里的要点是,如果您希望它成为一列,那么当您将.flex-parent中包含的每个顶级元素设置为列方向时,它们自然就会显示出来.因此,它的右边没有任何内容可以截断.

Takeaways here are, if you want it to be a column, by nature every top-level element you include in the .flex-parent, when it's set to column direction, will display as such. Therefore, there will be nothing to the right of it to truncate with.

因此,从本质上讲,如果您希望顶级元素成为一列并截断其中的内容,则完成此操作的一种方法是将它们都包含在同一行"或.flex-child中.然后在该行中,您可以确定对齐和对齐属性.

So essentially, if you want top-level elements to be a column AND truncate content inside of it, then one way of accomplishing it is by including both of them in the same 'row' or .flex-child. Then the row is where you could identify the justify and aligning properties.

.flex-parent {
  display: flex;
  flex-direction: column;
  padding: 10px;
  margin: 30px 0;
}
.flex-child {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.long-and-truncated-with-child-corrected {
  flex: 1;
  min-width: 0; /* or some value */
}
.long-and-truncated-with-child-corrected h2 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.short-and-fixed > div {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: lightgreen;
    display: inline-flex;
}

/*nonessentials*/
body {
  padding: 40px;
}
h2 {
  font-size: 1rem;
  font-weight: normal;
}
.flex-parent {
  background: rgba(0,0,0,0.1);
}

<div class="flex-parent">

  <div class="flex-child long-and-truncated-with-child-corrected">
    <h2>This is a <em>long string</em> that is OK to truncate please and thank you. Some more text to demonstrate, if the string is <b>REALLY</b> truncated</h2>
    <div class="flex-child short-and-fixed">
      <div></div>
      <div></div>
      <div></div>
    </div>
  </div>

</div>

这篇关于如何截断方向列flexbox子元素内的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆