最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Center same-paragraph text in a new line - Stack Overflow

programmeradmin0浏览0评论

I have this paragraph which I decreased the width of so a part of its text appears in a new line. How do I center the text in the new line?

I have tried using the <center> tag, but it messed up my paragraph by shoving all the text in the previous line to the corner. I considered using the html space entity ( ), but there must be a better way. Here's my code:

<div class="CTA-disclaimer">
      <p>After your free trial, the yearly subscription is $69.99 and automatically 
      renews each year  until <!-- New line, to be centered -->
cancelled. <a href="">Terms</a> | <a href="">Cancel anytime</a>
      </p>
     </div>

CSS:

.CTA-disclaimer {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.CTA-disclaimer p{
    color: rgba(0, 0, 0, 0.6);
    font-size: 12px;
    font-weight: 500;
    width: 500px;
}

I have this paragraph which I decreased the width of so a part of its text appears in a new line. How do I center the text in the new line?

I have tried using the <center> tag, but it messed up my paragraph by shoving all the text in the previous line to the corner. I considered using the html space entity ( ), but there must be a better way. Here's my code:

<div class="CTA-disclaimer">
      <p>After your free trial, the yearly subscription is $69.99 and automatically 
      renews each year  until <!-- New line, to be centered -->
cancelled. <a href="">Terms</a> | <a href="">Cancel anytime</a>
      </p>
     </div>

CSS:

.CTA-disclaimer {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.CTA-disclaimer p{
    color: rgba(0, 0, 0, 0.6);
    font-size: 12px;
    font-weight: 500;
    width: 500px;
}
Share Improve this question asked Feb 6 at 13:25 Adam 10kAdam 10k 113 bronze badges New contributor Adam 10k is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 4
  • 3 <center> is a deprecated/obsolete element and should no longer be used. – Paulie_D Commented Feb 6 at 13:26
  • Oh, didn't know that. Thank you for the info! – Adam 10k Commented Feb 6 at 13:28
  • 1 If you don't want to apply text-align: center to the whole paragraph (which will move the text in the first line a little bit as well), then stick the "new line" content into a span, and applydisplay: block; text-align: center to that. – C3roe Commented Feb 6 at 13:30
  • 1 It works! Thank you. – Adam 10k Commented Feb 6 at 13:36
Add a comment  | 

1 Answer 1

Reset to default 1

What I believe you are asking for is text-align-last

The text-align-last CSS property sets how the last line of a block or a line, right before a forced line break, is aligned.

.CTA-disclaimer {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.CTA-disclaimer p {
  color: rgba(0, 0, 0, 0.6);
  font-weight: 500;
  width: 500px;
  border: 1px solid grey;
  text-align-last: center;
}
<div class="CTA-disclaimer">
  <p>After your free trial, the yearly subscription is $69.99 and automatically
    renews each year until cancelled. <a href="">Terms</a> | <a href="">Cancel anytime</a>
  </p>
</div>

发布评论

评论列表(0)

  1. 暂无评论