cuốn sách gpt4 ai đã làm

css - 如何设置Div(绝对)宽度100%

In lại Tác giả: Walker 123 更新时间:2023-11-28 17:05:42 30 4
mua khóa gpt4 Nike

当它的位置绝对时,我试图使一个框宽度为 100%?

下图是我想要做的

../../../qMaT361.gif



trôi nổi



.box1 { position:relative; width:500px; height:100px; margin:0 auto; overflow:visible; background:#f1f1f1;}
.box2 { position:absolute; top:10px; right:0; left:0; width:100%; height:50px; background:red; }

Thử nghiệm:https://jsfiddle.net/otkg9nfh/8/

请帮忙~

câu trả lời hay nhất

当一个 div 设置为绝对位置时,该 div 将采用父 div 设置的边界(相对位置)。如果您想使 div 100% 占据浏览器屏幕,则必须将 div 位置固定为 tuyệt đối

.box1 { position:relative; width:500px; height:100px; margin:0 auto; overflow:visible; background:#f1f1f1;}
.box2 { position:fixed; top:10px; left:0; right:0; width:100%; height:50px; background:red; }


trôi nổi

.

关于css - 如何设置Div(绝对)宽度100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49725842/

30 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress