【发布时间】:2018-12-19 00:27:49
【问题描述】:
This image describes the story. I want to make purple div same as green div . 有人可以解释一下如何在父级的边距和填充未知的情况下使子级 div 全宽吗?
<div class="parent">
<div class="child1">
</div>
<div class="child2">
</div>
</div>
我主要是坚持调整子 div 的边距和内边距。
注意:父 div 的宽度是边距和内边距未知 plz checkout the image red portion is parent and purple color is child, I want the purpule portion come out and take the full width of viewport
【问题讨论】:
-
取决于您想要实现的目标。
position: fixed将 div 设置为相对于主体,而不是父级,这可能会有所帮助。其他尝试使您的最终结果更清晰(屏幕截图或示例),因为现在很难理解您需要什么。 -
@elveti 感谢您的回复。我添加了一张图片,你可以看看link这里红色是父div,紫色和绿色是孩子。我想让紫色 div 和绿色 div 一样。