[100天挑战100个前端效果]第三天---实现导航条

我们先来看看效果的实现

在这里插入图片描述

html代码

<!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>第三天</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <ul>
        <li><a href="#">首页</a></li>
        <li><a href="#">文章</a></li>
        <li><a href="#">归档</a></li>
        <li><a href="#">收藏</a></li>
    </ul>
</body>
</html>

css代码

*{
    
    
    padding: 0;
    margin: 0;
}
body{
    
    
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100vh;
}
ul{
    
    
    width: 60vw;
    display:flex;
    justify-content: space-between;
    align-items: center;
}
li{
    
    
    list-style: none;
}
a{
    
    
/* 这里是为了将鼠标放在条上的动画显示出来 */
    position: relative;
    color:#fff;
    text-decoration: none;
    padding: 6px 18px;
    /* background-color: rgb(143, 147, 202); */
    transition: background-color 0.8s;
}
a:hover{
    
    
    background-color: #cf5829;
}
a::before{
    
    
    position: absolute;
    content: "";
    width: 18px;
    height: 18px;
    border: 2px solid #e74c3c;
    border-width: 0 0 2px 2px;
    left:0;
    bottom:0;
    opacity: 0;
    transition:  0.2s;
}
a::after{
    
    
    position: absolute;
    content: "";
    width: 18px;
    height: 18px;
    border: 2px solid #e74c3c;  
    border-width: 2px 2px 0 0 ;
    top:0;
    right:0;  
    opacity: 0;
    transition:  0.2s;
}
/* ctrl +alt+上下方向键可以出现多个光标,同时书写多行代码 */
a:hover::before {
    
    
    /* -12是为了把小红角框拉远 格局一下就出来了 */
    left:-12px;
    bottom: -12px;
    opacity: 1;
}
a:hover::after  {
    
    
    top:-12px;
    right: -12px;
    opacity: 1;
}            

新学到的知识总结

标签 作用
border-width 设置四个边框的宽度
space-between 在弹性盒对象的 div 元素中的各项周围留有空白

复习知识

标签 作用
display: flex 弹性布局
opacity 设置元素的不透明级别
transition 产生过渡效果

猜你喜欢

转载自blog.csdn.net/qq_42136832/article/details/115062495