gpt4 book ai didi

html - CSS 在一行中拉伸(stretch)所有 div

转载 作者:太空宇宙 更新时间:2023-11-04 06:56:32 25 4
gpt4 key购买 nike

我有以下 HTML/CSS,我尝试拉伸(stretch) div 以使其内容适合。您可以在右边的列表中看到它,子项的大小扩展了父项的大小(这就是我添加 border 的原因)。所以我尝试将 align-items: stretch 添加到 container div,但这不起作用。
我可以将此规则添加到每个 div,但这会导致例如左侧变大,而右侧保持不变。我想避免这种情况,相反,我希望整行(div)在一个被拉伸(stretch)时被拉伸(stretch)。
我希望你明白我想要实现的目标。
我知道 CSS 相当大,但我发布了所有内容以确保我没有遗漏任何错误。

澄清:
当内容放不下时,我想最大化 div 的大小 当窗口大小变小时 (比如第一个左边的 div): 标题放在里面文本,因为没有剩余空间)

更新
刚刚注意到由于这个 CSS 属性,拉伸(stretch)有点困惑,我觉得细长是一个更好的术语。当内容不适合它们时,div 应该增长。

body {
margin:0;
}
.container {
display:flex;
flex-wrap:wrap;
height:100vh;
background-color: white;
}
.container > div {
min-height: 100vh;
border: 1px solid black;
box-sizing:border-box;
background-color: inherit;
}
.container > div > a > .dot{
position: relative;
transition: background .2s linear;
left: 50%;
bottom: 10%;
z-index: 101;
height: 25px;
width: 25px;
background-color: white;
border-radius: 50%;
display: inline-block;
}
.container > div > a > .dot > .arrow-down {
transition: border .2s linear;
position: absolute;
top:11%;
left: 24%;
border: solid black;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 5px;
}
.container > div > a .dot:hover{
background: black;
}
.container > div > a .dot:hover > .arrow-down{
border: solid white;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 5px;
}
.container > div > a > .dot > .arrow-down{
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}

.container > div .content{
height: 100vh;
width: 100vw;
background-color: inherit;
}
.full-width {
width:100%;
}
.half-width {
width:50%;
}

.video-iframe.fullsize{
height: 100%;
width: 100%;
}

.list{
text-align: center;
}

.half-width > .half-width-content{
position: relative;
margin-top: 0;
height: 100%;
width: 100%;
}
.half-width > .half-width-content > .instagram-slideshow{
position: relative;
height: 100%;
width: 100%;
}
.half-width > .half-width-content > .instagram-slideshow > img{
position: absolute;
width: 60%;
height: 60%;
left: 50%;
top:50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}

