CSS 帶搜索導(dǎo)航欄的示例代碼
發(fā)布時(shí)間:2021-02-22 15:39:34 作者:佚名
我要評(píng)論

這篇文章主要介紹了CSS 帶搜索導(dǎo)航欄的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
本文為大家介紹如何使用 CSS 創(chuàng)建一個(gè)帶搜索的導(dǎo)航欄。
以下實(shí)例均是響應(yīng)式的。
可以先看下效果圖:
創(chuàng)建一個(gè)搜索欄
<div class="topnav"> <a class="active" href="#home">主頁(yè)</a> <a href="#about">關(guān)于</a> <a href="#contact">聯(lián)系我們</a> <input type="text" placeholder="搜索.."> </div>
/* 在頂部導(dǎo)航欄中添加黑色背景顏色 */ .topnav { overflow: hidden; background-color: #e9e9e9; } /* 設(shè)置導(dǎo)航欄的鏈接樣式 */ .topnav a { float: left; display: block; color: black; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } /* 在懸停時(shí)更改鏈接的顏色 */ .topnav a:hover { background-color: #ddd; color: black; } /* 突出顯示當(dāng)前選中的元素 */ .topnav a.active { background-color: #2196F3; color: white; } /* 設(shè)置導(dǎo)航欄的搜索框樣式 */ .topnav input[type=text] { float: right; padding: 6px; border: none; margin-top: 8px; margin-right: 16px; font-size: 17px; } /* 當(dāng)屏幕寬度小于 600px 時(shí),垂直堆疊顯示菜單選項(xiàng)和搜索框 */ @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 帶搜索導(dǎo)航欄 - 帶提交按鈕
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鳥(niǎo)教程(runoob.com)</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * {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; } } </style> </head> <body> <div class="topnav"> <a class="active" href="#home">主頁(yè)</a> <a href="#about">關(guān)于</a> <a href="#contact">聯(lián)系我們</a> <div class="search-container"> <form action="/action_page.php"> <input type="text" placeholder="搜索.." name="search"> <button type="submit">提交</button> </form> </div> </div> <div style="padding-left:16px"> <h2>響應(yīng)式搜索菜單</h2> <p>導(dǎo)航欄里面有一個(gè)搜索框。</p> <p>調(diào)整瀏覽器窗口的大小, 查看效果。</p> </div> </body> </html>
CSS 帶搜索導(dǎo)航欄 - 帶搜索圖標(biāo)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鳥(niǎo)教程(runoob.com)</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <style> * {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; } } </style> </head> <body> <div class="topnav"> <a class="active" href="#home">主頁(yè)</a> <a href="#about">關(guān)于</a> <a href="#contact">聯(lián)系我們</a> <div class="search-container"> <form action="/action_page.php"> <input type="text" placeholder="搜索.." name="search"> <button type="submit"><i class="fa fa-search"></i></button> </form> </div> </div> <div style="padding-left:16px"> <h2>響應(yīng)式搜索菜單</h2> <p>導(dǎo)航欄里面有一個(gè)搜索框。</p> <p>調(diào)整瀏覽器窗口的大小, 查看效果。</p> </div> </body> </html>
到此這篇關(guān)于CSS 帶搜索導(dǎo)航欄的示例代碼的文章就介紹到這了,更多相關(guān)CSS 搜索導(dǎo)航欄內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
- 本文主要介紹了css旋轉(zhuǎn)導(dǎo)航的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),該導(dǎo)航可用在一些網(wǎng)站首頁(yè)導(dǎo)航欄中,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-27
CSS+HTML 實(shí)現(xiàn)頂部導(dǎo)航欄功能
這篇文章主要介紹了CSS+HTML 實(shí)現(xiàn)頂部導(dǎo)航欄功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-24教你做個(gè)可愛(ài)的css滑動(dòng)導(dǎo)航條
今天來(lái)帶大家做一個(gè)可愛(ài)的滑動(dòng)導(dǎo)航欄效果,這個(gè)demo很基礎(chǔ),但是使用場(chǎng)景非常廣泛,感興趣的小伙伴們可以參考一下2021-06-15CSS實(shí)現(xiàn)移動(dòng)端橫向滾動(dòng)導(dǎo)航條(PC端也適用)
這篇文章主要介紹了CSS實(shí)現(xiàn)移動(dòng)端橫向滾動(dòng)導(dǎo)航條(PC端也適用),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編2021-03-17- 這篇文章主要介紹了純CSS實(shí)現(xiàn)導(dǎo)航欄下劃線跟隨效果,本文圖文并茂實(shí)例代碼詳解,給大家介紹的非常詳細(xì),需要的朋友參考下吧2019-12-09
css實(shí)現(xiàn)流程導(dǎo)航效果(三種方法)
本文通過(guò)三種方法給大家介紹css實(shí)現(xiàn)流程導(dǎo)航效果,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下2019-11-13html+css 實(shí)現(xiàn)簡(jiǎn)易導(dǎo)航欄功能
這篇文章主要介紹了基于html+css 實(shí)現(xiàn)簡(jiǎn)易導(dǎo)航欄功能,主要就是css(級(jí)聯(lián)樣式表)對(duì)html的內(nèi)容做格式化。具體內(nèi)容詳情大家跟隨小編一起通過(guò)本文學(xué)習(xí)吧2021-04-07css實(shí)現(xiàn)導(dǎo)航切換的實(shí)例代碼
本文通過(guò)實(shí)例代碼給大家介紹了css實(shí)現(xiàn)導(dǎo)航切換效果,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2018-08-15css實(shí)現(xiàn)電梯導(dǎo)航的項(xiàng)目實(shí)踐
CSS梯形導(dǎo)航圖是一種使用 CSS 布局實(shí)現(xiàn)的導(dǎo)航設(shè)計(jì),可以根據(jù)需要靈活調(diào)整導(dǎo)航菜單的上下位置和大小,本文主要介紹了css實(shí)現(xiàn)電梯導(dǎo)航,具有一定的參考價(jià)值,感興趣的可以了解2023-05-06