简体   繁体   English

如何使段落的第二行居中?

[英]How can I center the second line of a paragraph?

I need help centering the second line of my paragraph.我需要帮助将我的段落的第二行居中。 I don't know what to do because I'm new to HTML and CSS but I did try to create two "p" and give the second one a "text-align: center" however it was too far from the first line and I feel like there must be a better way to achieve what I want.我不知道该怎么做,因为我是 HTML 和 CSS 的新手,但我确实尝试创建两个“p”并给第二个“text-align:center”,但是它离第一行太远了,我觉得必须有更好的方法来实现我想要的。

This is the HTML sheet:这是 HTML 表:

 .p_music2 { color: #000; font-family: "PT Sans Narrow", sans-serif; font-size: 2rem; margin: 2.5rem 6rem; }
 <p class="p_music2"> Upgrade today to get your favorite music, movies, TV shows, and podcasts. You can join youTunes and stream — or download and play offline — over 70 million songs, ad‑free. </p>

Wrap the text that you want to center in a <span></span> and then set that span to display: block; text-align: center;将要居中的文本包裹在<span></span>中,然后将该跨度设置为display: block; text-align: center; display: block; text-align: center; . .

display: block; will cause that block of code to break out of the flow of the rest of the sentences, and allow you to center it.将导致该代码块脱离句子的 rest 流,并允许您将其居中。

 .p_music2 { color: #fff; font-family: "PT Sans Narrow", sans-serif; font-size: 2rem; margin: 2.5rem 6rem; background: #000; }.p_music2 span { display: block; text-align: center; }
 <p class="p_music2">Upgrade today to get your favorite music, movies, TV shows, and <span>podcasts. You can join youTunes and stream — or download and play</span> offline — over 70 million songs, ad‑free.</p>

I would recommend to create a parent <div> element class with the property text-align:center and inside that element add your <p> HTML elements with the corresponding text.我建议创建一个具有属性text-align:center的父<div>元素 class 并在该元素内添加具有相应文本的<p> HTML 元素。 Then set the styles properties of those two elements separately one for the parent music2 and another for all your <p> elements so you can have control over the margins of the <p> elements.然后分别设置这两个元素的 styles 属性,一个用于父music2 ,另一个用于所有<p>元素,这样您就可以控制<p>元素的边距。

 html{background:blue; color: #fff;font-family: "PT Sans Narrow", sans-serif;font-size: 2rem;padding:50px;}.music2 { text-align:center; }.music2 p{ margin: 0px; }
 <div class="music2"> <p> Upgrade today to get your favorite music, movies, TV shows, and podcasts. You can join youTunes and stream — or download and play offline — over 70 million songs, ad‑free. </p> <p> second paragraph..... offline — over 70 million songs, ad‑free. </p> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM