Teoom07 Asked:2022-07-31 21:56:29 +0800 CST2022-07-31 21:56:29 +0800 CST 2022-07-31 21:56:29 +0800 CST 父子块 772 情况如下: <div class="block"> <div class="parent"> <div class="child"></div> </div> </div> 有一个“块”元素,其宽度为浏览器窗口的 100%,还有一个“父”元素,其宽度固定,例如 1390px。在“父”内部应该存储一个“子”元素,其宽度为 15%,并且也像“块”一样从浏览器窗口缩放,而不是从“父”缩放。那么,如何实现这个问题呢? html css 1 个回答 Voted Best Answer soledar10 2022-07-31T22:41:28+08:002022-07-31T22:41:28+08:00 例子 * { box-sizing: border-box; } body { margin: 0; } .portfolio { background-color: #000; overflow-x: hidden; } .portfolio__container { max-width: 1390px; max-width: 390px; /* for test */ width: 100%; padding: 3rem 1rem; margin-left: auto; margin-right: auto; border: 1px solid #00f; } .portfolio__title { color: #fff; text-align: right; position: relative; } .portfolio__title::after { content: ''; position: absolute; top: 50%; left: calc(100% + 10px); width: 100vw; height: 1px; background-color: #fff; margin-top: -.5px; } <div class="portfolio"> <div class="portfolio__container"> <h2 class="portfolio__title">Portflio</h2> </div> </div>
例子