【问题标题】:Why do my circular buttons break when going from Bootstrap 3 to Bootstrap 4?从 Bootstrap 3 转到 Bootstrap 4 时,为什么我的圆形按钮会损坏?
【发布时间】:2020-01-25 01:58:32
【问题描述】:

我有以下小提琴:

https://jsfiddle.net/b3x6ou4k/

当我将 CSS 链接从 Bootstrap 3 更改为 Bootstrap 4(使用 https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css 作为 CSS)时,圆形按钮变为方形。

为什么圆形按钮的CSS:

.btn-circle {
    width: 30px;
    height: 30px;
    text-align: center;
    padding: 6px 0;
    font-size: 12px;
    line-height: 1.428571429;
    border-radius: 15px;
}

在 Bootstrap 4 中不起作用,我如何保持这种风格:

而不是这种风格:

从 3 升级到 4 时?

【问题讨论】:

  • 查看文档。随着主要版本的碰撞 api 更改可能会破坏事情。看看他们是否有迁移文件。
  • 我看到圆形按钮(没有连接线) - 您在什么浏览器中看到这个?此外,您可能想使用最新的 4.x 版本,目前是 4.3.1。

标签: javascript html twitter-bootstrap


【解决方案1】:

您需要咨询migration docs,但这似乎与您之前所拥有的近似:https://jsfiddle.net/xrcu92bo/1/

<div class="container">
    <div class="stepwizard">
        <div class="stepwizard-row setup-panel">
            <div class="stepwizard-step col-xs-3"> 
                <a href="#step-1" type="button" class="btn btn-success btn-circle">1</a>
                <p><small>Shipper</small></p>
            </div>
            <div class="stepwizard-step col-xs-3"> 
                <a href="#step-2" type="button" class="btn border btn-light btn-circle" disabled="disabled">2</a>
                <p><small>Destination</small></p>
            </div>
            <div class="stepwizard-step col-xs-3"> 
                <a href="#step-3" type="button" class="btn border btn-light btn-circle" disabled="disabled">3</a>
                <p><small>Schedule</small></p>
            </div>
            <div class="stepwizard-step col-xs-3"> 
                <a href="#step-4" type="button" class="btn border btn-light btn-circle" disabled="disabled">4</a>
                <p><small>Cargo</small></p>
            </div>
        </div>
    </div>

    <form role="form">
        <div class="panel panel-primary setup-content" id="step-1">
            <div class="panel-heading">
                 <h3 class="panel-title">Shipper</h3>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="control-label">First Name</label>
                    <input maxlength="100" type="text" required="required" class="form-control" placeholder="Enter First Name" />
                </div>
                <div class="form-group">
                    <label class="control-label">Last Name</label>
                    <input maxlength="100" type="text" required="required" class="form-control" placeholder="Enter Last Name" />
                </div>
                <button class="btn btn-primary nextBtn pull-right" type="button">Next</button>
            </div>
        </div>

        <div class="panel panel-primary setup-content" id="step-2">
            <div class="panel-heading">
                 <h3 class="panel-title">Destination</h3>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="control-label">Company Name</label>
                    <input maxlength="200" type="text" required="required" class="form-control" placeholder="Enter Company Name" />
                </div>
                <div class="form-group">
                    <label class="control-label">Company Address</label>
                    <input maxlength="200" type="text" required="required" class="form-control" placeholder="Enter Company Address" />
                </div>
                <button class="btn btn-primary nextBtn pull-right" type="button">Next</button>
            </div>
        </div>

        <div class="panel panel-primary setup-content" id="step-3">
            <div class="panel-heading">
                 <h3 class="panel-title">Schedule</h3>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="control-label">Company Name</label>
                    <input maxlength="200" type="text" required="required" class="form-control" placeholder="Enter Company Name" />
                </div>
                <div class="form-group">
                    <label class="control-label">Company Address</label>
                    <input maxlength="200" type="text" required="required" class="form-control" placeholder="Enter Company Address" />
                </div>
                <button class="btn btn-primary nextBtn pull-right" type="button">Next</button>
            </div>
        </div>

        <div class="panel panel-primary setup-content" id="step-4">
            <div class="panel-heading">
                 <h3 class="panel-title">Cargo</h3>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="control-label">Company Name</label>
                    <input maxlength="200" type="text" required="required" class="form-control" placeholder="Enter Company Name" />
                </div>
                <div class="form-group">
                    <label class="control-label">Company Address</label>
                    <input maxlength="200" type="text" required="required" class="form-control" placeholder="Enter Company Address" />
                </div>
                <button class="btn btn-success pull-right" type="submit">Finish!</button>
            </div>
        </div>
    </form>
</div>

基本上,.btn-default 在 Bootstrap 4 中不存在;你得到的最接近的是.btn-light。我还添加了 .border 类,因为灯光按钮与您的背景没有太大的对比。

此外,disabled 属性 doesn't actually do anything on an anchor tag - 如果您想阻止用户点击“禁用”步骤,您需要使用 disabled 类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 2020-12-02
    • 1970-01-01
    • 2018-07-13
    • 2018-10-07
    相关资源
    最近更新 更多