gpt4 book ai didi

css - bootstrap btn-group 按钮未加入

转载 作者:太空宇宙 更新时间:2023-11-04 08:51:33 26 4
gpt4 key购买 nike

我使用的是 Bootstrap 版本 3.3.7,我从 W3Schools 网站上获得了这段代码( Bootstrap 网站目前在我的国家/地区不可用):

    <div class="btn-group btn-group-lg">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>

按钮没有连接在一起:

buttons not joined

我已经尝试添加 role="group",有和没有 btn-group-lg,在表单和容器内以及页面上裸露.在 chrome 开发人员工具中,我可以看到 btn-group 被应用并且没有被覆盖(我希望 border-radius 是)并且我已经重新下载了 boostrap CSS 文件以防我不小心损坏它们:

Chrome developer tools

我还可以查看什么来了解为什么他们没有加入?

我在输入组上有类似的东西,但目前找不到示例。

编辑

根据其中一个答案,我删除了所有应用程序样式并链接到 Bootstrap CDN,但它仍然不起作用,我看到 fiddle 和片段确实有效,但我仍然不知所措至于为什么它在这里不起作用。基于相同的答案,我将其添加到我的应用程序 CSS 中:

.btn-group button.btn {
border-radius:0px;
}
.btn-group button.btn:first-child {
border-radius:6px 0 0 6px;
}

.btn-group button.btn:last-child {
border-radius:0 6px 6px 0;
}

现在它们按预期出现了,但如果可能的话,我仍然想弄清楚到底发生了什么:(

最佳答案

尝试将此添加到您的样式中,这将检查 btn 组中的 btn 是否不是第一个或最后一个子节点,将 border-radius 设置为 0:

.btn-group>.btn:not(:first-child):not(:last-child):not(.dropdown-toggle) {
border-radius: 0 !important;
}

适合我吗?你有任何使用 !important 的 css 可以覆盖 Bootstrap 样式吗?

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>



<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>

您可以创建自己的 btn 的另一个选项,检查以下内容:

最重要的是

.btngrp li:first-child {
border-radius: 6px 6px 0 0;
border-top-width: 2px;
}
.btngrp li:last-child {
border-radius: 0 0 6px 6px;
}

这将通过强制 first btn in group 创建 btn group 效果,在左侧有 border-radiuslast btn in group要在右侧有 border-radius,中间的任何 btn 都不会有任何 border-radius 属性。

*, *:before, *:after {
box-sizing: border-box;
}

body {
text-align: center;
padding: 2em;
font-family: raleway, sans-serif;
}

.btngrp {
list-style-type: none;
margin: 2em auto;
padding: 0;
font-size: .85em;
display: table;
letterspacing: .2em;
}
@media (min-width: 768px) {
.btngrp {
font-size: 1em;
}
}
.btngrp li {
vertical-align: middle;
background: #337ab7;
padding: .75em 1.5em;
line-height: 0.5;
border: 2px solid #2e6da4;
border-top-width: 0;
-webkit-transition: 200ms;
transition: 200ms;
}
.btngrp li:first-child {
border-radius: 6px 6px 0 0;
border-top-width: 2px;
}
.btngrp li:last-child {
border-radius: 0 0 6px 6px;
}
@media (min-width: 480px) {
.btngrp li {
display: table-cell;
border-top-width: 2px;
border-left-width: 0;
}
.btngrp li:first-child {
border-radius: 6px 0 0 6px;
border-left-width: 2px;
}
.btngrp li:last-child {
border-radius: 0 6px 6px 0;
}
}
.btngrp li:hover {
background: #286090;
border: 2px solid ##204d74;
}
.btngrp a {
display: block;
text-align: center;
padding: 0 .5em;
text-decoration: none;
}
@media (min-width: 768px) {
.btngrp a {
padding: .5em .5em;
}
}
.btngrp a:link, .btngrp a:visited {
color: white;
}
<ul class="btngrp">
<li><a href="#">Apple</a></li>
<li><a href="#">Samsung</a></li>
<li><a href="#">Sony</a></li>
</ul>

关于css - bootstrap btn-group 按钮未加入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43414098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com