css實現父級元素根據子級元素內容自適應寬度


實現效果:

 

 

代碼:

               <ul class="sub">
                                <li>
                                    <a href="">新聞摘要新聞摘要新聞摘要新聞摘要新聞摘要</a>
                                    <a href="">新聞摘要</a>
                                    <a href="">新聞摘要</a>
                                    <a href="">新聞摘要</a>
                                    <a href="">新聞摘要</a>
                                    <a href="">新聞摘要</a>
                                    <a href="">新聞摘要</a>
                                    <a href="">新聞摘要</a>
                                    <a href="">新聞要新聞摘要摘要</a>
                                </li>
                            </ul>

 

 li{ display: block;
              a{
                text-align: center;
                // width: 98px;
                height:35px; 
                line-height:35px;
                color: #333; display: table; white-space: nowrap;
                &:hover {
                  color: #ff0000;
                }
              }
            }

   父級元素:

 display: block;


子集元素:
white-space: nowrap;禁止換行
display: table;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM