【发布时间】:2019-12-11 15:10:08
【问题描述】:
我想知道是否有办法知道用户是否在使用小型设备。如果用户使用小型设备或使用台式机,我希望我的导航菜单发生变化。我希望它类似于 col-sm
【问题讨论】:
标签: javascript html css sass bootstrap-4
我想知道是否有办法知道用户是否在使用小型设备。如果用户使用小型设备或使用台式机,我希望我的导航菜单发生变化。我希望它类似于 col-sm
【问题讨论】:
标签: javascript html css sass bootstrap-4
您可以针对响应式网站或不同尺寸的设备使用 CSS 媒体查询。您也可以根据移动方向使用 CSS。
<style>
/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {
/* Your CSS Code for this device size */
}
/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {
/* Your CSS Code for this device size */
}
/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {
/* Your CSS Code for this device size */
}
/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {
/* Your CSS Code for this device size */
}
/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px) {
/* Your CSS Code for this device size */
}
/* According to Mobile Orientation */
@media only screen and (orientation: landscape) {
/* Your CSS Code for this device orientation */
}
</style>
【讨论】:
这就是 @media 查询在 CSS 中的用途。
@media screen and (max-width:479px) {
.navbar {
// style of .navbar when screen is less than 479px
}
}
@media screen and (min-width:480px) {
.navbar {
// style of .navbar when screen is 480px or larger
}
}
【讨论】: