导航:首页 > 万维百科 > 网页设计绝对定位上下的代码

网页设计绝对定位上下的代码

发布时间: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>
这是代码

与网页设计绝对定位上下的代码相关的知识