導航:首頁 > 萬維百科 > 網頁設計絕對定位上下的代碼

網頁設計絕對定位上下的代碼

發布時間:2021-03-31 02:43:26

1、如何控制一段代碼在網頁上的上下高度??

放到一個div里,div的position:absolute,然後設置top或者bottom、left或者right、width、height,這樣就能把這個div固定在某個位置了,透明的話就設置opacity,話說,其實都是css啦

2、寫一個絕對定位1-2-1頁面布局的代碼

利用相對定位 絕對定位、浮動布局代碼如下(直接復制以後代碼即可):相對定位 絕對定位、浮動布局#container{ margin:0 auto; width:1000px; clear:both; position:relative;/*相對定位*/}#header{ margin:0 auto; width:1000px;height:100px; ...

3、如何用div實現頁面上下部分固定,中間部分隨滾動條移動而移動的代碼?

代碼詳情如下,直接使用即可!

.content1{
overflow: hidden;
overflow-y:scroll;
SCROLLBAR-FACE-COLOR:#205e17;
SCROLLBAR-SHADOW-COLOR:#86ff92;
SCROLLBAR-SHADOW-COLOR:#86ff92;
SCROLLBAR-3DLIGHT-COLOR:#205e17;
SCROLLBAR-TRACK-COLOR:#205e17;
SCROLLBAR-DARKSHADOW-COLOR:#205e17;
SCROLLBAR-BASE-COLOR:#205e17;
SCROLLBAR-ARROW-COLOR:#86ff92;
height:700px;
width:748px;
}
中間的div就用下面的,樣式是上面的。
<div class="content1">
<div>

4、求html按鈕上下自由放的代碼

放在哪個地方都可以,就是絕對定位了。用CSS屬性position: absolute配合top和left兩個屬性(確定左上角坐標)來實現。但需注意,這個絕對是相對於上級元素來說的,要相對於整個頁面隨處可放,就要把它作為<html>的子元素。

我有一個用滑鼠位置定位元素的html發給你參考一下:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body{
margin: 0;
padding: 0;
}
#container{
position: relative;
background: #eeeeff;
width: 800px;
height: 600px;
border: 1px solid red;
margin: 20px auto;
}
#moveBox{
position: absolute;
width: 100px;
height: 100px;
top: 150px;
left: 250px;
background: #ddffdd;
line-height: 100px;
color: red;
border: 1px solid black;
}
</style>
<script>
function move(){
var box=document.getElementById("moveBox");
var container=document.getElementById("container");
var containerX=container.offsetLeft;
var containerY=container.offsetTop;
var thisScrollTop = document.documentElement.scrollTop + document.body.scrollTop;
var thisScrollLeft = document.documentElement.scrollLeft + document.body.scrollLeft;
var posX=event.clientX+thisScrollLeft-containerX;
var posY=event.clientY+thisScrollTop-containerY;
console.log("posX="+posX+",posY="+posY);
box.style.top=posY+"px";
box.style.left=posX+"px";
//console.log("x="+event.clientX+",y="+event.clientY);
}
</script>
</head>
<body>
<div id="container" onmousemove="move()">
<div id="moveBox">
用滑鼠移動我
</div>
</div>
</body>
</html>

5、如何用div實現頁面上下部分固定,中間部分隨滾動條移動而移動的代碼

1、頭部定義一個div,固定高度,設置絕對定位(position:absolute),設置上邊距(top:0);

2、底部定義一個div,固定高度,設置絕對定位(position:absolute),設置下邊距(bottom:0);

3、中間定義一個div,設置滾動條自動( overflow: auto); 設置絕對定位(position:absolute),設置top和bottom,top的值等於頭部div的高度,bottom的值等於底部div的高度

示例

<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title></title>
<style>
#page{margin:0 auto;width:960px;}
#header{width:960px; height:60px; position:absolute; top:0;background-color:#ccc;}
#footer{width:960px; height:30px; position:absolute; bottom:0; background-color:#ccc;}
#content{width:960px; overflow: auto; position:absolute; top:60px; bottom:30px;}
</style>

</head>
<body>
<div id="page">
<div id="header">定義頂部</div>  
<div id="content">content定義中間</div>
<div id="footer">footer定義底部</div>
</div>
</body>


</html>

6、如圖,網頁設計,文字和表單上下對齊,請寫出HTML代碼,謝謝!

這個很簡單,隨便寫,你可以參考下php中文網的資料,上面有例子的,html還是很簡單的,我吧代碼貼給你,你自己看下

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網</title>
</head>
<body>
<div>
用戶名:<input type="text">
</div>
<br>
<div>
密&nbsp;碼:<input type="password">
</div>
</body>
</html>

就完成效果了!

7、求 網頁一側上下漂浮圖片代碼?

