英文:
What needs to be done to make the Bootstrap 5.3.0 Collapsible button show in this simple web page?
问题
我试图创建一个简单的网页,使用Bootstrap(版本5.3.0)的可折叠组件,但无论我尝试什么都无法使其工作。
我只想要一个可折叠组件,其中包含一些链接,当您单击它时会显示这些链接。
但是,即使我将问题简化为仅显示字符串列表(如下所示的代码),问题仍然存在。
问题是可折叠按钮无论我尝试什么都不显示。
<span class="navbar-toggler-icon"></span>
不可见。我在其两侧添加了'X',只是为了指示不可见的按钮在哪里。
有人知道如何修复这个问题,使可折叠按钮可见吗?
谢谢。
以下是代码:
<!-- language: lang-html -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<header class="bg-primary text-white text-center py-3">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="left-header">
<h3>Left Header</h3>
</div>
</div>
<div class="col-md-4">
<div class="central-header">
<h3>Central Header</h3>
</div>
</div>
<div class="col-md-4">
<div class="right-header">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNav">
X<span class="navbar-toggler-icon"></span>X
</button>
</div>
<div class="collapse" id="collapsibleNav">
<div class="card card-body">
<ul class="nav">
<li class="nav-item">Item 1</li>
<li class="nav-item">Item 2</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</header>
<main class="container mt-4">
<h2>Main Content</h2>
<p>This is the main content of the page.</p>
</main>
希望这能帮助您解决可折叠按钮不可见的问题。
英文:
I've tried to create a simple web page that uses the Bootstrap (version 5.3.0) Collapsible and I cannot get it to work no matter what I try.
All I want is a Collapsible that 'holds' a few links in it which are shown when you click it.
But when that didn't work I simplified it to just a list of strings (code shown below) but the problem is still there.
The problem is that the Collapsible button does not show no matter what I try.
The <span class="navbar-toggler-icon"></span>
is not visible. I've added 'X' to both sides
of it just so there is an indication where that invisible button is.
Anyone knows how to fix that, make the Collapsible button visible?
Thanks.
Here's the code:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<header class="bg-primary text-white text-center py-3">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="left-header">
<h3>Left Header</h3>
</div>
</div>
<div class="col-md-4">
<div class="central-header">
<h3>Central Header</h3>
</div>
</div>
<div class="col-md-4">
<div class="right-header">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNav">
X<span class="navbar-toggler-icon"></span>X
</button>
</div>
<div class="collapse" id="collapsibleNav">
<div class="card card-body">
<ul class="nav">
<li class="nav-item">Item 1</li>
<li class="nav-item">Item 2</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</header>
<main class="container mt-4">
<h2>Main Content</h2>
<p>This is the main content of the page.</p>
</main>
<!-- end snippet -->
答案1
得分: 1
尝试将.navbar
选择器添加到父容器中:right-header navbar
,因为实际上它来自该类(--bs-navbar-toggler-icon-bg
),而不是图标,_汉堡包_实际上是在.navbar
中定义的一个变量,所以通过将它添加到父容器中,它变得可访问:
.navbar-toggler-icon {
background-image: var(--bs-navbar-toggler-icon-bg);
}
.navbar {
--bs-navbar-toggler-icon-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2833, 37, 41, 0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<header class="bg-primary text-white text-center py-3">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="left-header">
<h3>Left Header</h3>
</div>
</div>
<div class="col-md-4">
<div class="central-header">
<h3>Central Header</h3>
</div>
</div>
<div class="col-md-4">
<div class="right-header navbar">
<button class="navbar-toggler mx-auto" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNav">
X<span class="navbar-toggler-icon"></span>X
</button>
</div>
<div class="collapse" id="collapsibleNav">
<div class="card">
<ul class="nav card-body">
<li class="nav-item">Item 1</li>
<li class="nav-item">Item 2</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</header>
<main class="container mt-4">
<h2>Main Content</h2>
<p>This is the main content of the page.</p>
</main>
英文:
Try adding .navbar
selector to the parent container: right-header navbar
, because it's actually coming from that class (--bs-navbar-toggler-icon-bg
), not the icon, the hamburger is actually a variable defined in .navbar
, so by adding it to the parent it becomes accessible:
.navbar-toggler-icon {
background-image: var(--bs-navbar-toggler-icon-bg);
}
<!-->
.navbar {
--bs-navbar-toggler-icon-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2833, 37, 41, 0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<header class="bg-primary text-white text-center py-3">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="left-header">
<h3>Left Header</h3>
</div>
</div>
<div class="col-md-4">
<div class="central-header">
<h3>Central Header</h3>
</div>
</div>
<div class="col-md-4">
<div class="right-header navbar">
<button class="navbar-toggler mx-auto" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNav">
X<span class="navbar-toggler-icon"></span>X
</button>
</div>
<div class="collapse" id="collapsibleNav">
<div class="card">
<ul class="nav card-body">
<li class="nav-item">Item 1</li>
<li class="nav-item">Item 2</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</header>
<main class="container mt-4">
<h2>Main Content</h2>
<p>This is the main content of the page.</p>
</main>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论