css怎么让一张图片适应任何屏幕大小的电脑平铺?

html-css011

css怎么让一张图片适应任何屏幕大小的电脑平铺?,第1张

不定义div的宽度,以及父div的宽度即可。

来做一个导航:

<style typr="text/css">

*{margin:0padding:0border:0}

.navbg{background:redheight:50px}

.nav{width:980pxheight:50pxmargin:0 auto}

li{float:leftmargin:10pxline-height:30px}

</style>

<div class="navbg">

<div class="nav">

<ul>

<li>首页</li>

<li>联系我们</li>

<li>留言</li>

</ul>

</div>

</div>

放在<body>里试一下便知

如果<style>里再加一句 body{width:980pxmargin:0 auto}则不能铺满屏幕,只有980px。

#bg{

margin:0px

background: url(images/beijing.png) no-repeat

background-size:100% 100%

background-attachment:fixed

}

扩展资料:

url(images/beijing.png)——图片路径的位置;

no-repeat—— 图片不重复;

center 0px——center是距离页面左边的定位,0px是距离页面上面的定位;

background-position: center 0——就是图片的定位,同上;

background-size: cover——把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。背景图像的某些部分也许无法显示在背景定位区域中;

min-height: 100vh——视窗的高度,“视区”所指为浏览器内部的可视区域大小,即window.innerWidth/ window.innerHeight大小。