Yves Schelpe
Yves Schelpe

Reputation: 3463

Align second span's text right under first span that has centered text

I want to achieve following effect:

           Some centered quote on screen
                                ~ author

and when the quote is longer, the author part should always be aligned right under it

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

I currently have this setup, but I can't figure out the best way to handle this is 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>

Upvotes: 0

Views: 65

Answers (2)

oo7grayfox
oo7grayfox

Reputation: 11

Place another wrap inside .quote-container that is 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>

example here: http://codepen.io/anon/pen/gwAJyp

Upvotes: 0

Yuri Pereira
Yuri Pereira

Reputation: 1995

You have to put text-align:right inside the .quote-container

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

See this working example

Upvotes: 2

Related Questions