Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2013, 06:52 PM   PM User | #1
IanIan
New Coder

 
Join Date: Oct 2011
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
IanIan is an unknown quantity at this point
Does 'clear' apply to inline elements?

Code:
<style>

.style1  li { width:220px;
  float:left;
}


</style>

<ul class="style1">
	<li><input type="checkbox" value="1">Value</li>
<li><input type="checkbox" value="1">Value</li>
</ul>
<span style="clear: both;">Hello</span>
With the above code the span doesn't clear the list. But it does if I make it a block element.
IanIan is offline   Reply With Quote
Old 01-18-2013, 07:07 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Yes, clear doesn't apply to inline elements. Well, .. it does officially, but because of the way inline elements work it won't have the desired effect.

In the demonstration below the span element won't pop-up above the UL if there isn't enough room for it. Try increasing the width of the DIV to see the effect.

Code:
<!DOCTYPE html>
<html>
<head>
    <title>Page Title</title>
    <style type="text/css">
        .style1 {
            width: 100px;
            float:  left;
            outline: 1px solid blue;
        }
        div {
            width: 100px;
        }
    </style>
</head>

<body>
<div>
<ul class="style1">
	<li><input type="checkbox" value="1">Value</li>
<li><input type="checkbox" value="1">Value</li>
</ul>
<span style="clear: both;">Hello</span>
</div>

</body>
</html>
But you don't really want to do this; just use a block-level element (P or DIV).

Added: Actually, the clear:both has no effect on the in-line element. The W3 says you can apply it to in-line elements but it's ineffectual.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 01-18-2013 at 07:12 PM..
AndrewGSW is offline   Reply With Quote
Old 01-21-2013, 10:37 AM   PM User | #3
IanIan
New Coder

 
Join Date: Oct 2011
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
IanIan is an unknown quantity at this point
'Clear' on an inline element is allowed but it has no effect. Is there a theoretical explanation as to why it has no effect?

Last edited by IanIan; 01-21-2013 at 11:11 AM..
IanIan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 10:53 AM.


Advertisement
Log in to turn off these ads.