【发布时间】:2020-01-26 18:20:06
【问题描述】:
有一个 div,里面有一张图片和一些文字。包含的 div 没有特定的高度,并且取决于 div 中的文本。
我正在为图像使用以下 css 并包含 div:
.Image{
float: left;
width: auto;
max-height: 70%;
margin-right: 1em;
border: 0;
}
.DivBlock{
display: block;
width: 100%;
}
但是,由于 div 没有指定高度,因此图像高度不会根据外部 div 进行调整。如何调整它以使其仅为包含 div 高度的 70%?
在下面找到整个代码:
.Image{
float: left;
width: auto;
max-height: 70%;
margin-right: 1em;
border: 0;
}
.DivBlock{
display: block;
width: 100%;
}
<h3>History:</h3>
<div class="DivBlock">
<img class="Image" src="https://cdn.pixabay.com/photo/2015/10/09/00/55/lotus-978659__340.jpg" />
<p>Matheran was identified by Hugh Poyntz Malet, the then district collector of Thane district in May 1850. Lord Elphinstone, the then Governor of Bombay laid the foundations of the development as a future hill station. The British developed Matheran as a resort to beat the summer heat in the region.</p>
<p>Matheran is the birthplace of freedom fighter Veer Bhai Kotwal. He was born on 1 December 1912 in a Barber family. The state government has built a monument in his memory. The Matheran Hill Railway was built in 1907 by Sir Adamjee Peerbhoy and covers a distance of 20 km (12 mi), over large swathes of forest territory.</p>
<p>The Matheran hill railway, also known as Matheran Light Railway (MLR), was inspected by UNESCO world heritage site officials but failed to make it to the list as a World Heritage Site. India's other Hill Railways like the Darjeeling Railway, the Kangra Valley Railway, Nilgiri Mountain Railway are already on the list.</p>
</div>
同样可以找到 jsfiddle: https://jsfiddle.net/mithunu/tu25y6da/
【问题讨论】:
标签: css image responsive