Using only CSS: How do you center the first line of formatted text and keep the remaining left justified?

Zinthose

I can't use javascript. Just getting that out of the way.

I want to format existing data to format the first line to be bold and centered. The remaining lines to be justify formatted. The issue I keep running into is the first like either gets justified or the last wrap for each line gets centered.

Any ideas?

/* Using the following is the closest I've gotten to getting it to work. */
#data {
  white-space: pre-line;
  text-align-last: center;
  text-align: justify;
}


#data::first-line {
  font-weight: bold;
}
<h3>This is the data given</h3>
<div id="data">This is the first line!
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>

<br>
<h3>This is what I want</h3>

<div align="center" style="font-weight: bold">This is the first line!</div>
<div align="justify">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>

p.s. bonus points if we can add inline tags via css to wrap data dynamically without Javascript.

Temani Afif

Here is a trick using pseudo element and padding to simulate this behavior. You may adjust the value of padding depending on the text in the first line.

#data {
  white-space: pre-line;
  text-align: justify;
}
#data:before {
  content:" ";
  padding:0 20%;
}

#data::first-line {
  font-weight: bold;
}
<h3>This is the data given</h3>
<div id="data">This is the first line!
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I keep reading the remaining bytes after reading the first few bytes using conn.Read() in Go?

How do I vertically center text with CSS?

How do you easily horizontally center a <div> using CSS?

CSS padding-left value of <code> is applied for only the first line

How do I left align text in a menu and keep the text visible?

How do you center text in Gitlab markdown?

How do I center child text on the left edge of Flexbox boxes?

How do I left align text in a menu and keep the text visible?

How to center text inputs using Materialize CSS?

How to center a flush-left text block on the longest line in CSS?

HTML/CSS align to left but keep center

How can text be justified on both the left and right sides of a line in Word?

Diff: How do you only compare the first n characters in each line?

How to put text on the center of a circle using CSS

How to test if an item is left justified?

Image to the left from a justified text

How do you double space text and keep the text alignment at the top?

How to CSS pairs of DIV text left/right of center

How do I only keep the first line of text in a multi-line cell?

jTextArea saves only first line of text in text file using BufferedReader?

How to center multiple line text in html using css, just like <center>?

How do you create a div with a triangle shape using css only?

How do you center two divs using pure CSS without Bootstrap?

How do you center a text-align=left text in a table cell in angular (css table)?

How do you keep the text from a text box in an appended box?

how to keep text on one line using css or javascript

How do you vertically align text using line-height for a css grid row element created using grid-template-rows?

How do you center Text in ScrollView at SwiftUI

How do you cut text from a line and append it to another line in text file using python?