将第二个跨度的文本对齐在具有居中文本的第一个跨度下方

时间:2016-09-15 19:06:33

标签: html css alignment text-alignment

我想达到以下效果:

           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>

2 个答案:

答案 0 :(得分:2)

您必须将text-align:right放入.quote-container

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

请参阅此working示例

答案 1 :(得分:0)

将另一个包装放在.quote-container中,显示: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