首页 > 解决方案 > CSS。根据设备屏幕宽度(而不是窗口)调整 div

问题描述

我想设置元素宽度等于(设备屏幕宽度)/4。
视口宽度和高度(vw,vh)不适合这个。
我可以只用 CSS 做到这一点吗?

我要这样广告媒体规则:

@media (min-width: 550px) {
    .poster {
        width: 25%;     /* here I want to set 25% of screen width */
        height: auto;
    }
}

标签: css

解决方案


我建议你好好看看这个:https ://css-tricks.com/snippets/css/a-guide-to-flexbox/

基本上使用百分比(设备屏幕的 1/4 为 25%)


推荐阅读