我可以使用CSS按比例缩放DIV高度到其宽度吗?

编程入门 行业动态 更新时间:2024-10-28 02:21:00
本文介绍了我可以使用CSS按比例缩放DIV高度到其宽度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可以设置css中的任何变量像我想我的div高度总是一半宽度我的div缩放与屏幕尺寸宽度为div是百分比

can i set any variable in css like i want my div height always half of width my div scales with the screen size width for div is in percent

<div class="ss"></div> css : .ss{ width:30%; height: half of the width; } this 30% width scales with screen resolution

推荐答案

您可以在父项的填充的帮助下,因为相对填充(甚至高度方面)是基于元素的宽度。

You can do it with the help of padding on a parent item, because relative padding (even height-wise) is based on the width of the element.

CSS:

.imageContainer { position: relative; width: 25%; padding-bottom: 25%; float: left; height: 0; } img { width: 100%; height: 100%; position: absolute; left: 0; }

有关详细信息,请参阅有关主题的文章 wemadeyoulook.at/en/blog/proportional-scaling-responsive-boxes- using-just-css /

For details, see this article on the subject wemadeyoulook.at/en/blog/proportional-scaling-responsive-boxes-using-just-css/

更多推荐

我可以使用CSS按比例缩放DIV高度到其宽度吗?

本文发布于:2023-09-21 22:43:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466887.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缩放   可以使用   宽度   按比例   高度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!