Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

html导航栏横向排列

作者:狂拽今生   发布日期:2026-01-07   浏览:41

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Horizontal Navigation Bar</title>
    <style>
        /* 设置导航栏的样式 */
        .navbar {
            overflow: hidden;
            background-color: #333;
        }

        /* 导航栏中的每个链接 */
        .navbar a {
            float: left;
            display: block;
            color: white;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }

        /* 鼠标悬停时的样式 */
        .navbar a:hover {
            background-color: #ddd;
            color: black;
        }
    </style>
</head>
<body>

    <!-- 导航栏 -->
    <div class="navbar">
        <a href="#home">Home</a>
        <a href="#about">About</a>
        <a href="#services">Services</a>
        <a href="#contact">Contact</a>
    </div>

</body>
</html>

解释说明:

  1. HTML 结构:

    • 使用 <div> 标签创建一个包含导航链接的容器,并为其添加 navbar 类。
    • 每个导航链接使用 <a> 标签表示,并设置相应的 href 属性指向不同的页面或锚点。
  2. CSS 样式:

    • .navbar 类用于设置导航栏的背景颜色和溢出处理,确保内容不会超出容器。
    • .navbar a 类用于设置导航链接的样式,包括浮动到左侧 (float: left)、块级显示 (display: block)、文本对齐方式 (text-align: center)、内边距 (padding) 和文本颜色 (color)。
    • .navbar a:hover 类用于定义鼠标悬停时的样式变化,如背景颜色和文本颜色的变化。

上一篇:html文字颜色

下一篇:html转义字符表

大家都在看

静态html源码

404 html

ios打开html

nginx访问不到html

html 符号

colspan在html中是什么意思

怎么将网页另存为html

xml转html

html时间代码

html localstorage

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站