考虑this HTML example个(如下所示的最小示例):

<p><svg style="float: left" width="300" height="300"><circle cx="150" cy="150" r="150" style="fill: red"
/></svg>First float here.</p>
<p><svg style="float: left; clear: left" width="300" height="300"><circle cx="150" cy="150" r="150" style="fill: green"
/></svg>Second float here.</p>
<p><svg style="float: right" width="300" height="300"><circle cx="150" cy="150" r="150" style="fill: blue"
/></svg>Third float here.</p>

我们有一些嵌入了三个浮点数的文本:

  1. 左边的浮动(红色圆圈),

  2. 另一个左边的浮点(绿色圆圈),这个有clear: left的浮点确保它低于第一个浮点,

  3. 右浮动(蓝色圆圈).

desired effect用于使右侧浮点完全独立于左侧浮点,即右侧浮点位于其插入位置的右侧(假设线条足够长,可以同时存在左侧浮点和右侧浮点,否则位于左侧浮点下方).actual effect是将右浮点数推到第一个左浮点数的下方,因为第二个左浮点数上的clear: left指令也会将右浮点数向下推.

简而言之,左侧浮点数为clear: left也会影响右侧浮点数.

Two questions:

  • 在css规范中,这个行为是在哪里指定的?(右浮点没有设置任何clear属性,所以我不明白规范的哪个部分暗示它受到前一个左浮点的clear的影响.)我还对基本逻辑感兴趣:why我们希望右浮点受到左浮点上的clear: left个属性的影响吗?

  • 更重要的是,我如何才能产生想要的效果(没有任何Java脚本)?

推荐答案

To answer your first question:
The documentation specifies this:
9.5.1 5.The outer top of a floating box may not be higher than the outer top of any block or floated box generated by an element earlier in the source document.
This means the top of your Blue float can't be higher than the top of your Green float.

To answer your second question:
There are a few ways of achieving this without js by changing the html structure, but none I can think are exactly what you want. For example you could wrap the red and green floats inside the same container and make it float left. The blue float will be in the position you want. However, in very small screens the text won't wrap beteen the red and green floats like the are doing at they moment.

Css相关问答推荐

在COLOR-MIX()中使用var()似乎会使其对于不支持COLOR-MIX()的浏览器具有可读性,从而阻止了回退的工作

Vue3日期 Select 器:作用域样式不起作用

在NextJS/Reaction应用程序中显示更新问题

使用 Flex 容器,如何在右对齐所有 Flex 子项的同时赋予子图像完整宽度?

如何在一个父类里面 Select 两个不同的类?

如何使用props 为 Vue 中的组件创建动态背景图像?

如何在悬停另一个部分的元素时使元素可见?

每当键盘在react native 中打开时,如何使用 KeyboardAvoidingView 删除图像?

CSS 字符串变量的正确null值是多少?

父母是内联块,子元素有%填充=奇怪的行为

Flexbox 子高度它的内容

调整屏幕大小时无法让我的视频背景保持不变

如何将 .btn-group 从 twitter-bootstrap 居中?

绝对位置和溢出:隐藏

ID 在整个页面中必须是唯一的吗?

媒体查询以错误的宽度触发

水平列表项

让 div 占据 100% 身体高度,减go 固定高度的页眉和页脚

如果容器 div 较小,如何将子 div 扩展到 100% 屏幕宽度?

在 CSS 中使用多个 @font-face 规则