gpt4 book ai didi

html - 如何在 bootstrap3 中创建响应式按钮?

转载 作者:太空狗 更新时间:2023-10-29 14:55:45 25 4
gpt4 key购买 nike

我尝试在 768 像素的屏幕上显示 btn-sm,但它一直显示 btn-xs。

这是我的 HTML 代码

<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3 col-sm-offset-3">
<button name="magnet" class="btn btn-success btn-sm btn-xs btn-lg">
<em class="glyphicon glyphicon-home"></em>
Home
</button>

<button name="magnet" class="btn btn-danger btn-sm btn-xs">
<em class="glyphicon glyphicon-download"></em>
Download
</button>
</div>

是否可以在不使用媒体查询的情况下完成此任务?

最佳答案

您的按钮不会神奇地与纯 HTML 一起缩放。所以你有两个选择。

选项#1:重复

这是最丑陋的一个,但它满足您的需求,因为它不需要额外的媒体查询:

<div class="container">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3 col-sm-offset-3">
<button name="magnet" class="btn btn-success btn-xs visible-xs"><em class="glyphicon glyphicon-home"></em> Home</button>
<button name="magnet" class="btn btn-success btn-sm visible-sm"><em class="glyphicon glyphicon-home"></em> Home</button>
<button name="magnet" class="btn btn-success btn-lg visible-md visible-lg"><em class="glyphicon glyphicon-home"></em> Home</button>

<button name="magnet" class="btn btn-danger btn-xs visible-xs"><em class="glyphicon glyphicon-download"></em> Download</button>
<button name="magnet" class="btn btn-danger btn-sm visible-sm"><em class="glyphicon glyphicon-download"></em> Download</button>
<button name="magnet" class="btn btn-danger btn-lg visible-md visible-lg"><em class="glyphicon glyphicon-download"></em> Download</button>
</div>
</div>

Bootply

选项#2:媒体查询

你...终于。这是执行此操作的正确方法。

<div class="container">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3 col-sm-offset-3">
<button name="magnet" class="btn btn-success btn-autosize">
<em class="glyphicon glyphicon-home"></em>
Home
</button>

<button name="magnet" class="btn btn-danger btn-autosize">
<em class="glyphicon glyphicon-download"></em>
Download
</button>
</div>
</div>
.btn-autosize {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
@media screen and (min-width: 768px) {
.btn-autosize {
padding: 5px 10px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
}
@media screen and (min-width: 992px) {
.btn-autosize {
padding: 10px 16px;
font-size: 18px;
line-height: 1.33;
border-radius: 6px;
}
}

Bootply

关于html - 如何在 bootstrap3 中创建响应式按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21709917/

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