[英]How to position a div element on the right side of the screen
我試圖使這個div一直到屏幕的右側。 這是HTML:
<html>
<head>
title></title>
<link rel="stylesheet" type="text/css" href="../css/style.css"/>
</head>
<h1> </h1>
<body>
<div id="bannerR">
<a href="yahoo.com" target=_blank>
<img src="yahoo.com" border=0></a>
</div>
這是style.css
#header{background-color: #fff; width: 1000px; position: relative; }
#bannerL{ position: relative; top: 500px; left: 500px; }
#bannerR{ position: relative; float: right; }
body {
background-image: url("beach.gif");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
margin-top:100px;
margin-right:180px;
margin-bottom:10px;
margin-left:200px;
}
請幫忙,我對代碼非常陌生,買了一本書,但沒有幫助。 我花了幾個小時試圖做到這一點,但無濟於事。
確保您的DIV不包含在空間有限的元素內(不跨越頁面的整個寬度)
確保將css文件鏈接到HTML,以便瀏覽器知道您正在使用的css文件。
<html>
<head>
<link rel="stylesheet" type="text/css" href="your_style.css">
</head>
<body>
<!-- YOUR HTML -->
</body>
</html>
您的body
樣式包含margin-right:180px
。 因此, #bannerR
永遠不會一直向右浮動。 刪除該樣式,它將起作用。 這是一些代碼:
body { background-image: url("beach.gif"); background-repeat: no-repeat; background-attachment: fixed; background-position: center; }
這是一個證明它的小提琴: http : //jsfiddle.net/rzKaz/1/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.