#1 2008-02-21 16:09:01
- MrStitch
- Member

- Registered: 2006-10-24
- Posts: 1079
- I've been thanked 12 times.
-

Image Breaks Div
I'm working on a site redesign, and as usual I've got a box for my content. The box is a div, and is skinnier than the width of my screen, and placed somewhat in the middle.
I put a picture in that box, and told it align=right.
At first, in FF, the picture broke the boundary of the div, sitting up against the right side of the screen. But in IE, it worked just like it's suppose to.
Since I literally just started, I haven't put in an html declaration yet, and thought that was the problem. Sooo... I gave it a 4.01transitional, and uploaded everything onto my server.
Now, the picture is breaking outside the div on BOTH browsers.... figures. In my CSS file, I gave the div some padding, but that didn't do anything. It's like the image is ignoring the div all together.
Any ideas?
Offline
#2 2008-02-21 16:27:21
- Steven_A_S
- Member

- From: San Antonio, TX
- Registered: 2006-08-07
- Posts: 449
- I've been thanked 21 times.
-
Re: Image Breaks Div
take out the align=right, add a style to the img with the attributes display:block; float:right; instead. You may also need something like <br style="clear:right"> just before the closing </div> to make sure the box properly surrounds the image at the bottom.
Offline
#3 2008-02-21 16:55:02
- MrStitch
- Member

- Registered: 2006-10-24
- Posts: 1079
- I've been thanked 12 times.
-

Re: Image Breaks Div
Hmmm... didn't work.
I know I'll have to do the br=clear thingy.... always have to do that for FF (don't understand why... stupid).
Guess I'll give it a shot on monday....
Offline
#4 2008-02-21 19:23:13
- laurie_m
- Member

- From: Bega, Sapphire Coast Australia
- Registered: 2005-08-18
- Posts: 1392
- I've been thanked 33 times.
-

Re: Image Breaks Div
Hey Stitch!
I've never done a br=clear thingy. Never seen it before. But my images work fine.
Make sure you've got the </div>
align=right isn't correct. That maybe your problem. Use float:right as Steven suggested.
Here's what I use:
Code: css
img {
padding: 0px;
display: inline;
border: solid black 1px;}
p.right_350 {
float: right;
text-align: center;
width: 350px;
margin: 0 0 2px 7px;
color: #666666;
}
Code: html
<p class="right_350">
<img src='http://www.sapphirecoastnews.com/wp-content/uploads/2008/02/julia_gillard.jpg' alt='Julia Gillard' />
Julia Gillard
</p>
This gives me an image with a black border. The text (caption) is centred below the image, outside the border. The text content flows around the image.
I don't understand what display: inline; means. But it works. I think it makes the top of the image line up with the top of the text. Not real sure about that, though. I think it will still work the same without it. So dunno!
I've been using <p> lately instead of <div> because that's what WP likes.
If you don't want the black border, or if you can be happy with the border surrounding the caption text as well as the image, you can control it all with the <img> tag.
Regards,
Laurie.
Last edited by laurie_m (2008-02-21 19:25:42)
John McDouall Stuart - Explorations in Australia
First Expedition Second Expedition Third Expedition Fourth Expedition
Offline
#5 2008-02-22 01:20:23
- streetkiter
- New member
- Registered: 2008-01-10
- Posts: 2
- I've been thanked 1 times.
-
Re: Image Breaks Div
Code: html
<div style = "border: 1px solid black; width: 500px; margin: 0 auto;"><img style = "float: right" src="boxes.jpg" /><br clear="right" /></div>
Offline
#6 2008-02-22 09:21:16
- Steven_A_S
- Member

- From: San Antonio, TX
- Registered: 2006-08-07
- Posts: 449
- I've been thanked 21 times.
-
Re: Image Breaks Div
laurie_m wrote:
I don't understand what display: inline; means. But it works. I think it makes the top of the image line up with the top of the text. Not real sure about that, though. I think it will still work the same without it. So dunno!
The display:inline; attribute is meant to make a block type element (<p>, <h1>...<h6>, <div>, any element that will normally take up a full area horizontally) act like an inline element (<span>, <b>, <img>, any element that can be used to change part of a line or add something inside a line). an image is already considered an inline element, so display:inline; is actually redundant. Normally when you float an object, it should be a block type, hence the reason I use display:block;. It's also a good idea to set the height and width in css of an image you're floating.
Last edited by Steven_A_S (2008-02-22 09:22:07)
Offline
#7 2008-02-23 05:02:11
- aknet47
- Member
- From: vienna
- Registered: 2006-09-14
- Posts: 234
- I've been thanked 1 times.
-
Re: Image Breaks Div
Elements behave like block-elements, by using CSS float 
Code: html
<div style = "border: 1px solid black; width: 500px; margin: 0 auto; text-align: right"><img src="img.jpg" /></div>
Thatīs the way how to right-align the img: text-align: right should be applied to the parent-div.
Last edited by aknet47 (2008-02-23 07:56:50)
Iīve got a blog
Offline
#8 2008-02-23 10:01:58
- Steven_A_S
- Member

