0HTML5标志响应背景图片的网站

我最近一直在更新我的网站和网络服务器,并添加新站点 (LoveCrete.org). 我想有一个LoveCrete背景图像和意识到,当然 1 尺寸不适合所有屏幕. 这里是一个总结就是我的想法是和我做了什么,以迎合众多的屏幕大小和方向.

哪个方向

I star­ted by mak­ing myself a little table of all the com­mon res­ol­u­tions used on 电脑 and tab­lets (in hori­zont­al ori­ent­a­tion). I decided to focus on this because most images are avail­able in land­scape so this is a sens­ible place to start.

I decided that I would place images cent­rally on the page and let the edges be lost off the edge of the screen in some instances. When a phone is used in por­trait ori­ent­a­tion it will load the image based on height (不宽) 并从图像的边缘都失去了很多. Doing it any oth­er way would mean need­ing images cropped to a totally dif­fer­ent shape or hav­ing a land­scape image “tile” on a tall screen, which is not desir­able.

The ratios of the max­im­um size image to make in each group were all around 1.6 with a few a bit high­er. To keep things sim­pler I decided to use a ratio of 16:10 for all images and came up with sizes to make accord­ingly.

This means in most cases the image will not be a per­fect fit to the screen size, but all screens will get some­thing very close and no screen will end up with some­thing too small. 这也意味着一个源图像可以被裁剪到 16:10 once and then mul­tiple sizes eas­ily cre­ated

常见的景观分辨率组

高度宽度图像,使其COM,目
4:316:1016:9
2160288038402400×38404ķUHD
1600
1536
1440
-
2048
1920
2560
-
-
-
-
2560
1600×2560
1200
1080
1050
1600
1440
1400
1920
-
1680
-
1920
-
1200×19201080p全高清
960
900
1280
1200
1536
1440
-
1600
1000×1600
800
768
720
-
1024
960
1280
-
-
-
-
1280
800×1280720p
600
576
800
768
960
-
-
1024
640×1024
480640768480×768

As you can see I have grouped quite a few res­ol­u­tions and will then make 1 image that will cov­er all heights up to the largest height in that group. I will make sure the image is also wide enough for the max­im­um width such a height might be paired with on a nor­mal screen. I haven’t taken account of unusu­al con­fig­ur­a­tions like 21:9 mon­it­ors or mul­tiple screens — there has to be a lim­it some­where!

因为 CSS uses the view­port or browser size and not the screen size land­scape screens need to use width rather than height — as on most sys­tems the top and bot­tom lose space to title bars etc whilst the width is usu­ally max­im­ised. 但是, for por­trait dis­plays it is bet­ter to use the height prop­erty. 这是可以做到的 CSS can identi­fy the screen ori­ent­a­tion

CSS used then looks as fol­lows

身体{背景重复: 不重复; 背景附件: 固定; 背景位置: 中心中心; 背景大小: 覆盖;}

@媒体 (最大宽度: 768PX) {身体 { 背景图片: 网址(bg480.jpg); }}
@媒体 (最小宽度:769PX) and (最大宽度: 1024PX) {身体 { 背景图片: 网址(bg640.jpg); }}
@媒体 (最小宽度:1025PX) and (最大宽度: 1280PX) {身体 { 背景图片: 网址(bg800.jpg); }}
@媒体 (最小宽度:1281PX) and (最大宽度: 1600PX) {身体 { 背景图片: 网址(bg1000.jpg); }}
@媒体 (最小宽度:1601PX) and (最大宽度: 1920PX) {身体 { 背景图片: 网址(bg1200.jpg); }}
@媒体 (最小宽度:1921PX) and (最大宽度: 2560PX) {身体 { 背景图片: 网址(bg1600.jpg); }}
@媒体 (最小宽度:2561PX) {身体 { 背景图片: 网址(../图片/ bg2400.jpg); }}

@媒体 (取向: 肖像){
@媒体 (最大高度: 480PX) {身体 { 背景图片: 网址(bg480.jpg); }}
@媒体 (最小高度:481PX) and (最大高度: 640PX) {身体 { 背景图片: 网址(bg640.jpg); }}
@媒体 (最小高度:641PX) and (最大高度: 800PX) {身体 { 背景图片: 网址(bg800.jpg); }}
@媒体 (最小高度:801PX) and (最大高度: 1000PX) {身体 { 背景图片: 网址(bg1000.jpg); }}
@媒体 (最小高度:1001PX) and (最大高度: 1200PX) {身体 { 背景图片: 网址(bg1200.jpg); }}
@媒体 (最小高度:1201PX) and (最大高度: 1600PX) {身体 { 背景图片: 网址(bg1600.jpg); }}
@媒体 (最小高度:1601PX) {身体 { 背景图片: 网址(bg2400.jpg); }}
}

发现这个有用? 请不要让我们知道通过下降到低于评论. 如果您想订阅,请使用菜单上的订阅链接右上方. 您还可以通过使用下面的链接社会分享这与你的朋友. 干杯.

发表评论