Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

float: right in IE7 dropping to a new line

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.

like image 891
CoreyT Avatar asked Jan 25 '11 18:01

CoreyT


3 Answers

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

like image 196
oryol Avatar answered Nov 12 '22 12:11

oryol


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.

like image 26
Tom Greever Avatar answered Nov 12 '22 13:11

Tom Greever


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;
  }
like image 38
Jeff Avatar answered Nov 12 '22 13:11

Jeff