Yves Schelpe Yves Schelpe - 1 year ago 38
CSS Question

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.


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


.align-center-page {
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: "~ ";

Answer Source

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

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

See this working example