html - div 外的段落改变了 div 内段落的位置

标签 html css

我得到了以下 html:

<div id="noiseCanvasDiv">
            <p>Noise</p>
            <canvas id="noiseCanvas" ></canvas>
        </div>
        <div id="noiseLegend">
            <p class="legendOne">Blue Sensor</p><p class="legendTwo">Grey Sensor</p>
        </div>
        <div id="lightCanvasDiv">
            <p>Light</p>
            <canvas id="lightCanvas"></canvas>
        </div>
...
</div>

对应的css:

baseCanvas,
#noiseCanvas,
#lightCanvas,
#activityCanvas {
    position: relative;
    height: 150px;
    width: 310px;
    padding-left: 5px;
}

#noiseCanvas {
    padding-top: 5px;
}

#activityCanvas {
    float: left;
}

#noiseLegend {
    position: relative;
    float: right;
    margin-top: -10px;
}

legendBaseclass,
.legendOne,
.legendTwo {
    display: inline;
    font-size: 10pt;
    font-weight: normal;
    padding-top: 0px;
    margin-top: 0px;
    margin-bottom: 0px;
}

段落 Light 应该像 Noise 一样显示在页面中间。但是只要我添加 noiseLegend 它就会被推到左边。这怎么可能,因为它被 lightCanvasDiv 包围了?

enter image description here

最佳答案

来自评论:

I'm guessing "Blue SensorGrey Sensor" does float: right;. Include a clearfix or make it a non floating block element with text-algin: right; or wrap it.

关于html - div 外的段落改变了 div 内段落的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33011711/

相关文章:

html - 如何调试tabindex

html - Bootstrap,无论 html 布局如何,都允许内容响应/灵活

javascript - 使用 Firebase 为 Web 应用创建房间

python - 在 Python 中,如何删除 HTML 片段中的 "root"标记?

css - W3C 有效的 XHTML 和 CSS 代码、语义和可访问标记是否足以用于网站的一般搜索引擎优化?

html - 如何增加 v-if 显示的值?

css - 禁止应用任何 :hover, :focus 和 :active css

css - 使用 Cufon 有什么缺点? sIFR 仍然是不错的选择吗? @font-face 不会使字母像使用 cufon 或 sIFR 时那样平滑

javascript - 在导航图标 css 下包装文本

html - 如何给 div 一个响应高度