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!
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.
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.
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.
If I understand what you're asking for, this works for me:
div { padding-left: 2em; text-indent: -2em; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With