Home  >  Article  >  Web Front-end  >  背景图片拉伸(CSS方法)_html/css_WEB-ITnose

背景图片拉伸(CSS方法)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:35:011117browse

  在布局现在的网站首页的时候,发现一个问题。我使用了一张1440*900的png图片作为背景图片。页面内的Div使用了较多的百分比自适应框体大小,原body元素的CSS如下

html {    width: 100%;    height: 100%;}body {    background: url(../img/bg.png) no-repeat;    margin: 0;    padding: 0;    width: 100%;    height: 100%;    overflow: auto;}

  背景图片为一张渐变图片,如果图片重复平铺的话将会非常难看,所以不做平铺处理。

  这样完成后在不超过1440*900的分辨率的显示器下都没有问题,可是当用更高的分辨率的显示器查看时,发现,框体随着浏览器的大小拉伸了,可是背景图片当超过1440*900以后就会用白色背景补缺,十分难看。

  后来去查找处理方法,找到一些用js处理(由于鄙人Js还在学习,未采用),还有一些在某些特定兼容条件下用CSS处理的。

  于是,就采用以下方式重新进行背景。

  HTML部分代码:

<!DOCTYPE html><html><head>    <meta charset="utf-8" /></head><body>    <img  id="background_img" src="img/bg.jpg" / alt="背景图片拉伸(CSS方法)_html/css_WEB-ITnose" ></body></html>

  CSS部分代码:

  

html {    width: 100%;    height: 100%;}body {    /*background: url(../img/bg.png) no-repeat;*/    margin: 0;    padding: 0;    width: 100%;    height: 100%;    overflow: auto;}/* ------------ Background Img ------------------*/#background_img {    z-index: -999;    position: fixed;    left: 0;    top: 0;    width: 100%;    height: 100%;}

  完成后背景图片(其实已经变成伪背景,是一个在页面的img)会随着浏览器的大小,进行拉伸。

  这种方法存在的问题:

  ①jpg图片,当拉伸到一定程度以后,画质损失会非常严重。

  ②当在空白区域鼠标右键,显示的是保存图片,而不是常规右键菜单。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn