【问题标题】:break the text in new line if it doesnt fit in span [closed]如果文本不适合跨度,则将文本换行[关闭]
【发布时间】:2019-09-30 18:44:49
【问题描述】:

我有一个面板,它分为两部分:左面板和右面板。 在右侧面板中,我有未排序的元素列表,其中确实有元素列表。 每个 li 都有标签,标签有 2 个跨度,一个用于并排的图标文件和文本内容。

当前:当文本长度增加时,整个跨度将移动到新行。跨度不再并排。

我需要实现,span1 和 span2 应该并排,当 span2 中的文本增加时,span 2 应该垂直增长而不是完全移动到新行。

jsfiddle for test application

.left_side_panel{
float: left;
width:50%;
padding-right:1.25rem;
}
.right_side_panel{
float: right;
width:20%;
padding-left:1.25rem;
}
.Panel_Info_Contents{
margin-bottom:3.75rem;
}
.userguide{
list-style: none;
}
.userguide li{
border: 5px solid yellow;
display: block;
min-height: 1.75rem;
margin-bottom:0.625rem;
}
a{
cursor: pointer;
color:#ffff;
text-decoration:none;
}
.guide_icon--file{
border: 2px solid green;
display: inline-block;
vertical-align:middle;
margin-right:0.625rem;
width:1.75rem;
height: 1.75rem;
background-repeat: no-repeat;
}
.guide_entrydetails{
display: inline-block;
vertical-align: middle;
color:red;
border: 2px solid blue;
}
<div class="client">
    <div class="middlePanel__client__overview">
      <div class="left_side_panel">
      </div>
      <div class="right_side_panel">
        <div class="Panel_Info_Contents">
            <ul class="userguide">
                <li>
                    <a title="user guide hand book and some more details to reproduce the issue" href="">
                        <span class="guide_icon--file">
                        </span>
                        <span class="guide_entrydetails">
                            user guide hand book and some more details to reproduce the issue and some more things and some more
                        </span>
                    </a>
                </li>
            </ul>
            <ul>
            </ul>
        </div>
      </div>
    </div>
  </div>

jsfiddle

Expected outcome

【问题讨论】:

    标签: html css responsive-design


    【解决方案1】:

    Flexbox 可以做到这一点:

    .left_side_panel {
      float: left;
      width: 50%;
      padding-right: 1.25rem;
    }
    
    .right_side_panel {
      float:right;
      width: 50%; /* for demo purposes */
      padding-left: 1.25rem;
    }
    
    .Panel_Info_Contents {
      margin-bottom: 3.75rem;
    }
    
    .userguide {
      list-style: none;
    }
    
    .userguide li {
      border: 5px solid yellow;
      display: block;
      min-height: 1.75rem;
      margin-bottom: 0.625rem;
    }
    
    a {
      display: flex; /* this */
      cursor: pointer;
      text-decoration: none;
    }
    
    .guide_icon--file {
      border: 2px solid green;
      display: inline-block;
      vertical-align: middle;
      margin-right: 0.625rem;
      width: 1.75rem;
      height: 1.75rem;
      background-repeat: no-repeat;
    }
    
    .guide_entrydetails {
      display: inline-block;
      vertical-align: middle;
      color: red;
      border: 2px solid blue;
    }
    <div class="client">
      <div class="middlePanel__client__overview">
        <div class="left_side_panel">
        </div>
        <div class="right_side_panel">
          <div class="Panel_Info_Contents">
            <ul class="userguide">
              <li>
                <a title="user guide hand book and some more details to reproduce the issue" href="">
                  <span class="guide_icon--file">I
                            </span>
                  <span class="guide_entrydetails">
                                user guide hand book and some more details to reproduce the issue and some more things and some more
                            </span>
                </a>
              </li>
            </ul>
            <ul>
            </ul>
          </div>
        </div>
      </div>
    </div>

    【讨论】:

    • 现在试一试
    猜你喜欢
    • 2016-10-29
    • 2019-04-26
    • 1970-01-01
    • 2022-10-31
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多