jquery - jquery 或 CSS 的函数可以动态地将图像和文本调整为浏览器的宽度和/或高度并保持纵横比?
问题描述
我希望通过浏览器宽度和/或高度动态调整 div 的大小并保持纵横比。如果可能的话,也让 div 内的文本也这样做。任何事情都会很棒!
解决方案
你追求的是这样的东西吗?
.staticSize {
border: 3px solid black;
min-height: 400px;
height: 400px;
min-width: 400px;
width: 400px;
position: absolute;
top: 10px;
left: 10px;
}
.staticSize * {
display: block;
text-align: center;
margin-left: auto;
margin-right: auto;
}
<div class="staticSize">
<h1>
A heading
</h1>
<img src="http://writingexercises.co.uk/images2/randomimage/boat.jpg" width=350/>
<label>A description of above. Wow, such description. Very descriptive. More text.
More text. More text. More text. More text. More text. More text. More text.
More text. More text. More text. More text. More text. More text. More text. </label>
</div>
使用min-witdth
, min-height
,您可以在某种程度上强制内容保持相同height
的width
大小 - 但是里面的文本仍然会受到浏览器驱动的缩放功能的影响。
请参阅JSFiddle,以便您可以查看图像。
推荐阅读
- python - 流生成器。无限迭代器中的输出限制
- javascript - 包裹字符编码
- geolocation - 如何从 Clickhouse 查询中获取 Maxmind 地理位置?
- javascript - 注册后如何在 Reactjs 中路由到不同的页面
- reactjs - 尝试使用 React 功能组件实现 ContextAPI
- javascript - 如何在 Multer 中为文件大小限制设置自定义错误消息
- javascript - React Native 中的文件位置问题
- java - Java spring boot 调用方法全部设置完毕
- javascript - Discord OGP 嵌入是否考虑了 JavaScript?
- javascript - 如何从函数内部调用函数?