【问题标题】:Vertically Center in Twitter Bootstrap在 Twitter Bootstrap 中垂直居中
【发布时间】:2015-08-04 11:45:58
【问题描述】:

我使用 Bootstrap 是为了在用户将鼠标悬停在铃铛图标上时创建一个类似通知的下拉菜单(字体真棒)。菜单创建好了,菜单中的每个元素都由红色人字形标志表示。我无法将 V 形垂直居中并将文本与 V 形右侧对齐以从同一位置开始(每行开头都有一些边距)。我不能以固定值垂直居中 V 形,因为容器内字符串的长度可以不同,并且 V 形的位置应该动态确定。

基本上,我正在创建一个 jQuery 元素

$("<div class='notification-content'><i class='ion-chevron-right'></i><span class=''>"+randromString+"</span></div>");`,

人字形与内容一起插入。

JSfiddle here.

HTML

<div class="notifications_wrap text-center center b-l b-r hidden-sm hidden-xs">
   <span class="vlign"> </span>
   <a href="#" id="notification-center" aria-haspopup="true" data-toggle="dropdown">
   <i class="glyphicon glyphicon-bell"></i>
   <span class="bubble "></span>
   </a>
   <div class="dropdown-menu notification-toggle1" role="menu" aria-labelledby="notification-center" id="notif">
      <!-- START Notification -->
      <div class="notification-panel">
         <div class="test"></div>
      </div>
   </div>
</div>

CSS

#notif{
    background-color: white;
    color: black;
}

.notification-content{
    text-align: left;
    padding: 10px;
    padding-right: 25px;
    border-bottom: 1px solid #ddd;
    transition: 0.4s ease;
}

.notification-content:hover{
    color: #48B0F7;
}

.notification-toggle1 {
    top: 75px;
    padding: 0;
    z-index: 9999;
    left: 100px;
    width: 250px;
}

/*    > sign of the notification*/
.notification-content >.ion-chevron-right:before {
    color: red;
/*   display:inline-block;*/
    vertical-align: middle;
    line-height: 50%;
    width: 50px;
    height: 20px;
}

.notification-content>span{
    position: relative;
    left: 15px;
}

JS

  $(".notifications_wrap").find("a").mouseover(function(){
        $(".notification-content").remove();
        var random_i=randomNumOfNotifs();
        for(var i=0;i<random_i;i++){
            var randromString = stringGen(randomLength());
            var notification = $("<div class='notification-content'><i class='ion-chevron-right'></i><span class=''>"+randromString+"</span></div>");
            $("#notif").append(notification);
        }

        $("#notif").animate({height:"show"},500);
    });

【问题讨论】:

    标签: html css twitter-bootstrap font-awesome


    【解决方案1】:

    您可以添加以下css:

    .notification-content >.ion-chevron-right {
        display:table-cell;
        vertical-align:middle;
    

    }

    .notification-content>span{
        display:table-cell;
    }
    

    这是fiddle

    【讨论】:

    • 惊人的答案。您能解释一下display:table-cell 的工作原理吗?
    • 它允许您模拟表格显示。这两个块显示有单元格(之后,在一个简单的表格单元格中,您可以使用 vertical-align:middle 将内容垂直居中)...the doc
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2013-10-03
    • 2021-02-28
    • 2013-04-26
    • 2012-04-22
    • 2012-07-09
    相关资源
    最近更新 更多