Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to indent text in a DIV when it wraps?

So I have a DIV that contains some dynamic text. Let's say I know the text and font-size but I don't know the size of the DIV. I'd like the display of the text in the DIV to be intelligent enough to show indentation when text wraps.

Say my original text looked something like this:

 Lorem ipsum dolor sit amet,  consectetur adipisicing  elit, sed do eiusmod  tempor incididunt 

Instead, I want it to look like this:

 Lorem ipsum dolor sit amet,     consectetur adipisicing     elit, sed do eiusmod     tempor incididunt 

What's the best way to do this if I don't know the size of the DIV a priori? And what's the best way to do it if I do know the size?

Thanks!

like image 718
fetucine53 Avatar asked Jan 26 '09 17:01

fetucine53


People also ask

How do I indent text inside a div?

You can use the CSS text-indent property to indent text in any block container, including divs, headings, asides, articles, blockquotes, and list elements. Say you want to indent all div elements containing text on a page to the right by 50px. Then, using the CSS type selector div, set the text-indent property to 50px.

How do you wrap a paragraph in a div?

If you've faced the situation when you need to wrap words in a <div>, you can use the white-space property with the "pre-wrap" value to preserve whitespace by the browser and wrap the text when necessary and on line breaks. Also, you'll need the word-wrap property.

How do you indent a text field?

Click the Properties button to open the Text Box Properties dialog box, and then click the Indents and Spacing tab. In the Indentation section, select First line from the Special list, and then in the By box, type the amount that you want the first line to be indented.


1 Answers

If I understand what you're asking for, this works for me:

div {     padding-left: 2em;     text-indent: -2em; } 
like image 197
Allain Lalonde Avatar answered Oct 24 '22 16:10

Allain Lalonde