CSS float div 固定边距顶部

标签 css css-float html

如何修复 float 的 div?我试过 margin-top

<div id="headerRightContent" style="float: left; height: 100px; margin-top: 105px; width: 1px; whitespace: no-wrap;background-lightyellow;margin:0px 10px 10px 12px;color: #FF00FF;border: 1px dashed black;width: 175px;padding-left:6px;padding-bottom:6px;padding-top:6px;">

但没有做任何事情,所以我添加了更多内容左侧的div向下 float 并删除了 float 向上的内容...

这里是 demo

最佳答案

两个问题。

问题 1:您包含的 td 正在从某处继承 vertical-align:middle。您需要删除它或使用 vertical-align:top 覆盖它。

<td style="vertical-align:top;"> 

问题 2:您在 div 上设置了两次边距样式,实质上是删除了您的 margin-top 设置。合并它们或删除第二个。

<div id="headerRightContent" style="float: left; height: 100px; margin:105px 10px 10px 12px; width: 1px; whitespace: no-wrap;background-lightyellow;color: #FF00FF;border: 1px dashed black;width: 175px;padding-left:6px;padding-bottom:6px;padding-top:6px;">

此外,我强烈建议将内联样式放入外部样式表中。

fiddle :http://jsfiddle.net/Vmjmz/3/

关于CSS float div 固定边距顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16181044/

相关文章:

javascript - 在 <p> 元素中插入 <span>

HTML5 表单不适用于其他较低版本的浏览器

javascript - 为什么iOS手机不能使用focus()

javascript - 把图标变成黑白

html - IE10 CSS动画问题

javascript - 如何等待所有动画在 jQuery 中完成?

html - 使用 float :left 时 CSS 背景消失

css - 调整窗口大小时 float ul 的 li 不保持内联

html - 使用 CSS,如何在两个 float div 之间堆叠两个跨度?

javascript - 将按钮链接到另一个页面的一部分