2

I have two divs that are inline. they both have similar styles and importantly both are inline.

JQuery is reporting that their css "display" is block ONLY in chrome. I really need to know that these two are inline.

jsfiddle here

css:

div
{
    display: inline;
    width: 50%;
    float: left;
    height: 100px;
    text-align: center;
    font-weight: bold;
    padding: 10px;
    box-sizing: border-box;
}
.div1
{
    background-color: black;
    color: white;
    border: 2px solid grey;
}

.div2
{
    background-color: white;
    color: black;
    border: 2px solid black;
}

html:

<div class="div1">1</div>
<div class="div2">2</div>

jQuery:

jQuery("div").click(function()
{
    jQuery(this).append("<br/><span>" + jQuery(this).css("display") + "</span>");
});

jQuery("div").click();

Does anyone know what is happening or more importantly what can I do? (other than pull my hair out... its starting to hurt ;) )

thirtydot
  • 224,678
  • 48
  • 389
  • 349
James Khoury
  • 21,330
  • 4
  • 34
  • 65
  • 3
    Are you aware that `float: left` forces `display: block`? `display: inline` isn't doing anything. Remove it if you don't believe me. – thirtydot May 02 '11 at 07:19
  • Doh! put it in an answer and i'll mark it correct. Also where would i find this information? w3c? – James Khoury May 02 '11 at 07:20
  • Yes, [W3C](http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo). (Edit: Sorry, didn't update to see the answer posted below containing the exact same link :( ) – jensgram May 02 '11 at 07:28

1 Answers1

8

As I said in my comment, float: left forces display: block.

Here's the relevant information in the spec:

http://www.w3.org/TR/CSS21/visuren.html#propdef-float

The element generates a block box that is floated to the left.

And then:

http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo

Otherwise, if 'float' has a value other than 'none', the box is floated and 'display' is set according to the table below.

To summarize said table: float = display: block.

thirtydot
  • 224,678
  • 48
  • 389
  • 349