float: right in IE7 dropping to a new line

17,290

Solution 1

Try to small change markup: place items with a float before items without it (from the same row). It should help.

Solution 2

I know it's been a long time since this was posted, but I found a solution that I like for this. The gist is using 'expression' tag in your CSS for IE7 only to move the floated element to be the first element of the parent in the DOM. It will be semantically correct for all other browsers, but for IE7 we modify the DOM to move the floated element.

In my case, I have:

<div>
    <h1></h1>...<p>any other content...</p>
    <small class="pull-right"></small>
</div>

In my CSS for pull-right, I use:

.pull-right {
    float:right;
    *zoom: ~"expression( this.runtimeStyle.zoom='1',parentNode.insertBefore( this,parentNode.firstChild ))";
}

The result is that IE7 moves my <small> to be the first element of <div> but all other browsers leave the markup alone.

This might not work for everyone. Technically, it is modifying the markup but only in the DOM for IE7 and it's also a javascript solution.

Also, I understand there may be some performance issues with expression (it's slow), so perhaps it's not ideal there are a lot of floats like this. In my case, it worked well and allowed me to keep semantically correct HTML.

Solution 3

If you float your .formText left, float your span.required left, and then float your inputs left as well you should be able to line them up on the same line.

I'd modify your markup a bit. your <span class="formText"> should really be a <label>

For example:

<P class=formRow>
<label for="FirstName">First Name<SPAN style="FLOAT: left" class=required>*</SPAN></label>
<INPUT id=FirstName class=formTextbox name=FirstName> 
</P>

and your css would be something like this:

.formRow {
  clear: both;
}
  .formRow label {
     float: left;
     width: 150px;
  }
  .formRow input {
     float: left;
  }
Share:
17,290

Related videos on Youtube

CoreyT
Author by

CoreyT

I code, sometimes well other times not so much.

Updated on July 13, 2020

Comments

  • CoreyT
    CoreyT over 3 years

    I've been stuck on a float issue for a little while so I am hoping the community can help me again. I have a new webform here. As usual it looks fine in everything but IE7 (or IE8 in compatibility).

    For some reason some of the containers are ending up with the form field on a new line below the form text. CSS is not my strong point, otherwise I'd be able to fix this I am sure. Can anyone tell me what I am missing here?

    I tried adding float: left to the form text but that ended up with a whole other mess.

  • Jeff Sheldon
    Jeff Sheldon almost 12 years
    This helped me today, what a simple fix. Thanks!
  • oryol
    oryol over 11 years
    Id depends.. But if we need to display page correctly in the IE we can't have ideal semantic. It's IE :)
  • Riveascore
    Riveascore over 10 years
    Gotta say, I've seen "solutions" to this problem everywhere. None of them worked except this one, well played and thank you :D
  • carbontwelve
    carbontwelve about 9 years
    We have to support IE6 due to certain government sectors still relying upon it and this really saved me; I spent ages trying to fix this before stumbling upon your answer. Thank you.

Related