這篇文章主要介紹bootstrap怎么讓dropdown menu按鈕式下拉框長度一致,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)主要從事網(wǎng)站制作、成都網(wǎng)站制作、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)醴陵,10多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108
bootstrap框架提供了下拉菜單組件(dropdown),即點(diǎn)擊一個元素或按鈕,觸發(fā)隱藏的列表顯示出來。
1、基本代碼和頁面展示
按鈕和菜單需要包裹在.dropdown 的容器里,而作為被點(diǎn)擊的元素按鈕需要設(shè)置
data-toggle="dropdown"
才能有效。對于菜單部分,設(shè)置 class="dropdown-menu"
才能
自動隱藏并添加固定樣式。設(shè)置 class="caret"表示箭頭,可上可下。
<div class="dropdown"> <button class="btn btn-default" data-toggle="dropdown"> 下拉菜單 <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >資訊</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >產(chǎn)品</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >關(guān)于</a></li> </ul> </div>
2、使用進(jìn)階和dropdown-menu長度問題
在解決這個問題之前,先記錄bootstrap的按鈕組功能(btn-group),可以將一組按鈕集成在一個容器里,且相互之前沒有間隔。直接貼代碼和顯示效果。
<span > </span><div class="btn-group"> <button type="button" class="btn btn-default">上一頁</button> <button type="button" class="btn btn-default">下一頁</button> <button type="button" class="btn btn-default">選擇頁數(shù)</button> <div class="btn-group"> <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">下拉框 <i class="caret"></i> </button> <ul class="dropdown-menu" > <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁</a></li> </ul> </div> </div>
代碼解析與總結(jié):
首先嵌套了<div class="btn-group">
容器,用于在按鈕組中使用按鈕式下拉框,
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span >中的dropdown-toggle的作用是讓按鈕式下拉框的也擁有btn-group的圓邊角。</span>
<i class="caret"> </i> <span >三角圖標(biāo),使用<span>也可以。 </span>
data-toggle="dropdown"
是html5的標(biāo)簽屬性,指以什么事件觸發(fā),常用的如:modal,popover,tooltips。這里指該button按鈕用于下拉按鈕。并且親測在html4中使用該屬性,雖然IDE會發(fā)出警告,但是仍然可以實際運(yùn)行,此特性作用于html5的其他新屬性,如input標(biāo)簽的placeholder。
<ul class="dropdown-menu" >
min-width:100%屬性用于將下拉框長度與按鈕長度保持一致,因為bootstrap并沒有設(shè)置這一點(diǎn)。原始效果如下:
以上是“bootstrap怎么讓dropdown menu按鈕式下拉框長度一致”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前名稱:bootstrap怎么讓dropdownmenu按鈕式下拉框長度一致
標(biāo)題URL:http://aaarwkj.com/article24/pdhjce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、定制網(wǎng)站、ChatGPT、網(wǎng)頁設(shè)計公司、網(wǎng)站建設(shè)、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)