<html>
<head>
<style type="text/css">
#floater {
position: absolute;
left: 500;
top: 146;
width: 125;
visibility: visible;
z-index: 10;
}</style>
<title>跟隨屏幕移動的圖片</title>
</head><body>
<div ID="floater" style="left: 0px; top: 0px">
<p align="center">
<img SRC="../../image/logo.jpg" border="0" width="85" height="55">
</div><script LANGUAGE="JavaScript">
self.onError=null;
currentX = currentY = 0;
whichIt = null;
lastScrollX = 0; lastScrollY = 0;
NS = (document.layers) ? 1 : 0;
IE = (document.all) ? 1: 0;
<!-- STALKER CODE -->
function heartBeat() {
if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }
if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }
if(diffY != lastScrollY) {
percent = .1 * (diffY - lastScrollY);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
if(IE) document.all.floater.style.pixelTop += percent;
if(NS) document.floater.top += percent;
lastScrollY = lastScrollY + percent;
}
if(diffX != lastScrollX) {
percent = .1 * (diffX - lastScrollX);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
if(IE) document.all.floater.style.pixelLeft += percent;
if(NS) document.floater.left += percent;
lastScrollX = lastScrollX + percent;
}
}
<!-- /STALKER CODE -->
<!-- DRAG DROP CODE -->
function checkFocus(x,y) {
stalkerx = document.floater.pageX;
stalkery = document.floater.pageY;
stalkerwidth = document.floater.clip.width;
stalkerheight = document.floater.clip.height;
if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight))) return true;
else return false;
}
function grabIt(e) {
if(IE) {
whichIt = event.srcElement;
while (whichIt.id.indexOf("floater") == -1) {
whichIt = whichIt.parentElement;
if (whichIt == null) { return true; }
}
whichIt.style.pixelLeft = whichIt.offsetLeft;
whichIt.style.pixelTop = whichIt.offsetTop;
currentX = (event.clientX + document.body.scrollLeft);
currentY = (event.clientY + document.body.scrollTop);
} else {
window.captureEvents(Event.MOUSEMOVE);
if(checkFocus (e.pageX,e.pageY)) {
whichIt = document.floater;
StalkerTouchedX = e.pageX-document.floater.pageX;
StalkerTouchedY = e.pageY-document.floater.pageY;
}
}
return true;
}
function moveIt(e) {
if (whichIt == null) { return false; }
if(IE) {
newX = (event.clientX + document.body.scrollLeft);
newY = (event.clientY + document.body.scrollTop);
distanceX = (newX - currentX); distanceY = (newY - currentY);
currentX = newX; currentY = newY;
whichIt.style.pixelLeft += distanceX;
whichIt.style.pixelTop += distanceY;
if(whichIt.style.pixelTop < document.body.scrollTop) whichIt.style.pixelTop = document.body.scrollTop;
if(whichIt.style.pixelLeft < document.body.scrollLeft) whichIt.style.pixelLeft = document.body.scrollLeft;
if(whichIt.style.pixelLeft > document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20;
if(whichIt.style.pixelTop > document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5) whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5;
event.returnValue = false;
} else {
whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY);
if(whichIt.left < 0+self.pageXOffset) whichIt.left = 0+self.pageXOffset;
if(whichIt.top < 0+self.pageYOffset) whichIt.top = 0+self.pageYOffset;
if( (whichIt.left + whichIt.clip.width) >= (window.innerWidth+self.pageXOffset-17)) whichIt.left = ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17;
if( (whichIt.top + whichIt.clip.height) >= (window.innerHeight+self.pageYOffset-17)) whichIt.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17;
return false;
}
return false;
}
function dropIt() {
whichIt = null;
if(NS) window.releaseEvents (Event.MOUSEMOVE);
return true;
}
<!-- DRAG DROP CODE -->
if(NS) {
window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);
window.onmousedown = grabIt;
window.onmousemove = moveIt;
window.onmouseup = dropIt;
}
if(IE) {
document.onmousedown = grabIt;
document.onmousemove = moveIt;
document.onmouseup = dropIt;
}
if(NS || IE) action = window.setInterval("heartBeat()",1);
</script>
</body></html>

8、網頁設計絕對定位的代碼是什麼?

p

9、怎麼控制html元素的位置(上下左右)代碼如下:

<!DOCTYPE html>
<html>
<head>
<title>MyHtml.html</title>
<script type="text/javascript">
var tmp=1;
function XX(){
var tab = document.getElementById("tab");
var span = document.createElement("span");
var tr = document.createElement("tr");
var select = document.createElement("select");
var textarea1 = document.createElement("textarea");
var textarea2 = document.createElement("textarea");
var textarea3 = document.createElement("textarea");
var textarea4 = document.createElement("textarea");
var inputDel = document.createElement("input");
select.add(new Option("css","cssEntryAddress"));
select.add(new Option("regex","regexEntryAddress"));
select.add(new Option("xpath","xpathEntryAddress"));
select.setAttribute("style", "width:80px;");
textarea1.setAttribute("placeholder", "範例:");
textarea1.setAttribute("style", "width:130px;");
textarea1.setAttribute("rows", "1");
textarea2.setAttribute("placeholder", "範例:");
textarea2.setAttribute("style", "width:155px;");
textarea2.setAttribute("rows", "1");
textarea3.setAttribute("placeholder", "範例:");
textarea3.setAttribute("style", "width:155px;");
textarea3.setAttribute("rows", "1");
textarea4.setAttribute("placeholder", "範例:");
textarea4.setAttribute("style", "width:155px;");
textarea4.setAttribute("rows", "1");
inputDel.setAttribute("type", "button");
inputDel.setAttribute("value", "刪除");
inputDel.setAttribute("class", "btn btn-info");
inputDel.setAttribute("style", "width:50px;");
inputDel.setAttribute("onclick", "deltd(this);");

span.appendChild(select);
span.appendChild(textarea1);
span.appendChild(textarea2);
span.appendChild(textarea3);
span.appendChild(textarea4);
span.appendChild(inputDel);
tr.appendChild(span);
tab.appendChild(tr);

tmp++;
}

function deltd(a){
a.parentNode.parentNode.removeChild(a.parentNode);
}

</script>
</head>

<body>
<form action="">
<input type="button" onclick="XX();" id="add" value="增加行"/>
<table id="tab">

</table>
</form>
</body>
</html>
這是代碼

與網頁設計絕對定位上下的代碼相關的知識