以像素为单位浮动DIV,以百分比表示DIV(响应式设计)。无法弄清楚

时间:2016-08-04 16:44:54

标签: html css

我将 DIV以像素 DIV以百分比浮动。哪个工作得很好。

但是每当我使用清除:百分比DIV 内部其他内容都会跳转。但我必须在其中使用 clear:both ,因为我在里面浮动另一个DIV。

<div style="width: 100%;">

    <div style="width: 100px; height: 200px; background: blue; float: left;"></div>
    <div style="background: green;">
        aaa
        <div style="clear: both"></div>
        aaa
    </div>
</div>
  • 我尝试按位置浮动它:绝对。但这会破坏我网络的其余部分。
  • 我不确定使用calc()(并非所有浏览器都支持)
  • 没有javascript
  • 我没有任何其他想法

1 个答案:

答案 0 :(得分:0)

Clear:both 不允许任何div在右侧或左侧浮动。 尝试提供height财产。

所需的输出不清楚。

编辑:

使用

<a href="<?php echo 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>"><img src="images/logo.png"></a>

使用&#39; &#39; (单引号)而不是&#34; &#34;在回声之后/将结束它。

编辑2:

<div style="width: 100%;">

<div style="width: 100px; height: 200px; background: blue; float: left;"></div>
<div style="background: green;width:100%;">
    <div style="background-color:red;width:100px;float:left;">
        Product 1
        <div style="">
            Header
        </div>
    </div>
    <div style="background-color:red;width:100px;float:left;">
        Product 2
        <div style="">
            Header
        </div>
    </div>
</div>