见代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>HTMLiveCode</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <style type="text/css">
            div{
                width:200px;
                height: 200px;
                border:1px red solid;
                display:table;  // 父元素设置为table
            }
            p{
                width:100px;
                height:100px;
                border:1px blue solid;
                word-break:break-word;
                display:table-cell;    // 居中的地方设置为table-cell
                vertical-align:middle;   // 居中
                text-align: center;
            }
        </style>
        <script type="text/javascript">
            
        </script>
    </head>
    <body>
        <div class="a">
            <p>ddddddddddddddddddddddddddssssssssssssssssssssssssssssssssssssssssssssssssssssssd</p>
        </div>
    </body>
</html>

 

结果见图:

小经验:display:table 和 vertical-align:middle 控制 块元素垂直居中

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2021-10-25
  • 2022-02-20
  • 2022-01-28
  • 2021-10-19
  • 2022-12-23
猜你喜欢
  • 2021-09-24
  • 2022-12-23
  • 2021-11-21
  • 2021-09-05
  • 2021-10-05
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案