css相对定位不随网页位置移动问题,求解答

html-css012

css相对定位不随网页位置移动问题,求解答,第1张

你那个主要是#header元素的宽度不固定啊

你可以这样设置

如果可以固定#header img的宽度的话

#header img{

position:absolute

top:187px

left:50%

width:200px//假设这个元素是200px

margin-left:-100px//使这个元素再向左移动自身宽度的一半

}

这样就可以定位到中间了

DIV加CSS和TABLE不一样,数字后面必须注明单位。

如果实际应用中的话,这样效果我建议还是使用图片比较好。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>Untitled Page</title>

<style>

body, table, div {

font-size :200pt

color:#00800

font-weight:bold

}

</style>

</head>

<body bgcolor ="6094FF">

<div style ="position :absolute top:10pxleft:167px width:268pxheight:267pxz-index:1"><span style ="font-size :200ptcolor:Red ">█</span></div>

<div style="position :absolute top:10pxleft:284px width:268pxheight:267pxz-index:1"><span style ="font-size :200ptcolor:Red ">█</span></div>

<div style="position :absolute top:85pxleft:232px width:68pxheight:67pxz-index:7"><span style ="font-size :50ptcolor:yellow ">★</span></div>

<div style="position :absolute top:153pxleft:297px width:17pxheight:17pxz-index:7"><span style ="font-size :12ptcolor:yellow ">★</span></div>

<div style="position :absolute top:120pxleft:316px width:17pxheight:17pxz-index:7"><span style ="font-size :12ptcolor:yellow ">★</span></div>

<div style="position :absolute top:84pxleft:309pxwidth:17pxheight:17pxz-index:7"><span style ="font-size :12ptcolor:yellow ">★</span></div>

<div style="position :absolute top:63pxleft:278px width:20pxheight:17pxz-index:7"><span style ="font-size :12ptcolor:yellow ">★</span></div>

<div style="position :absolute top:204pxleft:142px width:135pxheight:267pxz-index:7"><span style ="font-size :200ptcolor:red ">▏</span></div>

<span style="position :absolute top:26pxleft:79px width:82pxheight:80pxz-index:10"><span style =" font-family :Webdings font-size :60ptcolor :White "></span></span>

</body>

</html>