域名預(yù)訂/競(jìng)價(jià),好“米”不錯(cuò)過(guò)
這篇文章主要介紹了AmazeUI中各種的導(dǎo)航式菜單與解決方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
與Bootstrap一樣,AmazeUI提供的導(dǎo)航式菜單也是喜歡蜷縮在右上角的一個(gè)按鈕里面,然后一點(diǎn)擊就向下拉開一大段距離。這樣很不友好。此前《【AmazeUI】手機(jī)版頁(yè)面的頂部導(dǎo)航條Header與側(cè)邊導(dǎo)航欄offCanvas》(點(diǎn)擊打開鏈接)是一種解決方案,但是對(duì)于一些不使用頁(yè)面的頁(yè)面,這種方案則無(wú)能無(wú)力。
對(duì)于此有如下的幾種方案可以解決:
一、改造AmazeUI提供的手機(jī)端文字橫排菜單
AmazeUI提供的手機(jī)端文字橫排菜單的背景顏色是白色的,字體是藍(lán)色的,沒(méi)有提供相應(yīng)的class去改寫里面的字體,
我們可以為背景與文字添加一個(gè)css,改寫其背景與文字顏色
效果如下:
代碼如下:
<h1>導(dǎo)航菜單-橫排文字式</h1>
<style>
/*這里是改寫文字的顏色*/
.am-menu-default .am-menu-nav a {
color:#222;
}
/*這里是改寫背景的顏色*/
.am-menu-nav{
background:#f1f1f1;
}
</style>
<div data-am-widget="menu" class="am-menu am-menu-default" >
<a href="javascript: void(0)" class="am-menu-toggle a-in-menu"><i class="am-menu-toggle-icon am-icon-bars"></i></a>
<!--表示每一個(gè)菜單都占3格,也就是在12格1行的布局中占據(jù)4格的位置-->
<ul class="am-menu-nav am-avg-sm-3">
<!--表示這個(gè)項(xiàng)目帶下拉菜單-->
<li class="am-parent">
<a href="#">項(xiàng)目1</a>
<ul class="am-menu-sub am-collapse am-avg-sm-4">
<li><a href="#">項(xiàng)目1-1</a></li>
<li><a href="#">項(xiàng)目1-2</a></li>
<li><a href="#">項(xiàng)目1-3</a></li>
<li><a href="#">項(xiàng)目1-4</a></li>
<li><a href="#">項(xiàng)目1-5</a></li>
<li><a href="#">項(xiàng)目1-6</a></li>
</ul>
</li>
<li><a href="#">項(xiàng)目2</a></li>
<li><a href="#">項(xiàng)目3</a></li>
<li><a href="#">項(xiàng)目4</a></li>
<li class="am-parent">
<a href="#">項(xiàng)目5</a>
<ul class="am-menu-sub am-collapse am-avg-sm-4">
<li><a href="#">項(xiàng)目5-1</a></li>
<li><a href="#">項(xiàng)目5-2</a></li>
<li><a href="#">項(xiàng)目5-3</a></li>
<li><a href="#">項(xiàng)目5-4</a></li>
<li><a href="#">項(xiàng)目5-5</a></li>
<li><a href="#">項(xiàng)目5-6</a></li>
</ul>
</li>
</ul>
</div>
二、利用按鈕組與下拉按鈕
這里運(yùn)用了解決Bootstrap導(dǎo)航欄的思想,《【Bootstrap】導(dǎo)航欄navbar在IE8上的缺陷與解決方案》(點(diǎn)擊打開鏈接),但是AmazeUI的按鈕組與下拉按鈕的復(fù)合相當(dāng)不給力。沒(méi)有提供下拉按鈕與按鈕復(fù)合的按鈕組。同時(shí),其柵格化布局也無(wú)法約束其下拉按鈕的大小,因此,必須自己整幾個(gè)div,調(diào)節(jié)其width與margin屬性,規(guī)范其大小。
效果如下:
代碼如下:
<h1>導(dǎo)航菜單-下拉列表式</h1>
<style>
/*讓每一個(gè)下拉按鈕占據(jù)的寬度與居中*/
.am-dropdown{
width:30%;
text-align:center;
}
</style>
<!--這里表示一行-->
<div style="text-align:center; width:100%; margin-left:-1.5%">
<div class="am-dropdown" data-am-dropdown>
<button class="am-btn am-btn-primary am-dropdown-toggle" data-am-dropdown-toggle style="width:110%;" >項(xiàng)目1<span class="am-icon-caret-down"></span></button>
<ul class="am-dropdown-content">
<li><a href="#">項(xiàng)目1-1</a></li>
<li><a href="#">項(xiàng)目1-2</a></li>
<li class="am-divider"></li>
<li><a href="#">項(xiàng)目1-3</a></li>
</ul>
</div>
<div class="am-dropdown" data-am-dropdown >
<button type="button" class="am-btn am-btn-primary" style="width:110%;" onClick="javascript:window.location.href='#'">項(xiàng)目2</button>
</div>
<div class="am-dropdown" data-am-dropdown>
<button class="am-btn am-btn-primary am-dropdown-toggle" data-am-dropdown-toggle style="width:110%;" >項(xiàng)目3<span class="am-icon-caret-down"></span></button>
<ul class="am-dropdown-content">
<li><a href="#">項(xiàng)目3-1</a></li>
<li class="am-divider"></li>
<li><a href="#">項(xiàng)目3-2</a></li>
<li><a href="#">項(xiàng)目3-3</a></li>
<li><a href="#">項(xiàng)目3-4</a></li>
</ul>
</div>
</div>
<!--搞完一行,必須自己再開一行-->
<div style="text-align:center; width:100%; margin-left:-1.5%">
<div class="am-dropdown" data-am-dropdown>
<button type="button" class="am-btn am-btn-primary" style="width:110%;" onClick="javascript:window.location.href='#'">項(xiàng)目4</button>
</div>
<div class="am-dropdown" data-am-dropdown >
<button class="am-btn am-btn-primary am-dropdown-toggle" data-am-dropdown-toggle style="width:110%;" >項(xiàng)目5<span class="am-icon-caret-down"></span></button>
<ul class="am-dropdown-content">
<li><a href="#">項(xiàng)目5-1</a></li>
<li><a href="#">項(xiàng)目5-2</a></li>
<li class="am-divider"></li>
<li><a href="#">項(xiàng)目5-3</a></li>
<li><a href="#">項(xiàng)目5-4</a></li>
</ul>
</div>
<div class="am-dropdown" data-am-dropdown>
<button type="button" class="am-btn am-btn-primary" style="width:110%;" onClick="javascript:window.location.href='#'">項(xiàng)目6</button>
</div>
</div>
這里,每一行最好放置3個(gè)組件就好,設(shè)置css為text-align:center,還要補(bǔ)上一個(gè)margin-left:-1.5%才剛好其居中,width:100%占據(jù)一行。
其下的各個(gè)div占據(jù)30%的寬度。接著的各個(gè)按鈕、下拉按鈕其寬度必須是110%,這樣才能剛剛配合好原來(lái)的樣式,把按鈕與下拉按鈕符合起來(lái)。
其中,里面的li class="am-divider"意為分割線。
三、利用無(wú)下拉項(xiàng)目的標(biāo)簽頁(yè)
其實(shí)手機(jī)里面的導(dǎo)航真的無(wú)須使用下拉項(xiàng)目。下拉菜單在手機(jī)屏幕上是很難點(diǎn)的。直接利用標(biāo)簽頁(yè)設(shè)置一個(gè)導(dǎo)航。代碼也短,用戶也不會(huì)不滿意。關(guān)鍵是AmazeUI本來(lái)就提供這種布局。然后,你再于這個(gè)頁(yè)面里面布置二級(jí)導(dǎo)航也可以。
效果如下:
代碼如下:
<h1>導(dǎo)航菜單-標(biāo)簽頁(yè)布局</h1>
<div data-am-widget="tabs" class="am-tabs am-tabs-d2">
<ul class="am-tabs-nav">
<li class="am-active"><a href="#">項(xiàng)目1</a></li>
<li><a href="#">項(xiàng)目2</a></li>
<li><a href="#">項(xiàng)目3</a></li>
<li><a href="#">項(xiàng)目4</a></li>
</ul>
<ul class="am-tabs-nav">
<li><a href="#">項(xiàng)目5</a></li>
<li><a href="#">項(xiàng)目6</a></li>
<li><a href="#">項(xiàng)目7</a></li>
</ul>
</div>
同時(shí),AmazeUI也提供另一種風(fēng)格的標(biāo)簽頁(yè)布局,效果如下:
代碼如下:
<h1>導(dǎo)航菜單-標(biāo)簽頁(yè)極簡(jiǎn)布局</h1>
<div data-am-widget="tabs" class="am-tabs am-tabs-default">
<ul class="am-tabs-nav">
<li><a href="#">項(xiàng)目1</a></li>
<li><a href="#">項(xiàng)目2</a></li>
<li class="am-active"><a href="#">項(xiàng)目3</a></li>
</ul>
<ul class="am-tabs-nav">
<li><a href="#">項(xiàng)目4</a></li>
<li><a href="#">項(xiàng)目5</a></li>
<li><a href="#">項(xiàng)目6</a></li>
</ul>
</div>
最后貼一下整個(gè)頁(yè)面的效果圖與代碼:
<!--使用HTML5開發(fā)-->
<!doctype html>
<html class="no-js">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--自動(dòng)適應(yīng)移動(dòng)屏幕-->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!--優(yōu)先使用webkit內(nèi)核渲染-->
<meta name="renderer" content="webkit">
<!--不要被百度轉(zhuǎn)碼-->
<meta http-equiv="Cache-Control" content="no-siteapp"/>
<!--以下才是引入amazeui資源-->
<link rel="stylesheet" href="assets/css/amazeui.min.css">
<link rel="stylesheet" href="assets/css/app.css">
<!--引入js的時(shí)候要注意,必須先引入jQuery,再引入amazeui,因?yàn)檫@個(gè)框架是基于jQuery開發(fā)的-->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<title>導(dǎo)航菜單</title>
</head>
<body>
<h1>導(dǎo)航菜單-橫排文字式</h1>
<style>
/*這里是改寫文字的顏色*/
.am-menu-default .am-menu-nav a {
color:#222;
}
/*這里是改寫背景的顏色*/
.am-menu-nav{
background:#f1f1f1;
}
</style>
<div data-am-widget="menu" class="am-menu am-menu-default" >
<a href="javascript: void(0)" class="am-menu-toggle a-in-menu"><i class="am-menu-toggle-icon am-icon-bars"></i></a>
<!--表示每一個(gè)菜單都占3格,也就是在12格1行的布局中占據(jù)4格的位置-->
<ul class="am-menu-nav am-avg-sm-3">
<!--表示這個(gè)項(xiàng)目帶下拉菜單-->
<li class="am-parent">
<a href="#">項(xiàng)目1</a>
<ul class="am-menu-sub am-collapse am-avg-sm-4">
<li><a href="#">項(xiàng)目1-1</a></li>
<li><a href="#">項(xiàng)目1-2</a></li>
<li><a href="#">項(xiàng)目1-3</a></li>
<li><a href="#">項(xiàng)目1-4</a></li>
<li><a href="#">項(xiàng)目1-5</a></li>
<li><a href="#">項(xiàng)目1-6</a></li>
</ul>
</li>
<li><a href="#">項(xiàng)目2</a></li>
<li><a href="#">項(xiàng)目3</a></li>
<li><a href="#">項(xiàng)目4</a></li>
<li class="am-parent">
<a href="#">項(xiàng)目5</a>
<ul class="am-menu-sub am-collapse am-avg-sm-4">
<li><a href="#">項(xiàng)目5-1</a></li>
<li><a href="#">項(xiàng)目5-2</a></li>
<li><a href="#">項(xiàng)目5-3</a></li>
<li><a href="#">項(xiàng)目5-4</a></li>
<li><a href="#">項(xiàng)目5-5</a></li>
<li><a href="#">項(xiàng)目5-6</a></li>
</ul>
</li>
</ul>
</div>
<h1>導(dǎo)航菜單-下拉列表式</h1>
<style>
/*讓每一個(gè)下拉按鈕占據(jù)的寬度與居中*/
.am-dropdown{
width:30%;
text-align:center;
}
</style>
<!--這里表示一行-->
<div style="text-align:center; width:100%; margin-left:-1.5%">
<div class="am-dropdown" data-am-dropdown>
<button class="am-btn am-btn-primary am-dropdown-toggle" data-am-dropdown-toggle style="width:110%;" >項(xiàng)目1<span class="am-icon-caret-down"></span></button>
<ul class="am-dropdown-content">
<li><a href="#">項(xiàng)目1-1</a></li>
<li><a href="#">項(xiàng)目1-2</a></li>
<li class="am-divider"></li>
<li><a href="#">項(xiàng)目1-3</a></li>
</ul>
</div>
<div class="am-dropdown" data-am-dropdown >
<button type="button" class="am-btn am-btn-primary" style="width:110%;" onClick="javascript:window.location.href='#'">項(xiàng)目2</button>
</div>
<div class="am-dropdown" data-am-dropdown>
<button class="am-btn am-btn-primary am-dropdown-toggle" data-am-dropdown-toggle style="width:110%;" >項(xiàng)目3<span class="am-icon-caret-down"></span></button>
<ul class="am-dropdown-content">
<li><a href="#">項(xiàng)目3-1</a></li>
<li class="am-divider"></li>
<li><a href="#">項(xiàng)目3-2</a></li>
<li><a href="#">項(xiàng)目3-3</a></li>
<li><a href="#">項(xiàng)目3-4</a></li>
</ul>
</div>
</div>
<!--搞完一行,必須自己再開一行-->
<div style="text-align:center; width:100%; margin-left:-1.5%">
<div class="am-dropdown" data-am-dropdown>
<button type="button" class="am-btn am-btn-primary" style="width:110%;" onClick="javascript:window.location.href='#'">項(xiàng)目4</button>
</div>
<div class="am-dropdown" data-am-dropdown >
<button class="am-btn am-btn-primary am-dropdown-toggle" data-am-dropdown-toggle style="width:110%;" >項(xiàng)目5<span class="am-icon-caret-down"></span></button>
<ul class="am-dropdown-content">
<li><a href="#">項(xiàng)目5-1</a></li>
<li><a href="#">項(xiàng)目5-2</a></li>
<li class="am-divider"></li>
<li><a href="#">項(xiàng)目5-3</a></li>
<li><a href="#">項(xiàng)目5-4</a></li>
</ul>
</div>
<div class="am-dropdown" data-am-dropdown>
<button type="button" class="am-btn am-btn-primary" style="width:110%;" onClick="javascript:window.location.href='#'">項(xiàng)目6</button>
</div>
</div>
<h1>導(dǎo)航菜單-標(biāo)簽頁(yè)布局</h1>
<div data-am-widget="tabs" class="am-tabs am-tabs-d2">
<ul class="am-tabs-nav">
<li class="am-active"><a href="#">項(xiàng)目1</a></li>
<li><a href="#">項(xiàng)目2</a></li>
<li><a href="#">項(xiàng)目3</a></li>
<li><a href="#">項(xiàng)目4</a></li>
</ul>
<ul class="am-tabs-nav">
<li><a href="#">項(xiàng)目5</a></li>
<li><a href="#">項(xiàng)目6</a></li>
<li><a href="#">項(xiàng)目7</a></li>
</ul>
</div>
<h1>導(dǎo)航菜單-標(biāo)簽頁(yè)極簡(jiǎn)布局</h1>
<div data-am-widget="tabs" class="am-tabs am-tabs-default">
<ul class="am-tabs-nav">
<li><a href="#">項(xiàng)目1</a></li>
<li><a href="#">項(xiàng)目2</a></li>
<li class="am-active"><a href="#">項(xiàng)目3</a></li>
</ul>
<ul class="am-tabs-nav">
<li><a href="#">項(xiàng)目4</a></li>
<li><a href="#">項(xiàng)目5</a></li>
<li><a href="#">項(xiàng)目6</a></li>
</ul>
</div>
</body>
</html>
到此這篇關(guān)于AmazeUI中各種的導(dǎo)航式菜單與解決方法的文章就介紹到這了,更多相關(guān)AmazeUI導(dǎo)航式菜單內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
來(lái)源:腳本之家
鏈接:https://www.jb51.net/html5/741348.html
申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!