views:

70

answers:

2

I have a series of parragraphs. Each one ends with a ilustratión which clarifies the subject being xplained in the parragraph.

I want the ilustration to be on a new line and not display along with the text and I have found the following solutions, with it's own problems:

Put the ilustration in a different <p> than the text related to the ilustratión.

<p>Some text here<p/>
<p><img src="myphoto"/></p>

This seems to solve all the problems, but later I needed to enclose some of this parragraphs inside a <ul> instead of a <p>. The problem being I cannot enclose the <p> tag for the ilustration inside a <li> and does not make sense to put the ilustration inside a <li>.

<ul>
    <li>Some text</li>
    <p><img src="myphoto"/></p><!--Incorrect-->
    <li><img src="myphoto"/></li><!--Does not make sense-->
</ul>

Put the ilustration inside the same <p> as the text. Then use <br/> tag to move the picture to a new line. I'm not really happy with this workaround, the <br/> is doing presentational stuff that should be better in CSS.

<p>Some text here<br/><img src="myphoto"/></p>

Finally, set the display attribute of the <img> as block in the CSS style sheet. I'm not sure if this is a good way and don't know the unrelated consecuences it may have.

I don't know if there is a standard way of doing this. I have search for CSS to start my image in a new line but did not find it. Any help will be welcome.

+1  A: 

Ok, so this is my new solution. Basically, we just set the IMG element to be a block-level element.

img { display:block; }  

Live demo: http://vidasp.net/tinydemos/paragraph-image.html

This solution does not introduce any new markup. (You just place the <img> element right after the text in the paragraph / list item.)

I believe this to be the most elegant solution, since setting images to be blocks is rather common anyway.

Šime Vidas
David's point is he doesn't want a separate bullet for the illustrative image that follows the text - it's not a separate item, it doesn't make sense to have it's own bullet.
Rudu
Aha I get it ...
Šime Vidas
Rudu says exactly what I think, and Sime Vidas agrees with him and concludes his help is not rigth, but I cannot undestand. If I use a <br> tag inside the <li> tag to put the image in a new line I'm avoiding using a different <li> tag for the image and I getting it display in a new line. Is it rigth?
David Casillas
Your updated solution also seems the better for me. I can't see the need of an outer DIV as JacobM suggests below. There may be the need to add a CLASS attribute to the IMG so not every image gets display in a new line.
David Casillas
Yes, of course. Setting all images to blocks would be nonsense.
Šime Vidas
A: 

You're almost there, the simplest way is to wrap the text, and the image in block level elements:

For paragraphs:

<div class="paragraph">
  <div class="text">Some text</div>
  <div class="illustration"><img src="myphoto" /></div>
</div>

For list-items:

<ul>
  <li>
    <div class="text">Some text</div>
    <div class="illustration"><img src="myphoto" /></div>
  </li>
  <li>
    <div class="text">Some text2</div>
    <div class="illustration"><img src="myphoto2" /></div>
  </li>
</ul>

The classes are optional on the divs, but it allows you to further style them in CSS if you want.

Rudu
-1 You cannot place block-level elements inside paragraphs http://vidasp.net/HTML-structure-diagram.html
Šime Vidas
@Sime Good point, in a momentary lapse I forgot p is inline and not block, although you certainly can do this and the HTML will render fine, it's not a good approach. Better to style a block level element with margins for paragraph-like display then.
Rudu
Ok, I reversed the -1, however, it seems that someone else gave you another -1
Šime Vidas
Thanks @Sime, after a while you don't sweat the small stuff, although I certainly don't want to give misinformation. The communities about helping, learning new things, sometimes being tricked into doing work for other people ;) Something messy seems to be happening with the site anyway - it's no reporting no responses from today from me (and yet here your response is).
Rudu
Rudu says "p is inline and not block". Isn't it just the opposite?
David Casillas
Sime excelent link to vidasp.net/HTML-structure-diagram.html. It's really helpfull, not to mention the pleasing handwritten look.
David Casillas
Well, it is handwritten :) I don't know how to make such diagrams, so I just made it by hand and scanned the paper :)
Šime Vidas
P elements are block-level elements, of course.
Šime Vidas
That was supposed to read "(...) I forgot the content of p is inline(...)" sorry for the confusion David.
Rudu
'<div class="paragraph">' makes me a sad panda.
Bobby Jack
Yeah pandas aren't something I agree with. / I agree there's got to be a more semantically preferable class-name, but without context I can't tell. Used here only since David's likely to want to have margin formatting (at least) for the blocks.
Rudu