我是剛學網頁的。
我參考的網頁是這一個
https://providence-seaside.myshopify.com/
他有分上下兩個nav,但是在響應式的時候,在展開的按鈕中會顯示兩個nav中的按鈕。
我們已是切了兩個div來做上下nav,一個top-bar一個bottom-bar,然後把下面這個都設定一樣,以為data-target的id只要是指定的就會顯示。不過還是沒辦法。
所以想說是不是在不同的div下是沒辦法指定的呢?
如果是這樣,要怎麼做到
data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
原碼如下
<div id="char-section-header" class="char-section">
<div id="top-bar">
<nav class="navbar navbar-expand-lg text-primary navbar-primary bg-dark">
<div class="container">
<span class="navbar-text">
Made by us, enjoyed by you.
</span>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"><i class="fa fa-bars" style="color: #ADBBB2;" aria-hidden="true"></i></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Sign in
<span class="sr-only">(current)</span>
</a>
</li>
<a class="nav-link">/</a>
<li class="nav-item">
<a class="nav-link" href="#">Checkout</a>
</li>
<a class="nav-link">/</a>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa fa-shopping-cart text-primary" aria-hidden="true"></i></a>
</li>
<li class="nav-item">
<div class="">
<a class="box rounded-circle bg-light text-center nav-link" href="#">1</a>
</div>
</li>
</ul>
</div>
</div>
</nav>
</div>
<div id="bottom-bar">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">Seaside</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
以為data-target的id只要是指定的就會顯示?
看範例網站,明顯都是不同的頁面,應該和target無關
主要邏輯使用
css的@media screen配合大小
來做RWD小畫面跟大畫面的隱藏、顯示按鈕效果
效果圖
寬度在640px以上的畫面,上方標題、按鈕1顯示
寬度在640px以下的畫面,上方標題、按鈕1隱藏,下方的標題、按鈕1顯示
HTML:
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
@media screen and (min-width: 640px) {
.hide-for-small {
display: inherit !important;
}
.show-in-small {
display: none !important;
}
}
@media screen and (max-width: 640px) {
.hide-for-small {
display: none !important;
}
.show-in-small {
display: inherit !important;
}
}
</style>
</head>
<body>
<div class="container ">
<div class="row well">
<div class="show-in-small">按鈕在下方</div>
<div class="hide-for-small">IT邦幫忙 你好</div>
<button class="hide-for-small">按鈕1</button>
</div>
<br>
<div class="row well">
<div class="show-in-small">IT邦幫忙 你好</div>
<button class="show-in-small">按鈕1</button>
<button>按鈕2</button>
</div>
</div>
</body>
</html>
你先看一下,有不懂的地方在留言跟我說 :-)