- From: San Antonio, TX
- Registered: 2006-08-07
- Posts: 449
- I've been thanked 21 times.
-
Re: Image Breaks Div
Once a block element is floated (say to the right), any following elements, block and inline, will try and fill the empty space (in this case to the left of the floated object). Using text-align would have the unfortunate effect of causing text inside to be aligned right, and may not work as desired on images in all browsers as the specification is only meant to affect text (yes it probably works in IE, but that's because IE isn't compliant)
Offline
#9 2008-02-23 19:17:58
- laurie_m
- Member

- From: Bega, Sapphire Coast Australia
- Registered: 2005-08-18
- Posts: 1392
- I've been thanked 33 times.
-

Re: Image Breaks Div
Well, thanks, Steven.
I don't know how our friend Stitch is getting on but I'm working through this stuff, trying to get my head around it.
1) I understand the br=clear thingy now. And, yes, I have had an image stick through the bottom of the box when there isn't enough text to fill the left space and flow under the photo. Thought it was an unexplained mystery. Thanks.
2) text-align: center works for me in FF, IE and Opera.
I've had a look at the WC3 site and it looks like this is OK for block elements. That's what they give for <h1>.
Code:
<html>
<head>
<style type="text/css">
h1 {text-align: center}
h2 {text-align: left}
h3 {text-align: right}
</style>
</head>
<body>
<h1>This is header 1</h1>
<h2>This is header 2</h2>
<h3>This is header 3</h3>
</body>
</html>
So if I change the display: inline in my <div> or <p> for the photo, to display: block, thus making the element a block element, will align-text: center then be correct?
Note that what I want, and have achieved, is a photo with a black border and the caption centred below it (outside the border), and the main text flowing around this.
3) As a rule, I set up my css file with a set of standard sized <div>s or <p>s floated both left and right. This places my caption text nicely in line with the photo. Eg left 100px, 250px, 300px and so on. The same for float right. I always resize the photos to these standard sizes. But I never specify the height of the image. Seems to work OK.
Thanks,
Laurie.
Last edited by laurie_m (2008-02-23 19:20:08)
John McDouall Stuart - Explorations in Australia
First Expedition Second Expedition Third Expedition Fourth Expedition
Offline
#10 2008-02-24 10:06:20
- Steven_A_S
- Member

- From: San Antonio, TX
- Registered: 2006-08-07
- Posts: 449
- I've been thanked 21 times.
-
Re: Image Breaks Div
I'm not sure what you're asking, what you have seems to work fine on your page. Changing the image to a block element would prevent the text in the paragraph from coming up beside the image if the width of the paragraph were wider than the image and the text would be centered, but the image wouldn't be centered (except in IE)
The way I would have done it (though not necessarily better) is this:
Code: css
.right_350
{
float:right;
width:352px; /* 2 px wider to account for the 1 px border on each side of the image */
margin:0 0 2px 7px;
}
img
{
padding: 0px;
border: solid black 1px;
}
/* I used h4 instead of paragraph just for semantics and because it differentiates it from other
paragraphs you're probably using. you can use paragraph, but you'd need to set a class */
h4
{
text-align: center;
margin:0;
padding:0;
color: #666666;
}
Code: html
<div class="right_350">
<img src='http://www.sapphirecoastnews.com/wp-content/uploads/2008/02/julia_gillard.jpg'
alt='Julia Gillard' />
<h4>
Julia Gillard
</h4>
</div>
This just takes the image out of the paragraph so I can control them separately and puts them both in a div which controls how they interact with the rest of the page. Because the image is contained in a block element (div in my example and paragraph in yours) there's no need to change the display type on the image.
Offline
#11 2008-02-24 18:19:56
- laurie_m
- Member

- From: Bega, Sapphire Coast Australia
- Registered: 2005-08-18
- Posts: 1392
- I've been thanked 33 times.
-

Re: Image Breaks Div
Thanks Steven.
I think I'll stick to doing it the way I have been.
With the br clear thingy:
WP is a brute of a thing in some situations. Any valid code that it doesn't like, it just destroys.
But I should be able to add to the css file for the appropriate div, something like:
Code: css
.whatever br
{
clear: both;
}
I should then be able to use a <br /> tag after the image and all will be well.
Or would it work if I simply used a br tag on it's own?
Thanks,
Laurie.
John McDouall Stuart - Explorations in Australia
First Expedition Second Expedition Third Expedition Fourth Expedition
Offline
#12 2008-02-24 22:39:23
- Steven_A_S
- Member

