gpt4 book ai didi

javascript - Twitter Bootstrap 的响应式背景?

转载 作者:行者123 更新时间:2023-11-28 04:13:13 25 4
gpt4 key购买 nike

我想为网站背景设置响应式图像排列。

例如,基于不同的屏幕分辨率,我想加载不同的背景图片。此外,如果我可以定义不同的行为,那将会很有用;例如,较高分辨率的台式机将具有更大的拉伸(stretch)背景图像,而上网本可能具有较小版本的缩小版以适合,或者 3GS iPhone 将具有较小的平铺图像。

您将如何实现这样的场景?

最佳答案

我相信这会帮助您解决问题。我今天在一次不相关的谷歌探险中遇到了以下图书馆:eCSSential .好像是票您可以使用库来检测屏幕尺寸,并加载适当的 CSS 文件,同时考虑当前视口(viewport)和当前设备的屏幕尺寸。非常漂亮。

结合我前面部分的回答,相信你会有一个很好的处理问题的方法。


下面只是您可以查询的屏幕尺寸的示例,但您明白了。可以为每个场景设置背景样式。

/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
/* Styles */
}

/* Smartphones (portrait) ----------- */
@media only screen
and (max-width : 320px) {
/* Styles */
}

/* iPads (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}

/* iPads (landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}

/* iPads (portrait) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}

/* Desktops and laptops ----------- */
@media only screen
and (min-width : 1224px) {
/* Styles */
}

/* Large screens ----------- */
@media only screen
and (min-width : 1824px) {
/* Styles */
}

/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}

背景可以为任何分辨率设置不同的样式,例如:

@media only screen 
and (min-device-width : [width])
and (max-device-width : [width]) {

body {
background-image: url('../img/image.png');
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
// or you could just center the image if it's bigger than the current viewport
// background-position: center center;
}
}

来源:大部分来自 CSS Tricks

关于javascript - Twitter Bootstrap 的响应式背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13018000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com