.half-width > .half-width-content > .half-width-text {
position: absolute;
left: 50%;
top: 50%;
visibility: visible;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.half-width > .half-width-content > h1{
position: relative;
text-align: center;
top: 15%;
}

.half-width-text > .middle-text{
margin-left: -30px;
}

.list-div {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}

.list-div ul {
padding: 0;
width: 75%;

}

.list-div li {
position: relative;
display: block;
margin-bottom: 5px;
padding: 10px;
text-align: left;
visibility: visible;
text-transform: uppercase;
}


.full-width > .content > .third-parent{
height: 100%;
display: flex;
}

.full-width > .content > .third-parent > .third{
position: relative;
flex: 1 1 0px;

width: 100%;
}

.full-width > .content > .third-parent > .third > img{
position: absolute;
width: 100%;
height: auto;
left: 50%;
top:50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}

.middle-text{
position: absolute;
width: 100%;
left: 50%;
top:50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}

.full-width > .content > .third-parent > .third > .middle-text > .list-div2{
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}

.full-width > .content > .third-parent > .third > .middle-text > .list-div2 li{
position: relative;
display: block;
border: 1px solid red;
margin-bottom: 5px;
padding: 10px;
text-align: left;
text-transform: uppercase;
visibility: visible;
}

.list-div2 li::before{
content: '\2022';
margin-right: 10px;
}
.items-list2 {
margin: 0;
padding: 0;
}
<div class="container">
<div class="full-width">
<iframe class="video-iframe fullsize" src="https://www.youtube.com/embed/osg9PmkfTB0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
<a href="#section2">
<span class="dot">
<i class="arrow-down"></i>
</span>
</a>
</div>
<div class="half-width" id="section2">
<div class="half-width-content">
<h1>Headline</h1>
<div class="half-width-text">
<div class="text-content">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</p>
</div>
</div>
</div>
</div>
<div class="half-width">
<div class="half-width-content">
<div class="instagram-slideshow" id="1">
<img class="slide" src="http://placekitten.com/200/300">
<img class="slide" src="https://placeimg.com/640/480/animals">
<img class="slide" src="http://placekitten.com/200/300">
</div>
</div>
</div>
<div class="half-width">
<div class="half-width-content">
<div class="instagram-slideshow" id="2">
<img class="slide" src="https://fakeimg.pl/350x200/?text=Hello">
<img class="slide" src="https://fakeimg.pl/350x200/?text=Bye">
<img class="slide" src="https://fakeimg.pl/350x200/?text=BLA">
</div>
</div>
</div>
<div class="half-width">
<div class="half-width-content">
<div class="middle-text">
<h2>Headline</h2>
<p>
This is some text paragraph
</p>
<div class="list-div">
<ul class="items-list" id="list">
<li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr</li>
<li>sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam </li>
<li>sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</li>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
</ul>
</div>
</div>
</div>
</div>
<div class="full-width">
<div class="content">
<div class="third-parent">
<div class="third" id="one">
<img src="https://fakeimg.pl/350x200/?text=right">
</div>
<div class="third" id="two">
<div class="middle-text">
<h1>Headline</h1>
<div class="list-div2">
<ul class="items-list2" id="list">
<li>Entry A</li>
<li>Entry B</li>
<li>Entry C</li>
<li>Entry D</li>
</ul>
</div>
</div>
</div>
<div class="third" id="three">
<img src="https://fakeimg.pl/350x200/?text=left">
</div>
</div>
</div>
</div>
</div>

最佳答案

我想我知道你想要什么。您正在使用 lefttoptransform: translate(-50%, -50%);那就是你犯错误的地方。

我已经评论了不需要的 CSS 并添加了备用 .. 请检查下面。

body {
margin:0;
}
.container {
display:flex;
flex-wrap:wrap;
height:100vh;
background-color: white;
}
.container > div {
min-height: 100vh;
border: 1px solid black;
box-sizing:border-box;
background-color: inherit;
}
.container > div > a > .dot{
position: relative;
transition: background .2s linear;
left: 50%;
bottom: 10%;
z-index: 101;
height: 25px;
width: 25px;
background-color: white;
border-radius: 50%;
display: inline-block;
}
.container > div > a > .dot > .arrow-down {
transition: border .2s linear;
position: absolute;
top:11%;
left: 24%;
border: solid black;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 5px;
}
.container > div > a .dot:hover{
background: black;
}
.container > div > a .dot:hover > .arrow-down{
border: solid white;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 5px;
}
.container > div > a > .dot > .arrow-down{
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}

.container > div .content{
height: 100vh;
width: 100vw;
background-color: inherit;
}
.full-width {
width:100%;
position:relative;
}
.half-width {
width:50%;
position:relative;
overflow: auto
}

.video-iframe.fullsize{
height: 100%;
width: 100%;
}

.list{
text-align: center;
}

.half-width > .half-width-content{
position: relative;
margin-top: 0;
height: 100%;
width: 100%;
}
.half-width > .half-width-content > .instagram-slideshow{
position: relative;
height: 100%;
width: 100%;
}
.half-width > .half-width-content > .instagram-slideshow > img{
position: absolute;
width: 60%;
height: 60%;
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
/*left: 50%;
top:50%;*/
visibility: visible;
text-align: center;
/*-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
}

.half-width > .half-width-content > .half-width-text {
/*position: absolute;
left: 50%;
top: 50%;*/
visibility: visible;
/*-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
padding-left: 50px;
padding-right: 50px;
}
.half-width#section2 > .half-width-content, .half-width#section3 > .half-width-content {
display: flex;
flex-direction: column;
justify-content: center;
}

.half-width > .half-width-content > h1{
position: relative;
text-align: center;
/*top: 15%;*/
}

.half-width-text > .middle-text{
margin-left: -30px;
}

.list-div {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}

.list-div ul {
padding: 0;
width: 75%;

}

.list-div li {
position: relative;
display: block;
margin-bottom: 5px;
padding: 10px;
text-align: center;
visibility: visible;
text-transform: uppercase;
}


.full-width > .content > .third-parent{
height: 100%;
display: flex;
}

.full-width > .content > .third-parent > .third{
position: relative;
flex: 1 1 0px;

width: 100%;
display: flex;
align-items: center;
align-content: center;
justify-content: center;
}

.full-width > .content > .third-parent > .third > img{
position: absolute;
width: 100%;
height: auto;
left: 50%;
top:50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}

.middle-text{
/*position: absolute;
width: 100%;
left: 50%;
top:50%;*/
visibility: visible;
text-align: center;
/*-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);*/
}

.full-width > .content > .third-parent > .third > .middle-text > .list-div2{
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}

.full-width > .content > .third-parent > .third > .middle-text > .list-div2 li{
position: relative;
display: block;
border: 1px solid red;
margin-bottom: 5px;
padding: 10px;
text-align: center;
text-transform: uppercase;
visibility: visible;
}

.list-div2 li::before{
content: '\2022';
margin-right: 10px;
}
.items-list2 {
margin: 0;
padding: 0;
}
<div class="container">
<div class="full-width">
<iframe class="video-iframe fullsize" src="https://www.youtube.com/embed/osg9PmkfTB0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
<a href="#section2">
<span class="dot">
<i class="arrow-down"></i>
</span>
</a>
</div>
<div class="half-width" id="section2">
<div class="half-width-content">
<h1>Headline</h1>
<div class="half-width-text">
<div class="text-content">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
</div>
</div>
</div>
<div class="half-width">
<div class="half-width-content">
<div class="instagram-slideshow" id="1">
<img class="slide" src="http://placekitten.com/200/300">
<img class="slide" src="https://placeimg.com/640/480/animals">
<img class="slide" src="http://placekitten.com/200/300">
</div>
</div>
</div>
<div class="half-width">
<div class="half-width-content">
<div class="instagram-slideshow" id="2">
<img class="slide" src="https://fakeimg.pl/350x200/?text=Hello">
<img class="slide" src="https://fakeimg.pl/350x200/?text=Bye">
<img class="slide" src="https://fakeimg.pl/350x200/?text=BLA">
</div>
</div>
</div>
<div class="half-width" id="section3">
<div class="half-width-content">
<div class="middle-text">
<h2>Headline</h2>
<p>
This is some text paragraph
</p>
<div class="list-div">
<ul class="items-list" id="list">
<li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr</li>
<li>sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam </li>
<li>sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</li>
<li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
</ul>
</div>
</div>
</div>
</div>
<div class="full-width" id="section4">
<div class="content">
<div class="third-parent">
<div class="third" id="one">
<img src="https://fakeimg.pl/350x200/?text=right">
</div>
<div class="third" id="two">
<div class="middle-text">
<h1>Headline</h1>
<div class="list-div2">
<ul class="items-list2" id="list">
<li>Entry A</li>
<li>Entry B</li>
<li>Entry C</li>
<li>Entry D</li>
</ul>
</div>
</div>
</div>
<div class="third" id="three">
<img src="https://fakeimg.pl/350x200/?text=left">
</div>
</div>
</div>
</div>
</div>

您也可以在这里进行测试。 https://jsfiddle.net/nimittshah/gda5f643/36/

关于html - CSS 在一行中拉伸(stretch)所有 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52407204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com