Front-end note recording---simple navigation bar (floating)

Statement: The following content is a summary of personal study, the original intention is to facilitate their own study and review records. If there are any errors, please correct me!

Achieve effect

Before
Insert picture description here
clicking: After clicking:
Insert picture description here

Implementation code

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		/*清除页面上的默认样式*/
		* {
     
     
			margin: 0;
			padding: 0;
        }

        /*清除页面上li元素的默认样式:即去掉小黑点*/
        li {
     
      
        	list-style: none;

        }
        a {
     
     
            text-decoration: none;
        }

        .one {
     
     
        	width: 1202px;
        	height: 142px;
        	/*tips:当一个div里放图片时,最好一定要设置高度,不要指望图片的自然高度撑开div,因为会差4px*/
        	margin: 0 auto;
        	/*先设置盒子宽度,然后margin设置左右auto,使盒子居中显示在页面*/
        }
        .two {
     
     
        	margin: 0 auto;
        	width: 1202px;
        	background-color: #fe8a63;
        	height: 40px;
        }
        .two li {
     
     
            float: left;
            margin-right: 1px;
        }
        .two li a{
     
     
        	display: inline-block;
        	width: 150px;
        	height: 40px;
        	line-height: 40px;
        	text-align: center;
        	background-color: #ffaa71;
        	color: black;
        }
        .two li a:hover {
     
     
        	color: white;
        	background-color: #543243;
        }
	</style>
	
</head>
<body>
	
		<div class="one">
		   <img src="imgs/view.jpg" alt="">
	    </div>
		<div class="two">
			<li><a href="#">首页</a></li>
			<li><a href="#">前端</a></li>
			<li><a href="#">后端</a></li>
			<li><a href="#">工具使用</a></li>
			<li><a href="#">关于我</a></li>
		</div>
</body>
</html>

Guess you like

Origin blog.csdn.net/pilgrim_121/article/details/111088730