有趣的css – 简约文字风格导航栏

有趣的css - 简约文字风格导航栏
整体效果演示

利用单选按钮来模拟导航栏点击选中效果,实现一个简约的文字类导航栏。

核心代码部分,简要说明了写法思路;完整代码在最后,可直接复制到本地运行。

导航栏主体结构html代码:

<nav class="nav92">
  <label class="label92">
    <input id="sel91-1" class="inp92" type="radio" name="radio92" checked="" />
    <span class="nav-a92">首页</span>
</label>
<label class="label92">
    <input id="sel91-2" class="inp92" type="radio" name="radio92" />
    <span class="nav-a92">设计</span>
</label>
<label class="label92">
    <input id="sel91-3" class="inp92" type="radio" name="radio92" />
    <span class="nav-a92">前端</span>
</label>
</nav>

css 部分代码:

.nav92{
height: 32px;
padding: 4px;
position: relative;
overflow: hidden;
display: flex;
background-color: #eee;
box-shadow: 010px10px -5pxrgba(0, 0, 0, 0.2);
border-radius: 20px;
}
.label92{
cursor: pointer;
}
.label92.inp92{
display: none;
}
.nav-a92{
width: 88px;
height: 32px;
line-height: 32px;
border-radius: 16px;
display: block;
color: #3d3d3d;
font-size: 14px;
text-decoration: none;
transition: all 0.4s linear;
}
.nav-a92:hover{
font-weight: bold;
}
.inp92:checked + .nav-a92{
font-weight: bold;
background-color: #ffffff;
}

注意 :checked + [classname] 选择器这样写时,是表示选中按钮的下一个同级元素,要注意 html 的元素结构,否则就不起作用。

完整代码如下,html 页面:

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="style.css">
    <title>92 简约文字风格导航栏</title>
</head>
<body>
    <div class="app">
      <nav class="nav92">
        <label class="label92">
          <input id="sel91-1" class="inp92" type="radio" name="radio92" checked="" />
          <span class="nav-a92">首页</span>
        </label>
        <label class="label92">
          <input id="sel91-2" class="inp92" type="radio" name="radio92" />
          <span class="nav-a92">设计</span>
        </label>
        <label class="label92">
          <input id="sel91-3" class="inp92" type="radio" name="radio92" />
          <span class="nav-a92">前端</span>
        </label>
      </nav>
    </div>
</body>
</html>

完整代码如下,css 样式:

/** style.css **/
.app{
width: 100%;
height: 100vh;
background-color: #fff;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.nav92{
height: 32px;
padding: 4px;
position: relative;
overflow: hidden;
display: flex;
background-color: #eee;
box-shadow: 010px10px -5pxrgba(0, 0, 0, 0.2);
border-radius: 20px;
}
.label92{
cursor: pointer;
}
.label92.inp92{
display: none;
}
.nav-a92{
width: 88px;
height: 32px;
line-height: 32px;
border-radius: 16px;
background-color: transparent;
text-align: center;
display: block;
color: #3d3d3d;
font-size: 14px;
text-decoration: none;
transition: all 0.4s linear;
}
.nav-a92:hover{
font-weight: bold;
}
.inp92:checked + .nav-a92{
font-weight: bold;
background-color: #ffffff;
}
有趣的css - 简约文字风格导航栏
页面渲染效果

转载作品,原作者:设计师工作日常,文章来源:https://mp.weixin.qq.com/s/jDhwWVIs9qDgDCOyKm8MGg

(0)
打赏 微信赞赏 微信赞赏 支付宝赞赏 支付宝赞赏
上一篇 2025-01-17 13:14
下一篇 2025-01-23 09:34

相关推荐

  • css修改导航条样式

    近期由于工作需要要修改table表格导航条样式。本人特整理出相关代码,以及最后效果,供各位小伙伴参考。 具体代码如下: .xp-table-content ::-webkit-sc…

    Html/CSS 2022-01-17
    4210
  • 分享几个CSS4操作小技巧,助你代码开挂

    1.::part() 让组件更加灵活 如果你在开发Web组件(Web Components),::part() 让你能直接控制组件的部分元素。它能改变一个封装元素内部的某些样式。 …

    2025-01-17
    1870
  • CSS适配iOS全面屏底部横条

    CSS适配iOS全面屏底部横条,所有开发者应对资源页面做好不同手机型号的适配效果,不影响用户的正常浏览使用。其中IOS全面屏手机底部横线不可遮挡页面的具体功能和内容。

    2023-12-28
    3880
  • 常用的一些CSS代码规则

    常用的一些CSS代码规则:限制视口内的内容宽度、增加正文文本大小、增加文本行之间的间距、限制图片宽度、限制内容中文本的宽度、以更平衡的方式包裹标题、表单控件颜色与页面样式匹配、易于跟随的表格行

    2024-08-08 Html/CSS
    3900
  • 一行 CSS 代码实现响应式布局 – 使用 Grid 实现的响应式布局

    在这篇文章中,我将教你如何使用 CSS Grid(网格) 布局来创建一个超酷的图像网格,它会根据屏幕的宽度改变列的数量,以实现响应式布局。 而这篇文章中最漂亮的部分是:添加一行 C…

    2025-01-23 Html/CSS
    1640
  • CSS如何优雅的实现卡片多行排列布局?

    在前端开发中,我们经常遇见这样的开发需求,实现下列以此排布的卡片,这些卡片宽度一般是固定的。 并且在不同大小的屏幕宽度下自动换行。 实现这样的一个需求其实不难,我们很容易想到设置一…

    2025-01-24 Html/CSS
    1250

发表回复

登录后才能评论
扫码了解
扫码了解
分享本页
返回顶部