Why does this work?

This is a discussion on "Why does this work?" within the Web Page Design section. This forum, and the thread "Why does this work? are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 6th, 2007, 10:24
Up'n'Coming Member
Join Date: Aug 2007
Location: Bicester
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Why does this work?

Hi

I have some css like this:

<p span style="float:right;"><img src="pic.jpg" /><br /><span class="caption" >caption here</span><br /></p>
<p>Some text here</p>

[class 'caption' is just a font]

The result I get is the picture on the right and the text 'Some text here' on the left - which is what I want.

But i would have thought that the first <p> would put everything it contains in a block with no float. It seems the float is inherited upwards by its enclosing <p> which I didn't expect. Can anyone explain for me why this happens?


Thanks
Kropotkin
Reply With Quote

  #2 (permalink)  
Old Aug 6th, 2007, 10:33
SuperMember

SuperMember
Join Date: Apr 2007
Location: Ireland
Age: 15
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Pádraig
Re: Why does this work?

Can we have a link to the website? It helps to see the all of the code.
Reply With Quote
  #3 (permalink)  
Old Aug 6th, 2007, 10:52
Up'n'Coming Member
Join Date: Aug 2007
Location: Bicester
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why does this work?

Hi Pádraig

A bit difficult as this is a DVD but i've reproduced the problem here:
http://www.justinwyllie.net/css_problem.html

As I say it works but I'm interested to know why? do you know?

Cheers
Justin
Reply With Quote
  #4 (permalink)  
Old Aug 6th, 2007, 10:59
SuperMember

SuperMember
Join Date: Apr 2007
Location: Ireland
Age: 15
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Pádraig
Re: Why does this work?

I'm not sure I fully understand the problem, but as you have a "float: right" in both of the <span>'s, the text will obey that. I'm not sure that this will work in all browsers, though.
Reply With Quote
  #5 (permalink)  
Old Aug 6th, 2007, 11:04
SuperMember

SuperMember
Join Date: Sep 2006
Location: Pink House
Posts: 3,946
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why does this work?

Since the first p has a float right to it, it scooted the photo to the right.
Leaving blank space to the left of it. Anything following that photo will fill in the space on the left.
Reply With Quote
  #6 (permalink)  
Old Aug 6th, 2007, 11:58
Up'n'Coming Member
Join Date: Aug 2007
Location: Bicester
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why does this work?

Hi lchad

But my first p element doesn't have a float on it. If it did then fine - my question is about the fact that the float is on a child element of this p. In CSS does a float on a child element effect the parent element?

Thanks

Justin
Reply With Quote
  #7 (permalink)  
Old Aug 6th, 2007, 12:35
Up'n'Coming Member
Join Date: Aug 2007
Location: Bicester
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why does this work?

Pádraig.

btw i tried to view your web site and there was a problem, don't know if it is just my end or otherwise
Reply With Quote
  #8 (permalink)  
Old Aug 6th, 2007, 12:40
SuperMember

SuperMember
Join Date: Sep 2006
Location: Pink House
Posts: 3,946
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why does this work?

Whatever the last css is assigned to a particular "element" is what the browsers read. The last get's priority.

So the first p is getting ignored.
Reply With Quote
  #9 (permalink)  
Old Aug 6th, 2007, 12:41
SuperMember

SuperMember
Join Date: Apr 2007
Location: Ireland
Age: 15
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Pádraig
Re: Why does this work?

I'm moving to a new server. If I have to wait another day, I will have to look for another host!
Reply With Quote
  #10 (permalink)  
Old Aug 6th, 2007, 13:24
Up'n'Coming Member
Join Date: Aug 2007
Location: Bicester
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why does this work?

ok. thanks. Lchad. This must though be something to do with float - if I made the span color red but put text in the para outside the span that wouldn't be red. It seems that with boxes if an inner box sets a float or width (are these called something?) then if the parent element does not have its own set it will take its value from the child - as you say the parent is ignored.

I tested in safari, FF and IE so consident.
Reply With Quote
Reply

Tags
css

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript menu - does not work on title page, but does work on other pages Crystal Phoenix Starting Out 4 Mar 24th, 2008 19:40
my last work enesdanis Free Web Site Critique 8 Jan 14th, 2008 06:08
How does this work? Phixon JavaScript Forum 7 Sep 7th, 2007 14:40
simple js doesn't work with IE7 (work with FF1.5) gpazi JavaScript Forum 1 Jun 10th, 2007 11:00
Do you like where you work bigtester Webforumz Cafe 35 Jun 9th, 2007 03:24


All times are GMT. The time now is 02:54.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43