【发布时间】:2017-06-02 16:57:59
【问题描述】:
我一直在使用视口单元为我的网站设置图像的宽度和高度。我想知道是否有办法将 vh/vw 转换为像素,这样我就可以将图像调整为那些特定的像素。以下是我的代码/测量值。
#left > img:nth-of-type(1) {
height: 65vh;
width: 78vw;
}
#left > img:nth-of-type(2) {
height: 90vh;
width: 78vw;
}
#left, #right {
display: inline-block;
}
#top-right, #bottom-right {
display: block;
}
#top-right > img:nth-of-type(1) {
width: 75vw;
height: 100vh;
}
#top-right > img:nth-of-type(2) {
width: 45vw;
height: 100vh;
}
#bottom-right > img:nth-of-type(1) {
width: 70vw;
height: 55vh;
}
#bottom-right > img:nth-of-type(2) {
width: 50vw;
height: 55vh;
}
【问题讨论】:
-
Fwiw,您可以确定任何元素的当前像素大小,例如使用JavaScript 中的
offsetWidth和offsetHeight属性。
标签: css pixels image-scaling viewport-units