我想用div div扩展div父级,但我不知道这是否可能以及如何做到这一点.
我准备一个小提琴,并包括一些代码.
CSS
body {
background: gray;
}
div.page {
color: white;
background: black;
max-width: 72em;
margin: auto;
padding: 1em;
}
div.one {
background-color: red;
width: 40%;
}
div.two {
background-color: green;
width: 120%;
}
Run Code Online (Sandbox Code Playgroud)
HTML
<body>
<div class="page">
<div class="one">One</div>
<div class="two">Two</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
bot*_*bot 37
您的问题的关键解决方案是使用display:inline-block;
HTML
<div class="page">
<div class="one">One</div>
<div class="two">Two</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
body {
background: gray;
}
div.page {
color: white;
background: black;
margin: auto;
padding: 1em;
display:inline-block;
}
div.one {
background-color: red;
width: 10em;
display:inline-block;
}
div.two {
background-color: green;
width: 40em;
display:inline-block;
}
Run Code Online (Sandbox Code Playgroud)
这是工作小提琴
You cannot use % and expect box to overflow, else it never ends 100% turns 120%, but then 120% of 120%, becomes .. and so on. forget this idea, it cannot work.
Your CSS request is incoherent.
Beside, to see an element to grow wider than window, one of the parent must be able to behave this way, mostly , content overflow and remain visible. (html/body or parent)
as far as i know only:
display:
Run Code Online (Sandbox Code Playgroud)
table
inline-table
table-row
table-cell
Can let container grow as much as content does.
归档时间: |
|
查看次数: |
46487 次 |
最近记录: |