The method of flex layout text centering, text overflow and automatic line wrapping

directly on the code

display:flex;
flex:1;
align-items: center;
justify-content: center;
overflow:hidden;
word-wrap:break-word;
word-break:break-all;
border-right:1px solid #323232;
font-size:12px;

insert image description here

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="box">
      <div class="itemOne">
        <div class="itemOne1">
          动态内容XXXXX居中 50%动态内容XXXXX居中
          50%动态内容XXXXX居中50%0%动态内容XXXXX居中50% 0%动态内容XXXXX居中50%
          0%动态内容XXXXX居中50%
          0%动态内容XXXXX居中50%0%动态内容XXXXX居中50%0%动态内容XXXXX居中50%
        </div>
      </div>
      <div class="itemTwo">
        <div class="itemTwo1">头部33333333333333333333333333333</div>
        <div class="itemTwo3"></div>
        <div class="itemTwo1">底部</div>
      </div>
    </div>
    <script></script>
  </body>
</html>
<style>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  .box {
    width: 100%;
    height: 400px;
    background-color: plum;
    display: flex;
  }
  .itemOne {
    width: 75%;
    height: 100%;
    background-color: red;
    display: flex;
    justify-content: center;
  }
  .itemOne1 {
    width: 100%;
    height: 100%;
    background-color: rgb(192, 236, 255);
    margin-left: 33%;
    flex: 1;
    overflow: hidden;
    word-wrap: break-word;
    word-break: break-all;
    border-right: 1px solid #323232;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .itemTwo {
    width: 25%;
    height: 100%;
    background-color: green;
    display: flex;
    flex-direction: column;
    align-content: space-between;
    margin-left: 10px;
  }
  .itemTwo1 {
    width: 50%;
    height: 33%;
    background-color: yellow;
    flex: 1;
    overflow: hidden;
    word-wrap: break-word;
    word-break: break-all;
    border-right: 1px solid #323232;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .itemTwo3 {
    width: 50%;
    height: 33%;
  }
</style>

Guess you like

Origin blog.csdn.net/lzfengquan/article/details/127882652