float: right in IE7 dropping to a new line

霸气de小男生 提交于 2019-11-28 20:25:23

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

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.

Jeff

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;
  }

You could try to make the span tags you have for the text a fixed width, float them left, and do the same for the input field you want to correspond with. I'd also recommend using a label tag instead of a span tag on forms. No real solid reason for it, it's just that a label was meant for exactly what you have the span tag doing.

What you want to do is add a clear:both as the last sibling of your floated elements.

So something like:

<div style="float:left;">
  <!-- children of div here -->
</div>
<div style="clear:both;">
  <!-- leave empty -->
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!