Как исправить перенос текста, не нарушая выравнивание CSS? - PullRequest
0 голосов
/ 13 июня 2018

У меня ниже html и css для отображения некоторых данных согласно скриншоту.Если я добавлю white-space: nowrap;, тогда текст выйдет из поля (первый снимок экрана).Если я не использую его, он переносит, но нарушает выравнивание блока (2-я строка на скриншоте).

Любое свойство, которое я могу установить, чтобы исправить это, не увеличивая ширину блока?Я также пробовал отображать свойства, но пока не повезло.

<html>      
  <head>
    <meta charset="UTF-8"/>
 <style>
.sideBarList li {
  width: 12%;
  height: 50px;
  text-align: center;
  line-height: -10px;
  border-radius: 10px;
  background: skyblue;
  margin: 0 10px;
          white-space: nowrap;
  display: inline-block;
  color: black;
  position: relative; 
  text-align: center;
  font-family: Arial;
  font-size: 11px;
}

.sideBarList li::before{
  content: '';
  position: absolute;
  top: 25px;
  left: -8em;
  width: 8em;
  height: .2em;
  background: skyblue;
  z-index: -1;
}

   </style>

   </head>
  <body>

  <ul class="sideBarList">
        <li class="li">Hi There</li>  
        <li class="li">Hi There</li> 
        <li class="li"> ABC DEF GHI TYTYT YTYYT IIIOO</li> 
 </ul>
  </body>
</html>

Ответы [ 4 ]

0 голосов
/ 13 июня 2018

Используйте этот стиль

ul {
   display: flex;
}

 
.sideBarList li {
  width: 12%;
  height: 50px;
  text-align: center;
  line-height: -10px;
  border-radius: 10px;
  background: skyblue;
  margin: 0 10px;
  white-space: normal;
  display: inline-block;
  color: black;
  position: relative; 
  text-align: center;
  font-family: Arial;
  font-size: 11px;
}

.sideBarList li::before{
  content: '';
  position: absolute;
  top: 25px;
  left: -8em;
  width: 8em;
  height: .2em;
  background: skyblue;
  z-index: -1;
}
ul {
   display: flex;
}
<ul class="sideBarList">
  <li class="li">Hi There</li>
  <li class="li">Hi There</li>
  <li class="li"> ABC DEF GHI TYTYT YTYYT IIIOO</li>
</ul>
0 голосов
/ 13 июня 2018

только обновите свой .sideBarList li до этого

.sideBarList li {
   width: 12%;
  height: 50px;
  text-align: center;
  line-height: -10px;
  border-radius: 10px;
  background: skyblue;
  margin: 0 10px;
  display: inline-block;
  vertical-align: top;
  color: black;
  position: relative;
  text-align: center;
  font-family: Arial;
  font-size: 11px;
}
0 голосов
/ 13 июня 2018

display:inline-flex тоже работает.Пожалуйста, проверьте.

.sideBarList li {
    width: 12%;
    height: 50px;
    text-align: center;
    line-height: -10px;
    border-radius: 10px;
    background: skyblue;
    margin: 0 10px;
    display: -webkit-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    vertical-align:top;
    color: black;
    position: relative;
    text-align: center;
    font-family: Arial;
    font-size: 11px;
}

.sideBarList li::before {
    content: '';
    position: absolute;
    top: 25px;
    left: -8em;
    width: 8em;
    height: .2em;
    background: skyblue;
    z-index: -1;
}
<ul class="sideBarList">
  <li class="li">Hi There</li>
  <li class="li">Hi There</li>
  <li class="li"> ABC DEF GHI TYTYT YTYYT IIIOO</li>
</ul>
0 голосов
/ 13 июня 2018

Вы используете inline-block, вам нужно использовать vertical-align:top для поддержания выравнивания, так как выравнивание по умолчанию равно baseline.

.sideBarList li {
  width: 12%;
  height: 50px;
  text-align: center;
  line-height: -10px;
  border-radius: 10px;
  background: skyblue;
  margin: 0 10px;
  display: inline-block;
  vertical-align: top;
  color: black;
  position: relative;
  text-align: center;
  font-family: Arial;
  font-size: 11px;
}

.sideBarList li::before {
  content: '';
  position: absolute;
  top: 25px;
  left: -8em;
  width: 8em;
  height: .2em;
  background: skyblue;
  z-index: -1;
}
<ul class="sideBarList">
  <li class="li">Hi There</li>
  <li class="li">Hi There</li>
  <li class="li"> ABC DEF GHI TYTYT YTYYT IIIOO</li>
</ul>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...