css - CSS。根据设备屏幕宽度(而不是窗口)调整 div
问题描述
我想设置元素宽度等于(设备屏幕宽度)/4。
视口宽度和高度(vw,vh)不适合这个。
我可以只用 CSS 做到这一点吗?
我要这样广告媒体规则:
@media (min-width: 550px) {
.poster {
width: 25%; /* here I want to set 25% of screen width */
height: auto;
}
}
解决方案
我建议你好好看看这个:https ://css-tricks.com/snippets/css/a-guide-to-flexbox/
基本上使用百分比(设备屏幕的 1/4 为 25%)
推荐阅读
- python - 将重复项转换为 nan 仅保留最后一次出现
- google-cloud-platform - 谷歌云sql数据读取审计日志
- c - GCC 可以警告库中未定义的函数吗?
- c++ - 为什么这些介于 0 和 1 之间的双精度数总是打印 0?
- html - 没有填充或边距:是什么让我的表格无法获得 100% 的宽度?& 为什么当鼠标悬停在可滚动的 el 上时滚动条不随滚轮滚动?
- regex - LoadError:PCRE 编译错误:lookbehind 断言不是固定长度
- reactjs - 将 Redux 选择器值传递给响应状态而不在 useEffect 中重新渲染
- c++ - 为什么 C++20 std::condition_variable 不支持 std::stop_token?
- c++ - 如何在 C++ 控制台中禁用输入法?
- typescript - 将 ECMAScript Observable / Zen Observable 转换为 RXJS Observable