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

fetucine53 picture fetucine53 · Jan 26, 2009 · Viewed 43.4k times · Source

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!

Answer

Allain Lalonde picture Allain Lalonde · Jan 26, 2009

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

div {
    padding-left: 2em;
    text-indent: -2em;
}