Search code examples
htmlcssinternet-explorer-7

IE7 display-block and width: auto


I've got a little problem and it's been bugging me for a little while, as much as i've tried, i couldn't or the life of me find a solution on here or through google that solved it. The problem itself only persists in IE7 ( i am unsure about IE6 but i would like to say that the result is somewhat similar to IE7)

Here is my mark up:

<div class="roomsLeft">
  <a href="#" class="selectProperty button">Select</a>
  <span>Only 3 rooms left!</span>
</div>

and here is the CSS for said mark up:

.roomsLeft{
    background:#fffed7;
    border-radius:5px;
    padding:1px;
    margin:15px 0 0 0;
    border:1px solid #ffd542;
    margin-right:-3px;
    width:auto;
    display:inline-block;}

.roomsLeft span{
    color:#555;
    font-size:0.7em;
    padding: 9px 8px 8px 8px;
    display:inline-block;
    width:auto;}

CSS for the button if it's needed:

.button {
    font-family:tahoma;
    background:#F70065;
    background:-moz-linear-gradient(top,#fb458f 0%,#F70065 100%);
    background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#fb458f),color-stop(100%,#F70065));
    background:-webkit-linear-gradient(top,#fb458f 0%,#F70065 100%);
    background:-o-linear-gradient(top,#fb458f 0%,#F70065 100%);
    background:-ms-linear-gradient(top,#fb458f 0%,#F70065 100%);
    background:linear-gradient(top,#fb458f 0%,#F70065 100%);
     /* For Internet Explorer 5.5 - 7 */ 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#fb458f, endColorstr=#F70065 ); 
    /* For Internet Explorer 8 */ 
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#fb458f, endColorstr=#F70065 )";
    padding:7px 9px;
    color:#fff;
    font-size:0.7em;
    border-radius:4px;
    -moz-border-radius:4px;
    -webkit-border-radius:4px;
    border:1px solid #DD005B;
    font-weight:800;
    text-decoration:none;
    letter-spacing:0em;
    text-shadow:1px 0px 5px #DD005B;
    box-shadow:inset 0px 1px rgba(255,255,255,0.2);}

.button:hover {
    background:#F70065;
    background:-moz-linear-gradient(top,#fb458f 0%,#F70065 100%);
    background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#fb458f),color-stop(100%,#F70065));
    background:-webkit-linear-gradient(top,#fb458f 0%,#F70065 100%);
    background:-o-linear-gradient(top,#fb458f 0%,#F70065 100%);
    background:-ms-linear-gradient(top,#fb458f 0%,#F70065 100%);
    background:linear-gradient(top,#fb458f 0%,#F70065 100%);
     /* For Internet Explorer 5.5 - 7 */ 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#fb458f, endColorstr=#F70065 ); 
    /* For Internet Explorer 8 */ 
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#fb458f, endColorstr=#F70065 )";
    padding:7px 9px;
    color:#fff;
    font-size:0.7em;
    border-radius:4px;
    -moz-border-radius:4px;
    -webkit-border-radius:4px;
    border:1px solid #DD005B;
    font-weight:800;
    text-decoration:none;
    letter-spacing:0em;
    text-shadow: 0 0 5px rgba(255,255,255,0.7);
    box-shadow:inset 0px 1px rgba(255,255,255,0.2), 0 0 5px rgba(247, 0, 101, 0.5);}

Here's a fiddle of what it looks like in all the other major browsers (IE8-10, Chrome, FF & Opera):

http://jsfiddle.net/vpF27/

the parents width only stretches to the combined width of it's children no matter the width of the parent container, however ... In strolls IE7 and his older brothers to wreck up the place and decides that

.roomsLeft

needs to fill the entire parent, any parent.

Now i've tried taking the culprit out of the context of my project (and away from any other items that might be interfering) and ran the css and html in a seperate file, hoping to narrow down any problems, but unfortunately this didn't solve anything, the problem still persists.

any help you guys can provide would be fantastic.

thank you.

EDIT: hopefully this fiddle gives a little bit more context of what's going on inside IE7. in all other browsers, adding

display:block;

to

.roomsLeft

solves the problem


Solution

  • Try this way:

    .button { display:inline-block; *display:inline; zoom:1;  /*float:right;*/ }
    

    JSFiddle

    Removing the float, changing it with display-inline-block; and switching the html placing of the element.