2016-08-18 2 views
0

Я создаю таблицу с использованием flexbox. Он имеет фиксированные заголовки и прокручиваемое тело. В Windows, когда полоса прокрутки добавляется в тело с помощью overflow-y: auto, выравнивание по левому краю разрывается между заголовком и строками. Потому что на окнах панель прокрутки занимает некоторое дополнительное пространство от тела, но заголовок все равно получает одинаковое пространство. Есть ли способ сделать сжатие ширины заголовка, когда панель прокрутки добавляется в тело?Столбец таблицы Flexbox с левой стороны разбит на полосу прокрутки

Я хочу убедиться, что ширина заголовка и тела одинакова, когда имеется полоса прокрутки и даже когда она отсутствует.

&__item, &--header__item { 
 
     position: relative; 
 
     flex-basis: 20%; 
 
     flex-grow: 1; 
 
     overflow: hidden; 
 
     text-overflow: ellipsis; 
 
     &.sm, &.lg { 
 
     flex-grow: 0; 
 
     } 
 
     &.sm { 
 
     flex-basis: 40px; 
 
     } 
 
    }
<!-- Header HTML --> 
 

 
    <ul class="table-list-container"> 
 
     <li class="table-list-row"> 
 
     <ul class="table-list header"> 
 
      <li class="table-list&#45;&#45;header__item sm text-center"> 
 
      </li> 
 
      <li class="table-list&#45;&#45;header__item md-padding-left-10"> 
 
      Header 1 
 
      </li> 
 
      <li class="table-list&#45;&#45;header__item"> 
 
      Header 2 
 
      </li> 
 
      <li class="table-list&#45;&#45;header__item"> 
 
      Header 3 
 
      </li> 
 
      <li class="table-list&#45;&#45;header__item text-center"> 
 
      Header 4 
 
      </li> 
 
     </ul> 
 
     </li> 
 
    </ul> 
 

 
<!-- Body HTML --> 
 

 
    <div style="height: 305px" class="scrollable"> 
 
     <ul class="table-list-container"> 
 
     <li class="table-list-row"> 
 
      <ul class="table-list body"> 
 
      <li class="table-list__item sm text-center"> 
 
       <input type="checkbox"> 
 
      </li> 
 
      <li class="table-list__item md-padding-left-10">Data</li> 
 
      <li class="table-list__item">Data</li> 
 
      <li class="table-list__item">Data</li> 
 
      <li class="table-list__item text-center">Data</li> 
 
      </ul> 
 
     </li> 
 
     </ul> 
 
    </div>

+0

Просьба предоставить минимальный, полный код. –

+0

@SyamPillai Проверьте правильность изменения для кода – jarvis

+0

Не могли бы вы воспроизвести это в кодефене или jsfiddle? – Norbert

ответ

0
overflow-y: overlay; 

ш orked для меня. Поскольку теперь полоса прокрутки будет занимать пространство из существующего табличного пространства, а не дополнительное пространство, заголовки столбцов и строки идеально согласованы.

Осторожно: вам нужно убедиться, что в вашем последнем столбце достаточно места, чтобы показать его содержимое после добавления полосы прокрутки, потому что от этого полосы прокрутки получает свое пространство.

0

Вот рабочая Demo

body{ 
 
\t margin: 0; 
 
} 
 
.table{ 
 
\t display: flex; 
 
\t flex-wrap: wrap; 
 
} 
 
ul{ 
 
\t display: flex; 
 
\t width: 100%; 
 
\t list-style: none; 
 
\t padding: 0; 
 
\t margin: 0; 
 
} 
 
li{ 
 
\t flex: 5; 
 
\t /* width: 15%; */ 
 
\t padding: 10px; 
 
} 
 
.scrollable{ 
 
\t width: 100%; 
 
\t margin-top: 80px; 
 
} 
 
li.empty{ 
 
\t /* max-width: 12px; */ 
 
\t flex:1; 
 
} 
 
.header{ 
 
\t position: fixed; 
 
\t height: 80px; 
 
\t z-index: 5; 
 
\t background: red; 
 
}
<div class="table"> 
 

 
\t <ul class="table-list-container header"> 
 
\t \t <li class="table-list-row"> 
 
\t \t \t <ul class="table-list header"> 
 
\t \t \t \t <li class="table-list&#45;&#45;header__item sm text-center empty"> 
 
\t \t \t \t </li> 
 
\t \t \t \t <li class="table-list&#45;&#45;header__item md-padding-left-10"> 
 
\t \t \t \t \t Header 1 
 
\t \t \t \t </li> 
 
\t \t \t \t <li class="table-list&#45;&#45;header__item"> 
 
\t \t \t \t \t Header 2 
 
\t \t \t \t </li> 
 
\t \t \t \t <li class="table-list&#45;&#45;header__item"> 
 
\t \t \t \t \t Header 3 
 
\t \t \t \t </li> 
 
\t \t \t \t <li class="table-list&#45;&#45;header__item text-center"> 
 
\t \t \t \t \t Header 4 
 
\t \t \t \t </li> 
 
\t \t \t </ul> 
 
\t \t </li> 
 
\t </ul> 
 

 
\t <div style="height: 305px" class="scrollable"> 
 
\t \t <ul class="table-list-container"> 
 
\t \t \t <li class="table-list-row"> 
 
\t \t \t \t <ul class="table-list body"> 
 
\t \t \t \t \t <li class="table-list__item sm text-center empty"> 
 
\t \t \t \t \t \t <input type="checkbox"> 
 
\t \t \t \t \t </li> 
 
\t \t \t \t \t <li class="table-list__item md-padding-left-10">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</li> 
 
\t \t \t \t \t <li class="table-list__item">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</li> 
 
\t \t \t \t \t <li class="table-list__item">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</li> 
 
\t \t \t \t \t <li class="table-list__item text-center">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</li> 
 
\t \t \t \t </ul> 
 
\t \t \t </li> 
 
\t \t </ul> 
 
\t </div> 
 
</div>

+0

Не могли бы вы объяснить, что именно вы изменили и что повлияло на него? – jarvis

+0

Пожалуйста, проверьте css. Я добавил несколько классов в заголовок nav, firsrt empty 'li' в заголовке и т. Д. Так как' css', предоставленный вами, недостаточно для понимания проблемы, я создал свой собственный. Получил 'flex-box' для каждой' ul' и дал равную ширину для всех 'li', за исключением того, что сначала дал« flex: 1 »и« flex: 5' –

Смежные вопросы