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>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>6、如圖,網頁設計,文字和表單上下對齊,請寫出HTML代碼,謝謝!
這個很簡單,隨便寫,你可以參考下php中文網的資料,上面有例子的,html還是很簡單的,我吧代碼貼給你,你自己看下
<!DOCTYPE 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>
這是代碼