如何在Panel Title的左侧和右侧添加文本?

时间:2013-08-21 08:56:37

标签: html css twitter-bootstrap

我正在使用Twitter Bootstrap为我带走了很多CSS工作。我想将他们的面板用于用户的某种“发布”。我想让标题部分包含标题右侧的编辑/删除超链接,而标题本身则在左侧对齐。

我试过这个没有成功:

<div class="row">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title">@vModel.Title <span class="text-right">Hey</span></h3>
        </div>
        <div class="panel-body">
            @vModel.Blog
        </div>
    </div>
</div>

标题应该在左侧对齐(默认情况下是这样)但我希望在右侧显示附加文本“嘿”。

编辑: http://getbootstrap.com/dist/css/bootstrap.css

6 个答案:

答案 0 :(得分:48)

Twitter bootstrap有两个类可以帮助你。

首先是.text-right,第二个是.pull-right所以请添加这两个类并查看。

答案 1 :(得分:39)

tiny clearfix做到了

<div class="panel panel-default">
    <div class="panel-heading">
         <div class="panel-title pull-left">
             Works fine for me!
         </div>
        <div class="panel-title pull-right">Text on the right</div>
        <div class="clearfix"></div>
    </div>
    <div class="panel-body">Panel content</div>
</div>

您可以在http://jsfiddle.net/b1Lec5ge/

尝试

答案 2 :(得分:3)

添加float:right并移除text-align: right

.text-right {
  float:right;
}

答案 3 :(得分:2)

问题的工作解决方案

<div class="panel panel-default">
    <div class="panel-heading">
        <div class="row">
            <div class="col-md-4 text-left panel-title">@vModel.Title</div>
            <div class="col-md-8 text-right"><a>hyperlink1</a> <a>hyperlink2</a></div>
        </div>
    </div>
    <div class="panel-body">
        ...
    </div>
</div>

面板的每个部分都可以使用col-xx-xx

保存行
<div class="panel panel-default">
    <div class="panel-heading">
        <div class="row">
            <div class="col-md-4 text-left">Header left</div>
            <div class="col-md-4 text-center">Header center</div>
            <div class="col-md-4 text-right">Header right</div>
        </div>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-md-6 text-right">Body left align right</div>
            <div class="col-md-6 text-left">Body right align left</div>
        </div>
    </div>
    <div class="panel-footer">
        <div class="row">
            <div class="col-md-3 text-center">Footer 1/4 center</div>
            <div class="col-md-3 text-center">Footer 2/4 center</div>
            <div class="col-md-3 text-center">Footer 3/4 center</div>
            <div class="col-md-3 text-center">Footer 4/4 center</div>
        </div>
    </div>
</div>

这里有一个带有col-xs-xxx的snipplet,用于匹配屏幕。文档here

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>


<div class="panel panel-default">
    <div class="panel-heading">
        <div class="row">
            <div class="col-xs-4 text-left">Header left</div>
            <div class="col-xs-4 text-center">Header center</div>
            <div class="col-xs-4 text-right">Header right</div>
        </div>
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-xs-6 text-right">Body left align right</div>
            <div class="col-xs-6 text-left">Body right align left</div>
        </div>
    </div>
    <div class="panel-footer">
        <div class="row">
            <div class="col-xs-3 text-center">Footer 1/4 center</div>
            <div class="col-xs-3 text-center">Footer 2/4 center</div>
            <div class="col-xs-3 text-center">Footer 3/4 center</div>
            <div class="col-xs-3 text-center">Footer 4/4 center</div>
        </div>
    </div>
</div>

答案 4 :(得分:1)

面板标题中的左右按钮。您可以使用链接替换这些按钮。

<div class="panel-heading text-right">
  <div class="nav"><!-- clears floated buttons -->

    <div class="btn-group pull-left" data-toggle="buttons">
      <label class="btn btn-default">
        <input type="checkbox" autocomplete="off"><i class="fa fa-toggle-on"></i>
      </label>
    </div>

    <div class="btn-group pull-right" data-toggle="buttons">
      <label class="btn btn-default">
        <input type="checkbox" autocomplete="off"><i class="fa fa-trash"></i>
      </label>
    </div>

  </div>
</div>

答案 5 :(得分:0)

我认为这也有帮助。你可以使用bootstrap行和列将面板分成两部分,就像我在这里做的那样:

<div class="panel panel-default">

    <div class="panel-body">

        <div class="row">

            <div class="col-md-6">

                <p>Text on left</p>

            </div>

            <div class="col-md-6">

                <p>Text on right</p>

            </div>

        </div>

    </div>

</div>