900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 搜索导航HTML CSS 带搜索导航栏的示例代码

搜索导航HTML CSS 带搜索导航栏的示例代码

时间:2019-10-27 19:27:39

相关推荐

搜索导航HTML CSS 带搜索导航栏的示例代码

本文为大家介绍如何使用 CSS 创建一个带搜索的导航栏。

以下实例均是响应式的。

可以先看下效果图:

创建一个搜索栏

主页

关于

联系我们

/* 在顶部导航栏中添加黑色背景颜色 */

.topnav {

overflow: hidden;

background-color: #e9e9e9;

}

/* 设置导航栏的链接样式 */

.topnav a {

float: left;

display: block;

color: black;

text-align: center;

padding: 14px 16px;

text-decoration: none;

font-size: 17px;

}

/* 在悬停时更改链接的颜色 */

.topnav a:hover {

background-color: #ddd;

color: black;

}

/* 突出显示当前选中的元素 */

.topnav a.active {

background-color: #2196F3;

color: white;

}

/* 设置导航栏的搜索框样式 */

.topnav input[type=text] {

float: right;

padding: 6px;

border: none;

margin-top: 8px;

margin-right: 16px;

font-size: 17px;

}

/* 当屏幕宽度小于 600px 时,垂直堆叠显示菜单选项和搜索框 */

@media screen and (max-width: 600px) {

.topnav a, .topnav input[type=text] {

float: none;

display: block;

text-align: left;

width: 100%;

margin: 0;

padding: 14px;

}

.topnav input[type=text] {

border: 1px solid #ccc;

}

}

CSS 带搜索导航栏 - 带提交按钮

菜鸟教程()

* {box-sizing: border-box;}

body {

margin: 0;

font-family: Arial, Helvetica, sans-serif;

}

.topnav {

overflow: hidden;

background-color: #e9e9e9;

}

.topnav a {

float: left;

display: block;

color: black;

text-align: center;

padding: 14px 16px;

text-decoration: none;

font-size: 17px;

}

.topnav a:hover {

background-color: #ddd;

color: black;

}

.topnav a.active {

background-color: #2196F3;

color: white;

}

.topnav .search-container {

float: right;

}

.topnav input[type=text] {

padding: 8px;

margin-top: 8px;

font-size: 17px;

border: none;

}

.topnav .search-container button {

float: right;

padding: 6px;

margin-top: 8px;

margin-right: 16px;

background: #ddd;

font-size: 17px;

border: none;

cursor: pointer;

}

.topnav .search-container button:hover {

background: #ccc;

}

@media screen and (max-width: 600px) {

.topnav .search-container {

float: none;

}

.topnav a, .topnav input[type=text], .topnav .search-container button {

float: none;

display: block;

text-align: left;

width: 100%;

margin: 0;

padding: 14px;

}

.topnav input[type=text] {

border: 1px solid #ccc;

}

}

主页

关于

联系我们

提交

响应式搜索菜单

导航栏里面有一个搜索框。

调整浏览器窗口的大小, 查看效果。

CSS 带搜索导航栏 - 带搜索图标

菜鸟教程()

* {box-sizing: border-box;}

body {

margin: 0;

font-family: Arial, Helvetica, sans-serif;

}

.topnav {

overflow: hidden;

background-color: #e9e9e9;

}

.topnav a {

float: left;

display: block;

color: black;

text-align: center;

padding: 14px 16px;

text-decoration: none;

font-size: 17px;

}

.topnav a:hover {

background-color: #ddd;

color: black;

}

.topnav a.active {

background-color: #2196F3;

color: white;

}

.topnav .search-container {

float: right;

}

.topnav input[type=text] {

padding: 6px;

margin-top: 8px;

font-size: 17px;

border: none;

}

.topnav .search-container button {

float: right;

padding: 6px 10px;

margin-top: 8px;

margin-right: 16px;

background: #ddd;

font-size: 17px;

border: none;

cursor: pointer;

}

.topnav .search-container button:hover {

background: #ccc;

}

@media screen and (max-width: 600px) {

.topnav .search-container {

float: none;

}

.topnav a, .topnav input[type=text], .topnav .search-container button {

float: none;

display: block;

text-align: left;

width: 100%;

margin: 0;

padding: 14px;

}

.topnav input[type=text] {

border: 1px solid #ccc;

}

}

主页

关于

联系我们

响应式搜索菜单

导航栏里面有一个搜索框。

调整浏览器窗口的大小, 查看效果。

到此这篇关于CSS 带搜索导航栏的示例代码的文章就介绍到这了,更多相关CSS 搜索导航栏内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。