<css 十七>导航栏

网页的导航栏就如同一本书的目录。在网页中是必不可少的。

导航栏的实现,可以使用边框+背景色实现,但由于每个块级元素的数字设定,要保证元素之间的距离,横竖的对齐,故非常繁琐,所以使用列表设定可以减少很多麻烦。

导航栏显示可以为横向展开和纵向展开:

横向设定:主要属性-display

<!DOCTYPE html>
<html>
<head>
	<style type="text/css">
		li {
			background-color:#faebd7;
			width:60px;
			height:20px;
			display:inline;
			font-family:微软雅黑;
			color:black;
		}
		li.a {
			margin-left:-7px;
		}
		li.b {
			display:block;
			width:50px;
			height:20px;
			font-family:微软雅黑;
			color:black;
			margin-top:1px;
			border:none;
		}
		li.bb { margin-top:2px;
				border:none;
				width:50px;
		display:block;}
		ul {
			list-style-type:none;
			margin-left:10px;
			padding-left:2px;
		}
		a:link,a:visited { color:black; text-decoration:none; }	
		a:hover {
			background-color:green;
			color:white;
		}
		
	</style>
</head>
<body>
	<ul>
		<li><a href="#">赵子龙</a></li>
		<li class="a"><a href="#">Jobs</a></li>
		<li class="a"><a href="#">@#%^!</a></li>
		<li class="a"><a href="#">BBB</a></li>
		<li class="a"><a href="#">XXX</a></li>
	</ul>
</body>
</html>
 、外边框的可以使用负数进行扩张或缩小,而内边框无法起作用;

、如果需要使每个块的属性不一样,可以单独设定边框、字体、背景;

、某些元素有继承的特性,所以在单独设置一些属性的时候,需要将之前的属性当掉(例如:li的背景色为黑色,在设定li.a的背景色时,可以改成其他颜色,或者直接打none等“没有”的属性);

纵向设定:

		li.b {
			display:block;
			width:50px;
			height:20px;
			font-family:微软雅黑;
			color:black;
			margin-top:1px;
			border:none;
		}
		li.bb { margin-top:2px;
				border:none;
				width:50px;
		display:block;}
		ul {
			list-style-type:none;
			margin-left:10px;
			padding-left:2px;
		}
		ul.AA {
			list-style-type:square;
		}
		a:link,a:visited { color:black; text-decoration:none; }	
		a:hover {
			background-color:green;
			color:white;
		}
		
	</style>
</head>
<body>
	<ul>
		<span style="font-family: Arial, Helvetica, sans-serif;"><li class="bb"><a href="#">大白</a></li></span><pre name="code" class="html">		<li class="b"><a href="#">............</a></li>
		<li class="b"><a href="#">..........</a></li>
		<li class="b"><a href="#">................</a></li>
</ul></body></html>

 

、在设定纵向边框时,可以和横向边框合并在一起,同时需要注意横纵边框之间的距离,以防效果没有变化;

、横纵边框在整体上类似表格,所以如果框内的文字比较多时,会出现边框线错位,所以仍需要再次设定一些属性;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
帮我补充这段代码<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>外卖订餐网站首页</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <header> <div class="logo"> <img src="logo.png" alt="网站Logo"> </div> <nav> <ul> <li><a href="#">首页</a></li> <li><a href="#">菜单</a></li> <li><a href="#">关于我们</a></li> <li><a href="#">联系我们</a></li> </ul> </nav> </header> <div class="banner"> <img src="banner.jpg" alt="轮播图"> </div> <section class="featured-dishes"> <h2>推荐菜品</h2> <ul> <li> <img src="dish1.jpg" alt="菜品图片"> <h3>菜品名称</h3> <p>菜品描述</p> <span class="price">¥50</span> </li> <li> <img src="dish2.jpg" alt="菜品图片"> <h3>菜品名称</h3> <p>菜品描述</p> <span class="price">¥60</span> </li> <li> <img src="dish3.jpg" alt="菜品图片"> <h3>菜品名称</h3> <p>菜品描述</p> <span class="price">¥70</span> </li> </ul> </section> <section class="order-form"> <h2>下单</h2> <form> <label for="name">姓名</label> <input type="text" id="name"> <label for="phone">电话</label> <input type="tel" id="phone"> <label for="address">地址</label> <input type="text" id="address"> <label for="dish">菜品</label> <select id="dish"> <option value="1">菜品1</option> <option value="2">菜品2</option> <option value="3">菜品3</option> </select> <button type="submit">提交订单</button> </form> </section> <footer> <p>©2021 外卖订餐网站. All Rights Reserved.</p> </footer> </body> </html>添加左边导航和广告浮动窗口,请给我html和css的源代码
最新发布
06-02

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值