简体   繁体   English

仅使用 CSS 设置宽度等于高度

[英]Setting width equal height using CSS only

I'm trying to design a wesite for mobile with a button in the top left corner, which is set to 100% height of the parent object.我正在尝试为移动设备设计一个网站,左上角有一个按钮,该按钮设置为父对象的100% 高度 The width should be the same as the height , but I found only solutions with JS or JQuery. width 应该与 height 相同,但我只找到了 JS 或 JQuery 的解决方案。 I like to have something like:我喜欢有这样的东西:

.hamburger {
    height: 100%;
    width: height;
}

The solution is that a height of 9% of the viewport match with 9vh. 解决方案是,视口的9%的高度与9vh相匹配。 The parent was 9% of the viewport height, the child 100% of the parent's height. 父级为视口高度的9%,子级为视口高度的100%。 To become a perfect square you set the width to 9vh. 要成为一个完美的正方形,请将宽度设置为9vh。 1vh is equal to the 100. part of the viewport height. 1vh等于视口高度的100。 So now you can scale the viewport to any size and have always a sqare. 因此,现在您可以将视口缩放到任意大小,并且始终具有正方形。

    .hamburger{

    width:100vw; /* 100% of the viewport width */
    height: 100vw;
}

you can find details on link here 您可以在此处找到链接的详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM