在换行时,缩进DIV文本的最佳方式是什么? [英] What is the best way to indent text in a DIV when it wraps?

查看:124
本文介绍了在换行时,缩进DIV文本的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个包含一些动态文本的DIV。假设我知道文本和字体大小,但我不知道DIV的大小。我希望DIV文本的显示足够智能,以便在文本换行时显示缩进。



假设我的原始文本如下所示:

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



相反,我希望它看起来像这样:

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

什么是如果我不知道DIV的大小,最好的办法是做到这一点?如果我知道这个尺寸,最好的方法是什么?



谢谢!

解决方案

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


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!

解决方案

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

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

这篇关于在换行时,缩进DIV文本的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