【问题标题】:How to align text in the center of an element without considering floated elements如何在不考虑浮动元素的情况下对齐元素中心的文本
【发布时间】:2013-01-21 20:19:42
【问题描述】:

好的,我得到了这个标记

<th class="ai1ec-weekday <?php if( $day['today'] ) echo 'ai1ec-today' ?>">
    <span class="ai1ec-weekday-date"><?php
    echo Ai1ec_Time_Utility::date_i18n( 'l', $date, true );
    ?> </span>
</th>

生成此输出,因为跨度有 text-align: center

现在我想添加一个向右浮动的按钮

<th class="ai1ec-weekday <?php if( $day['today'] ) echo 'ai1ec-today' ?>">
    <div class="btn-group pull-right">
        <button class="btn ai1ec-reveal-events"><?php _e( 'Reveal all events', AI1EC_PLUGIN_NAME ) ?></button> 
    </div>
    <span class="ai1ec-weekday-date"><?php
    echo Ai1ec_Time_Utility::date_i18n( 'l', $date, true );
    ?> </span>
</th>

这就是我得到的

我想得到的是 mondais 仍然像以前一样居中,但我想在不使用绝对定位的情况下做到这一点(当然,如果可能的话)

CSS(我的意思不是引导 CSS)

.ai1ec-week-view th .ai1ec-weekday-date,
.ai1ec-oneday-view th .ai1ec-weekday-date {
  font-size: 10.5pt !important;
  font-weight: normal !important;
}
.ai1ec-week-view th .ai1ec-weekday-day {
  font-size: 9pt !important;
  font-weight: normal !important;
}
.ai1ec-month-view th, .ai1ec-oneday-view th {
    text-align: center !important;
}

【问题讨论】:

  • 我们能看到所有的 CSS 吗? (或者是在 Twitter Bootstrap 中?)
  • 为什么不想使用绝对位置?
  • @PaulD.Waite 好吧,是的,这是 twitter 引导程序,我添加了我认为重要的内容,还有很多覆盖等等
  • @FabrizioCalderan 因为我认为它不会正确调整大小
  • 您可以在给定断点之后使用绝对位置(使用媒体查询)和移动优先样式的静态位置。

标签: html css twitter-bootstrap


【解决方案1】:

查看此方法:http://jsbin.com/uxejes/1/edit
(仅在 Fx18 和 Chrome 上测试)

相关的css

button {
  float: right; 
  margin-right: -100%;
  position: relative;
  left: -100%;
}

span {
  display: block;
  text-align: center;
}

按钮(带有position: relative)不会影响span元素内包含的文本的位置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 2017-10-27
    • 2020-12-17
    相关资源
    最近更新 更多