Выровнять центр по вертикали и горизонтали в поплавке - PullRequest
0 голосов
/ 16 января 2019

У меня есть код ниже. Я хочу, чтобы второй div, синий, имел такую ​​же ширину, что и красный div, а синий div текст должен быть выровнен по центру как по вертикали, так и по горизонтали.

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

    .red, .blue {
      color: white;
    }

    .red {
    background-color: red;
    }

    .blue {
    background-color: blue;

    }

    .row{ 
      overflow: auto;
     }
     
    .row::after {
      content: "";
      clear: both;
      display: table;
    }

    [class^="col-"] {
        float: left;
    }

    .col-3 {
        width: 30%;
    }


    .col-7 {
        width: 70%;
    }
<div class="row">
      <h1> Example 1</h1> 
      <div class="col-3 red">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.
Why do we use it?
</div>
      <div class="col-7 blue">ipsum ipsum</div>
</div>  
    

Ответы [ 2 ]

0 голосов
/ 16 января 2019

Или как то так?

.red, .blue {
      color: white;
    }

    .red {
    background-color: red;
    }

    .blue {
    background-color: blue;

    }

    .row{ 
      overflow: auto;
     }
     

    [class^="col-"] {
        display:table-cell;
        width: 30%;
    }


    .col-7 {
        text-align:center;
        vertical-align: middle;
    }
    .row::after {
      content: "";
      display: table-cell;
      width: 40%;
    }
<div class="row">
      <h1> Example 1</h1> 
      <div class="col-3 red">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.
Why do we use it?
</div>
      <div class="col-7 blue">ipsum ipsum</div>
</div>
0 голосов
/ 16 января 2019

Вы можете использовать display: table(-cell) вместо числа с плавающей запятой. Совместимость IE8 +. Не забудьте активировать table-layout: fixed, чтобы браузеры учитывали установленную вами ширину и не пытались сделать все возможное с содержимым «ячеек».
Примечание: этот режим отображения CSS имеет мало общего с таблицами HTML, за исключением последних, конечно, по умолчанию используется тот же алгоритм. Это не таблица макета HTML.

Вам необходимо переместить заголовок за пределы «ряда». Вы не можете обернуть, как вы могли бы с Flexbox или плавает.

    .red, .blue {
      color: white;
    }

    .red {
    background-color: red;
    }

    .blue {
    background-color: blue;

    }

    .row{ 
      overflow: auto;
      display: table;
      width: 100%;
      height: 100%;
      table-layout: fixed;
     }
     
    .row::after {
      content: "";
      clear: both;
      display: table;
    }

    [class^="col-"] {
        /*float: left;*/
        display: table-cell;
        height: 100%;
    }

    .col-3 {
        width: 30%;
    }


    .col-7 {
        width: 70%;
    }
<h1> Example 1</h1> 
<div class="row">
      <div class="col-3 red">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.
Why do we use it?
</div>
      <div class="col-7 blue">ipsum ipsum</div>
</div>  
    
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...