- From: San Antonio, TX
- Registered: 2006-08-07
- Posts: 449
- I've been thanked 21 times.
-
Re: Image Breaks Div
I wouldn't tie it to just a break tag as that could mess things up when you don't really need to clear a float. I normally assign a class to the break and set the clear:both; on that class
Offline
#13 2008-02-24 23:12:33
- laurie_m
- Member

- From: Bega, Sapphire Coast Australia
- Registered: 2005-08-18
- Posts: 1392
- I've been thanked 33 times.
-

Re: Image Breaks Div
OK. Looks like the inline style that you gave in the first place is the way to go.
<br style="clear:right">
Is that the correct way to write it for xhtml? Should it be <br style="clear:right" /> ?
Thanks,
Laurie.
John McDouall Stuart - Explorations in Australia
First Expedition Second Expedition Third Expedition Fourth Expedition
Offline
#14 2008-02-25 03:58:43
- streetkiter
- New member
- Registered: 2008-01-10
- Posts: 2
- I've been thanked 1 times.
-
Re: Image Breaks Div
the <br style="clear: right" /> is one way to go. (Take care of the "/" wich closes the tag) this is a must if you want to write w3c compliant xhtml - it closes the tag.
the other version is <br clear="right" /> <- slightly different - it doesnīt make use of css
the 3rd version for xhtml - strict
for the strict version <br /> is outdated, in this case youīll need some extra markup:
<div style="clear: right"></div>
thatīs it !?!
Offline
#15 2008-02-25 05:47:41
- laurie_m
- Member

- From: Bega, Sapphire Coast Australia
- Registered: 2005-08-18
- Posts: 1392
- I've been thanked 33 times.
-

Re: Image Breaks Div
Thanks streetkiter.
We're really getting to the finer points of css, now! 
Regards,
Laurie.
John McDouall Stuart - Explorations in Australia
First Expedition Second Expedition Third Expedition Fourth Expedition
Offline
#16 2008-02-25 09:36:37
- Steven_A_S
- Member

- From: San Antonio, TX
- Registered: 2006-08-07
- Posts: 449
- I've been thanked 21 times.
-
Re: Image Breaks Div
actually Street, I tested my page (which has <br /> tags) on xhtml 1.0 strict and xhtml 1.1 (which is strict only) and both accepted the tags. Doesn't look like W3C is depricating the <br /> tag yet.
Offline
#17 2008-02-29 16:57:16
- MrStitch
- Member

- Registered: 2006-10-24
- Posts: 1079
- I've been thanked 12 times.
-

Re: Image Breaks Div
I think I might have figured it out.
I was thinking that 'padding' on a div was meant for the INSIDE of the box, but NOOOOooooo. Combine that with some other things that don't make any sense (like when I add padding-left on the dive, the entire size of the box changes), and you get yourself a mess.
So, what I did was styled a P tag (probably have to do that 100,000 times) and got the correct results.
Is there a way to force the size of a div, and add padding to the inside of the box.... wait... Margin is 'outside', isn't it?
Frick... Now I'm utterly lost.
Offline
#18 2008-02-29 17:52:22
- Steven_A_S
- Member

- From: San Antonio, TX
- Registered: 2006-08-07
- Posts: 449
- I've been thanked 21 times.
-
Re: Image Breaks Div
Any height you set doesn't include the padding, margin, and border width. The padding is inside the border, but outside what is considered the object or div. When you evaluate how much space an object is going to take for purposes of placement you need to add the padding, border width, and margin to it. Hopefully this example will help
Code:
-------------------------------------------------------------------
| Margin |
| ------------------------Border------------------------- |
| | Padding | |
| | --------------------------------------------- | |
| | | /\ | | |
| | | | | | |
| | | height | | |
| | |<----width-----------+-------------------->| | |
| | | \/ | | |
| | --------------------------------------------- | |
| ------------------------------------------------------- |
-------------------------------------------------------------------
Assuming the object above is your div, the area you could normally put something within the div would be limited to inside the inner box (assuming you didn't use negative margins, specifically position the object outside the div, or the inner object didn't overflow the div).
Last edited by Steven_A_S (2008-02-29 20:36:43)
Offline
#19 2008-03-02 12:58:37
- MrStitch
- Member

- Registered: 2006-10-24
- Posts: 1079
- I've been thanked 12 times.
-

Re: Image Breaks Div
Not at work right now, so I can't see the code, but....
Thinking back, I just might have a margin set for the div on the left side. This was to position the box appropriately underneath the heading. Then, I added padding to the div (which apparently was incorrect), to position the text. What's weird is, it worked... but then made the size of the div bigger.
I'm guessing the padding and margin settings of the div 'locked horns' and one beats out the other, causing a slight mess.
I'll just have to keep in mind that I should use margin settings for positioning text, graphics.... see what happens on monday.
Offline
| Never |
- Sponsored Results
|
|