简体   繁体   English

引导面板标题 - 右对齐控件

[英]bootstrap panel title - align controls on right

I have few controls in bootstrap panel title section and I want them to display on the right side. 我在引导程序面板标题部分中有几个控件,我希望它们显示在右侧。 I used "pull-right" css class to align the controls on right but, the panel title is losing it's height. 我使用“pull-right”css类来对齐右边的控件,但是面板标题正在失去它的高度。 This behavior is observed in IE8 and above as well as chrome. 在IE8及更高版本以及chrome中观察到此行为。

Current Status: 当前状态:

在此输入图像描述

Fiddler: https://jsfiddle.net/99x50s2s/156/ 提琴手: https //jsfiddle.net/99x50s2s/156/

Code: 码:

<div id="DataRow" class="col-md-12">
    <div class="panel panel-info">
        <div class="panel-heading">
            <h3 class="panel-title">
                <div class="pull-right">
                    <a class="btn btn-warning btn-xs" data-toggle="collapse" data-parent="#DataRow" href="#CollapseData" aria-expanded="true" aria-controls="CollapseData">
                    <span class="glyphicon glyphicon-collapse-down"></span>
                </a>
                Data               

                <button class="btn btn-danger btn-xs disabled" id="DownloadBtn" type="button" title="Download all data"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span>&nbspDownload</button>
                </div>                
            </h3>

        </div>
        <div id="CollapseData" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
            <div class="panel-body">
                <div class="form-inline col-sm-12 move-down-sm">
                    Controls will be displayed here
                </div>
                <div class="form-horizontal col-sm-12 move-down-sm">
                    Controls will be displayed here
                </div>
                <div class="form-inline col-sm-12 move-down-sm">
                    Controls will be displayed here
                </div>                    
            </div>
            <div class="panel-footer">
                <button class="btn btn-success btn-xs" id="SaveChangesBtn" type="button" title="Save the changes"><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span>&nbspSave Changes</button>
            </div>
        </div>
    </div>
</div>

Expectation: 期望:

在此输入图像描述

What you need is to create a new block formatting context around the floated items. 您需要的是围绕浮动项创建一个新的块格式化上下文 This can be done in several ways . 这可以通过几种方式完成。 I've done so in this fork of your demo using overflow: hidden : https://jsfiddle.net/r30ebnfs/ 我在你的演示分支中使用overflow: hiddenhttps//jsfiddle.net/r30ebnfs/

Another acceptable method is using the following: 另一种可接受的方法是使用以下方法

.panel-title {
    display:inline-block;
    vertical-align: top;
    width: 100%;
} 

https://jsfiddle.net/r30ebnfs/1/ https://jsfiddle.net/r30ebnfs/1/

EDIT: 编辑:

Yet another method is to not float at all and use bootstrap styles (using text-right ): 另一种方法是不浮动并使用引导样式(使用text-right ):

<h3 class="panel-title text-right">
    <div class="">
        <a class="btn btn-warning btn-xs" data-toggle="collapse" data-parent="#DataRow" href="#CollapseData" aria-expanded="true" aria-controls="CollapseData">
            <span class="glyphicon glyphicon-collapse-down"></span>
        </a>
        Data               

        <button class="btn btn-danger btn-xs disabled" id="DownloadBtn" type="button" title="Download all data"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span>&nbspDownload</button>
    </div>                
</h3>

https://jsfiddle.net/r30ebnfs/3/ https://jsfiddle.net/r30ebnfs/3/

Elements normally get their height based on the content inside them. 元素通常根据其中的内容获得高度。 Floating elements don't normally contribute to that height, so if an element has floating child elements, it's content height will drop to zero if those are the only nested elements. 浮动元素通常不会对该高度有贡献,因此如果元素具有浮动子元素,则如果这些元素是唯一的嵌套元素,则其内容高度将降至零。

There are two ways to fix this behavior, both involve clearing the float. 有两种方法可以解决此问题,两种方法都涉及清除浮动。

<div id="someContainerWithFloatingChildren">
  <div class="floatingLeft"></div> <!-- or right, or both, doesn't matter-->
  <div class="clear"></div> <!-- empty element that clears the float -->
</div>

.clear {
    clear: both;
}

Or you can use a clearfix, a class that uses pseudo elements to accomplish what this clearing div is doing without polluting your markup with empty elements. 或者你可以使用一个clearfix,一个使用伪元素的类来完成这个清除div所做的事情,而不会用空元素污染你的标记。 I like this way better: https://jsfiddle.net/99x50s2s/157/ 我更喜欢这种方式: https//jsfiddle.net/99x50s2s/157/

More on clearfix: https://css-tricks.com/snippets/css/clear-fix/ 有关clearfix的更多信息: https ://css-tricks.com/snippets/css/clear-fix/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM