使用浮动定位技术制作简单网页 - 网页设计教程
欢迎来到我的网站
欢迎来到我的网站
这是我的网站的内容
这是我的网站的内容
这是我的网站的内容
导航怎么居中内容:要想让导航居中,可以使用以下方法:
-
将 .navbar 的 overflow 属性改为 auto,这样如果导航超出了容器宽度,就会出现滚动条,不会影响居中效果。
-
给 .navbar 添加 text-align: center;,让导航文字居中。
-
将 .navbar a 的 float 属性去掉,改为 display: inline-block;,这样导航就可以在同一行内居中显示。
修改后的代码如下:
.navbar { background-color: #f2f2f2; height: 50px; padding: 10px; overflow: auto; text-align: center; } .navbar a { display: inline-block; color: #333; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } .navbar a:hover { background-color: #ddd; color: #333; }
原文地址: https://www.cveoy.top/t/topic/oo5V 著作权归作者所有。请勿转载和采集!