gpt4 book ai didi

html - 当主
包装器中有第二个
时,自动调整
图像的大小

转载 作者:可可西里 更新时间:2023-11-01 13:31:00 25 4
gpt4 key购买 nike

我有一个 .well.carousel在里面我有两个 <div> ,一个是图片,一个是标题文字。我设法自动调整图像大小,但是当我降低 .well.carousel 的高度时然后标题文本落在 .well.carousel 之外.如何调整图像大小,使标题文本也包含在 .well.carousel 中当我的高度是 150px 时?

例如附Fiddle

  1. .well.carousel的高度为 150px,标题文本落在井外。
  2. 当我将高度更改为 300 像素时,标题文本落在井内(即使图像高度为 1300 像素!)。我不明白这一点。
  3. 如果我更改 .well.carousel 的宽度从 400 像素到 100 像素,您可以看到图像按比例缩小。但是,如果我将宽度保持在 400px,但仅将高度从 400px 更改为 100px,则图像不会发生任何变化。在这里我也希望它按比例缩小,就像您只更改宽度时一样。

HTML:

<div class="well carousel">
<div class="image">
<a href="placehold.it"><img alt="art-1" src=
"http://placehold.it/1400x1300"></a></div>

<div class="title">
<a href="">title titletitle titletitle titletitle titletitle title</a>
</div>
</div>

CSS:

.well.carousel {
height:150px;
width:100px;
border:5px solid #000000;
}

.title {
font-size:24px;
font-weight:bold;
color:#333333;
background-color:#FFF700;
}

.image {
padding-bottom:5px
}

.image img {
max-width:100%;
max-height:100%;
margin:auto;
display:block
}

最佳答案

在容器上使用display:flexflex-flow:column,然后设置overflow:autoflex:1 在文本包装器上,flex: 2 在图像包装器上

( Demo )

.well.carousel {
display: flex;
flex-flow: column;
height: 150px;
width: 100px;
border: 5px solid #000000;
}
.title {
overflow: auto;
font-size: 24px;
font-weight: bold;
color: #333333;
background-color: #FFF700;
flex: 1;
}
.image {
flex: 2;
padding-bottom: 5px;
height: 100px;
}
.image img {
width: 100%;
display: block
}
<div class="well carousel">
<div class="image">
<a href="placehold.it">
<img alt="art-1" src="http://placehold.it/1400x1300">
</a>
</div>

<div class="title">
<a href="">title titletitle titletitle titletitle titletitle title</a>
</div>
</div>

关于html - 当主 <div> 包装器中有第二个 <div> 时,自动调整 <div> 图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30059968/

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