Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you apply CSS only on text that is wrapped, i.e. the second and subsequent lines?

I want to put a margin-left on only the text that is wrapped, i.e. text after the first line:

This is text with no margin left      this text has margin left 

Example

click to see

The input and the label are in 1 div and text is wrapped on the second line, which is what I want
but is it possible to have like a margin left on only the text that is wrapped on the second line

jsfiddle example of my problem

like image 236
Kevin Avatar asked Mar 31 '11 08:03

Kevin


People also ask

What does wrap text do in CSS?

Definition and Usage The word-wrap property allows long words to be able to be broken and wrap onto the next line.

How do you wrap lines in CSS?

The overflow-wrap property in CSS allows you to specify that the browser can break a line of text inside the targeted element onto multiple lines in an otherwise unbreakable place. This helps to avoid an unusually long string of text causing layout problems due to overflow.

How do I keep text from wrapping in CSS?

If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).

Which tag is used to wrap the text to the next line?

The <br> HTML element produces a line break in text (carriage-return).


1 Answers

Yeah, sort of — I’d suggest combining padding-left and text-indent:

HTML

<div class="test">     <label for="2question1">         <input type="checkbox" id="2question1" name="2question" title="Merknaam 1" /> Very long text which is wrapped on the next line     </label><br>      <label for="2question2">         <input type="checkbox" id="2question2" name="2question" title="Merknaam 2" /> Merknaam 2     </label><br>      <label for="2question3">         <input type="checkbox" id="2question3" name="2question" title="Merknaam 3" /> Merknaam 3     </label><br>      <label for="2question4">         <input type="checkbox" id="2question4" name="2question" title="Merknaam 4" /> Merknaam 4     </label><br> </div> 

 CSS

.test {     width:200px; }  .test label {     display: block;     padding-left: 1em;     text-indent: -1em; } 

text-indent applies only to the first line of text in a block-level element, so it should achieve what you want.

See http://jsfiddle.net/pauldwaite/qUvvv/

like image 161
Paul D. Waite Avatar answered Nov 12 '22 03:11

Paul D. Waite