sách gpt4 ai đã đi

Phần tử float của Firefox yêu cầu DOM poke

In lại 作者:可可西里 更新时间:2023-11-01 14:50:20 32 4
mua khóa gpt4 Nike

我有两个向左浮动的元素。一个是 body 的第一个 child ,另一个是容器的第一个 child ,容器是 body 的第二个 child 。

...







...

容器具有固定宽度并使用“margin: 0 auto;”居中。目的是让容器 child 留在左边,但在窗口较小时容纳 body child 。

fiddle 在这里:

http://jsfiddle.net/mrSav/7/

此解决方案在 Chrome 中运行良好;您会注意到,当您缩小窗口时,container child 会愉快地移到 body child 身边。

但是在 Firefox 中,当您缩小窗口时,容器子项会与主体子项重叠。

我为这两个 child 添加了一个悬停状态,它有效地“戳 DOM”并强制 Firefox 重新流动页面。当您将鼠标悬停在子项上时,页面会自行更正并且子项会进入“正确”位置。

这是一个错误吗?有解决方法吗?

1 Câu trả lời

làm mới - 容器确实在 body 的第一个 child 下面流动仍在使用媒体查询,但更改了一些内容以允许容器子项相对于窗口而不是父项进行绝对定位: DEMO

从容器中移除position: relative。将两个 đứa trẻ div css 分开,并像这样在容器子上更改一些样式:

.child {
width: 100px;
chiều cao: 200px;
background-color: white;
border: 2px dashed black;
margin: 0px;
}

body > .child {
float: bên trái;
z-index: 1;
}

.container > .child {
position: absolute; //relative to window since parent has no position
left: 100px;
}

然后在 700px 以上使用 media-query 将 position 改为 relative,left 改为 auto:

@media screen and (min-width: 700px) {
.container > .child {
position: relative; //override absolute position
left: auto; //override left: 100px
}
}

原创 - 容器不会在 body 的第一个 child 下面流动。我不知道是什么原因造成的(我猜这是从流中取出的一个 float 项,Firefox 对其进行了不同的处理),但这里有一个使用媒体查询的解决方法: DEMO

对于固定宽度,你可以这样做:

.container { //use margin-left: 100px until the total width of the window is 700px (500px + 100px + 100px = container width + 100px on either side )
margin: 0 0 0 100px;
}

@media screen and (min-width: 700px) { //700px to account for 100px of left div (.container is centered at this size)
.container {
margin: 0 auto;
float: none;
}
}

我还会添加 * {box-sizing: border-box;}(带有适当的前缀、-moz-、-webkit-)来说明任何边框/填充。

关于html - Firefox float 元素需要 DOM 戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20689775/

32 4 0
可可西里
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com