CSS之導航欄設計之 ul 之 li 標簽排成一行


在HTML頁面元素設計中,
把具有相同一類功能的列表用 li 標簽。
例如導航欄中的菜單。



一、原始樣式 - display: list-item;




二、改成一行 - display: inline-block;





三、最終效果





四、代碼

<!DOCTYPE html>  
<html>  
<head>  
<style>  
    ul {  
        margin: 0;  
        padding: 0;  
        background-color: #444;  
    }  
    ul li {  
        display: inline-block;  
    }  
    li a {  
        display: block;  
        color: white;  
        text-align: center;  
        padding: 16px;  
        text-decoration: none;  
    }  
    li a:hover {  
        background-color: #888;  
    }  
</style>  
</head>  
<body>  
    <h2>Navigation Menu</h2>  
    <p>In this example, we use CSS to style the list horizontally, to create a navigation menu:</p>  
    <ul>  
        <li><a href="#home">Home</a></li>  
        <li><a href="#news">News</a></li>  
        <li><a href="#contact">Contact</a></li>  
        <li><a href="#about">About</a></li>  
    </ul>  
</body>  
</html>  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-


免責聲明!

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



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