【问题标题】:Align second span's text right under first span that has centered text在具有居中文本的第一个跨度下方对齐第二个跨度的文本
【发布时间】:2016-09-16 14:40:56
【问题描述】:

我想达到以下效果:

           Some centered quote on screen
                                ~ author

当引用较长时,作者部分应始终在其下方对齐

           Some longered, maybe even
      multi-line centered quote on screen
                                 ~ author

我目前有这个设置,但我不知道处理这个的最佳方法是 CSS。

.align-center-page {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.quote-container {
  width: 80%;
  text-align: center;
}
.quote-big {
  font-size: 52px;
  font-weight: bold;
  margin-bottom: 0px;
}
.quote-big span {
  margin: 0px;
  clear: both;
}
.quote-author {
  display: block;
  font-size: 14px;
  font-weight: normal;
  font-style: italic;
  margin-top: 0px;
  text-align: right;
}
.quote-author:before {
  content: "~ ";
}
<div class="align-center-page quote-container">
  <span class="quote-big">@Model.Quote</span>
  <span class="quote-author">@Model.Author</span>
</div>

【问题讨论】:

    标签: html css alignment text-alignment


    【解决方案1】:

    你必须把text-align:right 放在.quote-container 里面

    .quote-container {
        width: 80%;
        text-align: right;
    }
    

    查看此working 示例

    【讨论】:

      【解决方案2】:

      在 .quote-container 中放置另一个包装,即 display: inline-block;

      <div class="align-center-page quote-container">          
        <div class="display-inline-block">
          <span class="quote-big">@Model.Quote</span>
          <span class="quote-author">@Model.Author</span>
        </div>
      </div>
      

      此处的示例:http://codepen.io/anon/pen/gwAJyp

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-11
        • 1970-01-01
        • 2019-01-08
        相关资源
        最近更新 更多