使用HTML和CSS创建导航菜单

创建结构:在这里,我们将使用 li 标签创建一个普通的结构。这将创建一个简单的界面,你可以通过运行以下代码进行检查:

HTML代码如下:

<!DOCTYPE html> <html> <head>    
 <title>如何使用HTML和CSS创建面导航</title> 
 </head>
  <body>    
  <h1>web前端开发公众号</h1>    
   <b>网址:www.webqdkf.com</b>   
  <ul class="addressLink">       
 <li>            
<a href="#">HOME</a>      
   </li>     
  <li>       
<a href="#">WEB</a>      
   </li>        
  <li>           
   <a href="#">CSS</a>      
  </li>      
       <li>     
      <a href="#">HTML</a>     
    </li>        
 <li>         
 <a href="#">JS</a>     
 </li>       
 <li>       
<a href="#">VUE</a>      
 </li>    
</ul> 
 </body> 
 </html>

设计结构:这是最困难的任务,是在导航的右侧创建箭头形状。为了创建箭头形状,我们将使用:: after选择器。使用z-index属性将一个列表放置在另一列表上。对于CSS开发人员而言,这些事情都是非常容易的。
CSS代码:

   <style> 
        body { 
            text-align: center; 
        } 
        h1{ 
            color: #; 
        } 
          
        /* Styling addressLink class */ 
        .addressLink { 
            list-style: none; 
            overflow: hidden; 
            font: 16px; 
            margin: 30px; 
            padding: 0px; 
            border: 2px solid black; 
            font-style: italic; 
        } 
          
        /* Floating addressLink list */ 
        .addressLink li { 
            float: left; 
        } 
          
        /* Styling addressLink list's anchor element*/ 
        .addressLink li a { 
            background: #19b0cb; 
            color: white; 
            text-decoration: none; 
            padding: 5px 0px 5px 65px; 
            position: relative; 
            float: left; 
        } 
          
        .addressLink li a:after { 
            content: " "; 
            border-top: 50px solid transparent; 
            border-bottom: 50px solid transparent; 
            border-left: 30px solid #19b0cb; 
            margin-top: -50px; 
            position: absolute; 
            top: 50%; 
            left: 100%; 
            z-index: 2; 
        } 
          
        .addressLink li a:before { 
            content: " "; 
            border-top: 50px solid transparent; 
            border-bottom: 50px solid transparent; 
            border-left: 30px solid white; 
            position: absolute; 
            top: 50%; 
            left: 100%; 
            z-index: 1; 
        } 
          
        /* First child padding */ 
        .addressLink li:first-child a { 
            padding-left: 10px; 
        } 
          
        /* Second child bg-color */ 
        .addressLink li:nth-child(2) a { 
            background: #7c7f7f; 
        } 
          
        /* Second child Second half bg-color */ 
        .addressLink li:nth-child(2) a:after { 
            border-left-color: #7c7f7f; 
        } 
          
        /* Third child bg-color */ 
        .addressLink li:nth-child(3) a { 
            background: #b4b4b4; 
        } 
          
        /* Third child Second half bg-color */ 
        .addressLink li:nth-child(3) a:after { 
            border-left-color: #b4b4b4; 
        } 
          
        /* Last child bg-color and text-color */ 
        .addressLink li:last-child a { 
            background: transparent !important; 
            color: #000; 
        } 
          
        .addressLink li:last-child a:after { 
            border: 0px; 
        } 
          
        /* Hover on list's anchor element */ 
        .addressLink li a:hover { 
            background: #7c7f7f; 
        } 
          
        .addressLink li a:hover:after { 
            border-left-color: #7c7f7f !important; 
        } 
</style> 

最后,在本文中,我们将结合HTML和CSS代码来完成,全部代码如下:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>如何使用HTML和CSS创建导航</title> 
    <style> 
        body { 
            text-align: center; 
        } 
        h1{ 
            color: #; 
        } 
          
        /* Styling addressLink class */ 
        .addressLink { 
            list-style: none; 
            overflow: hidden; 
            font: 16px; 
            margin: 30px; 
            padding: 0px; 
            border: 2px solid black; 
            font-style: italic; 
        } 
          
        /* Floating addressLink list */ 
        .addressLink li { 
            float: left; 
        } 
          
        /* Styling addressLink list's anchor element*/ 
        .addressLink li a { 
            background: #19b0cb; 
            color: white; 
            text-decoration: none; 
            padding: 5px 0px 5px 65px; 
            position: relative; 
            float: left; 
        } 
          
        .addressLink li a:after { 
            content: " "; 
            border-top: 50px solid transparent; 
            border-bottom: 50px solid transparent; 
            border-left: 30px solid #19b0cb; 
            margin-top: -50px; 
            position: absolute; 
            top: 50%; 
            left: 100%; 
            z-index: 2; 
        } 
          
        .addressLink li a:before { 
            content: " "; 
            border-top: 50px solid transparent; 
            border-bottom: 50px solid transparent; 
            border-left: 30px solid white; 
            position: absolute; 
            top: 50%; 
            left: 100%; 
            z-index: 1; 
        } 
          
        /* First child padding */ 
        .addressLink li:first-child a { 
            padding-left: 10px; 
        } 
          
        /* Second child bg-color */ 
        .addressLink li:nth-child(2) a { 
            background: #7c7f7f; 
        } 
          
        /* Second child Second half bg-color */ 
        .addressLink li:nth-child(2) a:after { 
            border-left-color: #7c7f7f; 
        } 
          
        /* Third child bg-color */ 
        .addressLink li:nth-child(3) a { 
            background: #b4b4b4; 
        } 
          
        /* Third child Second half bg-color */ 
        .addressLink li:nth-child(3) a:after { 
            border-left-color: #b4b4b4; 
        } 
          
        /* Last child bg-color and text-color */ 
        .addressLink li:last-child a { 
            background: transparent !important; 
            color: #000; 
        } 
          
        .addressLink li:last-child a:after { 
            border: 0px; 
        } 
          
        /* Hover on list's anchor element */ 
        .addressLink li a:hover { 
            background: #7c7f7f; 
        } 
          
        .addressLink li a:hover:after { 
            border-left-color: #7c7f7f !important; 
        } 
</style> 
</head> 
  
<body> 
    <h1>web前端开发公众号</h1> 
    <b>网址:www.webqdkf.com</b> 
    <ul class="addressLink"> 
        <li> 
            <a href="#">HOME</a> 
        </li> 
        <li> 
            <a href="#">WEB</a> 
        </li> 
        <li> 
            <a href="#">CSS</a> 
        </li> 
        <li> 
            <a href="#">HTML</a> 
        </li> 
         <li> 
            <a href="#">JS</a> 
        </li> 
        <li> 
            <a href="#">VUE</a> 
        </li> 
    </ul> 
</body> 
  
</html> 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

X W F

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值