1

I'm trying to set two div elements to inline but its not working as expected

fiddle

html

<div id="id1"></div>
<div id="id2"></div>

css

#id1{
    background-color:blue;
    display:inline;

    height:100px;
    width:200px;
}
#id2{
    background-color:green;
    display:inline;

    height:100px;
    width:200px;
}
1
  • 1
    Inline elements dont have height. What is not working as expected? Commented Dec 30, 2013 at 21:51

4 Answers 4

3

You cannot specify width/height for inline elements..

Use inline-block instead

display:inline-block;

Demo at http://jsfiddle.net/gaby/CGHZ5/2/


And if indeed you want identical boxes which only differ in color, then use a class for the common properties..

<div id="id1" class="item"></div>
<div id="id2" class="item"></div>

and

.item{
    height:100px;
    width:200px;
    display:inline-block;
}
#id1{background-color:blue;}
#id2{background-color:green;}

Demo at http://jsfiddle.net/gaby/CGHZ5/4/

Sign up to request clarification or add additional context in comments.

Comments

0

I think you're looking for display: inline-block;

Comments

0

inline elements cannot have defined height or width, they take the height and width of their contents.

Just change all of your inline references to inline-block like so:

#id1{
    background-color:blue;
    display:inline-block;
    height:100px;
    width:200px;
}
#id2{
    background-color:green;
    display:inline-block;
    height:100px;
    width:200px;
}

Comments

0

Setting the width of a display:inline will not work, it just won't display. Use display:inline-block instead, although that has some legacy browser issues

Use this code instead

#id1{
    background-color:blue;
    display:inline-block;
    height:100px;
    width:200px;
}
#id2{
    background-color:green;
    display:inline-block;
    height:100px;
    width:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.