【发布时间】:2017-03-04 16:19:06
【问题描述】:
如何使用 Bootstrap 切换两个不同的图像?我希望它们充当单选按钮,但我也希望它们更改图像,指示一个是“活动的”,一个不是。
我的页面:http://matthewtbrown.com/test/imageasbutton/
代码 sn-p
.btn .btn-primary .active .thisweek {
padding: 0px;
border-left-width: 0px;
border-right-width: 0px;
border-top-width: 0px;
border-bottom-width: 0px;
content:url(../images/thisweek.png);
}
.btn .btn-primary .thisweek {
padding: 0px;
border-left-width: 0px;
border-right-width: 0px;
border-top-width: 0px;
border-bottom-width: 0px;
content:url(../images/thisweek_inactive.png);
}
.btn .btn-primary .active .alltime {
padding: 0px;
border-left-width: 0px;
border-right-width: 0px;
border-top-width: 0px;
border-bottom-width: 0px;
content:url(../images/thisweek.png);
}
.btn .btn-primary .alltime {
padding: 0px;
border-left-width: 0px;
border-right-width: 0px;
border-top-width: 0px;
border-bottom-width: 0px;
content:url(../images/alltime_inactive.png);
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active thisweek">
<input type="radio" name="options" id="option1" autocomplete="off" checked> <img src="images/thisweek.png" width="108" height="27" style="float: left" alt=""/>
</label>
<label class="btn btn-primary alltime">
<input type="radio" name="options" id="option2" autocomplete="off"><img src="images/alltime_inactive.png" width="259" height="27" alt=""/>
</label>
</div>
【问题讨论】:
-
SO 中已经有很多可用的内容..我在这里包括链接--[stackoverflow.com/questions/17541614/… [stackoverflow.com/questions/3896156/…
标签: html css twitter-bootstrap