CSS3如何固定图片宽度使图片高度按图片比例自适应?

html-css014

CSS3如何固定图片宽度使图片高度按图片比例自适应?,第1张

使用img标签,给它的width属性设定一个绝对数量值,其高度就会自动按照width的值进行缩放了。

如:

<img alt="" src="imgs/图片.jpg" width="1000" />

除了通过 JS 获取精确的 height 值的方法外,其实我们可以使用 max-height 代替 height。

只要我们设置一个肯定比元素自增长大的高度值就可以了。当然,因为是根据 max-height 值进行过渡效果,所以最好不要大得离谱,否则动画效果不理想。

一则好像会出现竖向滚动条,

二则,一旦content中内容多了……,

如果我没体会错,您是这个意思:

XML/HTML code?

<html>

<head>

<title>自适应高度测试</title>

</head>

<style>

html body {

height: 100%

}

.header {

height: 100px

}

.footer {

position: fixed

bottom: 0

}

</style>

<body>

<div class="header">This is header</div>

<div class="content">This is content</div>

<div class="footer">This is footer</div>

</body>

</html>