div container floats outside of parent container

JohnDizzle

I´m currently trying to create some kind of tab component. It all works fine, if the text inside the label tags is short enough to get displayed inside the content div. If the text is too long, the text gets shortened with ellipsis. But if this happens, the x icon floats out of the parent div.

How to fix this behaviour, so that the x stays in the component div without limiting the labels to a fix size? the reason behind this is, that the icon shcould only appear, if the mouse is hovered over the tab. otherwise the label should reach all the way to the right side. I know how to to this stuff. The only problem currently is the falsy displayed x icon.

.example {
  display: flex;
  flex-direction: column;
}

.component {
  max-width: 250px;
  min-width: 100px;
  width: auto;
  height: 40px;
  background-color: grey;
  cursor: default;
  display: flex;
  flex-direction: row;
}

.line {
    width: 2px;
    min-width: 2px;
    height: 30px;
    background-color: black;
    margin-top: 5px;
}

.content {
    height: 100%;
    width: 100%;
    padding: 7px 10px 7px 5px;
}

.label {
  line-height: 13px;
    font-size: 13px;
    height: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #c4c7cc;
    width: 100%;
}

.icon {
    color: black;
    float: left;
    margin-right: 7px;
    cursor: pointer;
    height: 10px;
    min-width: 10px;
    width: 10px;
}
<div class="example">
  Example with short Text
  <div class="component">
    <div class="line"></div>
    <div class="content">
      <div class=label>aaaaaaaa</div>
      <div class=label>bbbbbbbb</div>
    </div>
    <div class="icon">X</div>
  </div>
  
  <br>
  Example with long Text
  <div class="component">
    <div class="line"></div>
    <div class="content">
      <div class=label>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
      <div class=label>bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbnnnnnnnnnnnnnn</div>
    </div>
    <div class="icon">X</div>
  </div>
</div>

Osama Hussain

Just Need to add overflow: hidden; On the .content class

.example {
  display: flex;
  flex-direction: column;
}

.component {
  max-width: 250px;
  min-width: 100px;
  width: auto;
  height: 40px;
  background-color: grey;
  cursor: default;
  display: flex;
  flex-direction: row;
}

.line {
    width: 2px;
    min-width: 2px;
    height: 30px;
    background-color: black;
    margin-top: 5px;
}

.content {
    height: 100%;
    width: 100%;
    padding: 7px 10px 7px 5px;
    overflow: hidden;
}

.label {
  line-height: 13px;
    font-size: 13px;
    height: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #c4c7cc;
    width: 100%;
}

.icon {
    color: black;
    float: left;
    margin-right: 7px;
    cursor: pointer;
    height: 10px;
    min-width: 10px;
    width: 10px;
}
<div class="example">
  Example with short Text
  <div class="component">
    <div class="line"></div>
    <div class="content">
      <div class=label>aaaaaaaa</div>
      <div class=label>bbbbbbbb</div>
    </div>
    <div class="icon">X</div>
  </div>
  
  <br>
  Example with long Text
  <div class="component">
    <div class="line"></div>
    <div class="content">
      <div class=label>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
      <div class=label>bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbnnnnnnnnnnnnnn</div>
    </div>
    <div class="icon">X</div>
  </div>
</div>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Set a Fixed div to 100% width of the parent container

分類Dev

Set a Fixed div to 100% width of the parent container

分類Dev

The children outside container

分類Dev

container auto hide when clicked outside the container

分類Dev

Restrict container/parent for Sortable

分類Dev

Position div outside of parent

分類Dev

CSS submenu going outside container

分類Dev

YouTube video height ratio, stretch to window width & stretching outside parent container

分類Dev

put element on bottom of parent container

分類Dev

Giving Docker access to db file outside container

分類Dev

Why is my submit button outside its container?

分類Dev

absolute div visibility outside of div relative parent

分類Dev

Expand inner div to fit container

分類Dev

Make container widget fill parent vertically

分類Dev

How to tune/edit/add/change the kafka docker container parameters outside from the container

分類Dev

Bootstrap4 problem : proper column structure inside and outside a container

分類Dev

Bootstrap4 problem : proper column structure inside and outside a container

分類Dev

Place inner Element outside of a "max-width"-Container

分類Dev

wrap range of <li> items within a div container

分類Dev

About Additions On <div class="container-fluid>

分類Dev

Centre a Grid with a DIV container using Bootstrap

分類Dev

When container div shrinks, google map disappears

分類Dev

Make div background 100% in Bootstrap fluid container

分類Dev

CSS:div-containerの下部にdiv-containerを配置します

分類Dev

How can I hide a class of DIV in a container and how another div in the same container? Using jQuery

分類Dev

CSS:div-Containerをdiv-Container内に配置します

分類Dev

How to make two same size UIViews within a parent container programmatically

分類Dev

Make div height the max-height of container div

分類Dev

cssの(div#container)と(#container)の違いは何ですか

Related 関連記事

  1. 1

    Set a Fixed div to 100% width of the parent container

  2. 2

    Set a Fixed div to 100% width of the parent container

  3. 3

    The children outside container

  4. 4

    container auto hide when clicked outside the container

  5. 5

    Restrict container/parent for Sortable

  6. 6

    Position div outside of parent

  7. 7

    CSS submenu going outside container

  8. 8

    YouTube video height ratio, stretch to window width & stretching outside parent container

  9. 9

    put element on bottom of parent container

  10. 10

    Giving Docker access to db file outside container

  11. 11

    Why is my submit button outside its container?

  12. 12

    absolute div visibility outside of div relative parent

  13. 13

    Expand inner div to fit container

  14. 14

    Make container widget fill parent vertically

  15. 15

    How to tune/edit/add/change the kafka docker container parameters outside from the container

  16. 16

    Bootstrap4 problem : proper column structure inside and outside a container

  17. 17

    Bootstrap4 problem : proper column structure inside and outside a container

  18. 18

    Place inner Element outside of a "max-width"-Container

  19. 19

    wrap range of <li> items within a div container

  20. 20

    About Additions On <div class="container-fluid>

  21. 21

    Centre a Grid with a DIV container using Bootstrap

  22. 22

    When container div shrinks, google map disappears

  23. 23

    Make div background 100% in Bootstrap fluid container

  24. 24

    CSS:div-containerの下部にdiv-containerを配置します

  25. 25

    How can I hide a class of DIV in a container and how another div in the same container? Using jQuery

  26. 26

    CSS:div-Containerをdiv-Container内に配置します

  27. 27

    How to make two same size UIViews within a parent container programmatically

  28. 28

    Make div height the max-height of container div

  29. 29

    cssの(div#container)と(#container)の違いは何ですか

ホットタグ

アーカイブ