1. html5和css篇有關浮動以及如何清除浮動
浮動和盒狀模型、定位是CSS重點和難點。浮動,就是讓div樣式層塊,向左或向右(靠)浮動。
Float:left 靠左浮動;Float:right 靠右浮動;clear:both清除浮動,簡單舉例如下:
CSS樣式如下:
.box1{float:left;width:200px;height:300px;background:#f00;}/*設置div對象浮動靠左*/
.box2{float:right;width:200px;height:300px;background:#0f0;}/*設置div對象浮動靠右*/
.clear{clear:both;}/*清除浮動*/
html代碼如下:
<divclass="divcss5">
<divclass="box1">布局靠左浮動</div>
<divclass="box2">布局靠右浮動</div>
<divclass="clear"></div><!--html注釋:清除float產生浮動-->
</div>
效果如下:
浮動利用好了,再結合相對定位,絕對定位,CSS排版基本上就能搞定了,細節的東西在實踐中去體驗吧。
2. 一個DIV里,一邊靠左,一邊靠右,怎麼實現
利用float屬性給div里的標簽實現浮動對齊效果
定義和用法
loat 屬性定義元素在哪個方向浮動。以往這個屬性總應用於圖像,使文本圍繞在圖像周圍,不過在 CSS 中,任何元素都可以浮動。浮動元素會生成一個塊級框,而不論它本身是何種元素。
如果浮動非替換元素,則要指定一個明確的寬度;否則,它們會盡可能地窄。
注釋:假如在一行之上只有極少的空間可供浮動元素,那麼這個元素會跳至下一行,這個過程會持續到某一行擁有足夠的空間為止。
默認值: none
繼承性: no
版本: CSS1
javaScript 語法:object.style.cssFloat="left"
float可取值
left 元素向左浮動。
right 元素向右浮動。
none 默認值。元素不浮動,並會顯示在其在文本中出現的位置。
inherit 規定應該從父元素繼承 float 屬性的值。
3. 網頁右邊跟隨滾動條上下移動的小廣告是怎麼做的請高手給我代碼
左欄浮動廣告
<script language=javascript>var specialcode="<DIV id=searchspe style='Z-INDEX: <script language=javascript>var specialcode="<DIV id=searchspe style='Z-INDEX: 100; right: 1px; POSITION: absolute; TOP: 180px;'><TABLE cellSpacing=0 cellPadding=0 width=150 style='border-left:1px solid #2E6287;border-top:1px solid #2E6287;border-right:1px solid #2E6287;font-size:12px;color:#ffffff; border-bottom-color:#2E6287; border-bottom-width:1px'><TR bgcolor=#2E6287><TD height=20>推薦↓</TD><TD style='CURSOR: hand' onclick=searchspe.style.visibility='hidden' width=30>關 閉</TD></TR></TABLE><table border='1' width='150' height='500' bordercolor='#2E6287'><tr><td>廣告內容</td></tr></table></DIV>";document.write(specialcode);lastScrollY=0;function heartBeat0(){diffY=document.body.scrollTop;percent=.1*(diffY-lastScrollY);if(percent>0)percent=Math.ceil(percent);else percent=Math.floor(percent);document.all.searchspe.style.pixelTop+=percent;lastScrollY=lastScrollY+percent;}window.setInterval("heartBeat0()",1);</script>
右欄浮動廣告
<script language=javascript>var specialcode="<DIV id=searchspe style='Z-INDEX: 100; left: 1px; POSITION: absolute; TOP: 50px;'><TABLE cellSpacing=0 cellPadding=0 width=360 style='border-left:1px solid #333333;border-top:1px solid #333333;border-right:1px solid #333333;font-size:12px;color:#ffffff'><TR bgcolor=#2E6287><TD height=20>推薦↓</TD><TD style='CURSOR: hand' onclick=searchspe.style.visibility='hidden' width=30>關 閉</TD></TR></TABLE><table border='1' width='150' id='table1' bordercolor='#2E6287' height='500'><tr><td>廣告內容</td></tr></table></DIV>";document.write(specialcode);lastScrollY=0;function heartBeat0(){diffY=document.body.scrollTop;percent=.1*(diffY-lastScrollY);if(percent>0)percent=Math.ceil(percent);else percent=Math.floor(percent);document.all.searchspe.style.pixelTop+=percent;lastScrollY=lastScrollY+percent;}window.setInterval("heartBeat0()",1);</script>
左欄固定廣告
<DIV id=searchspe style='Z-INDEX: 100; left: 1px; POSITION: absolute; TOP: 50px;'><TABLE cellSpacing=0 cellPadding=0 width=360 style='border-left:1px solid #333333;border-top:1px solid #333333;border-right:1px solid #333333;font-size:12px;color:#ffffff'><TR bgcolor=#2E6287><TD height=20>推薦↓</TD><TD style='CURSOR: hand' onclick=searchspe.style.visibility='hidden' width=30>關 閉</TD></TR></TABLE>廣告內容</DIV>
右欄固定廣告
<DIV id=searchspe style='Z-INDEX: 100; right: 1px; POSITION: absolute; TOP: 50px;'><TABLE cellSpacing=0 cellPadding=0 width=360 style='border-left:1px solid #333333;border-top:1px solid #333333;border-right:1px solid #333333;font-size:12px;color:#ffffff'><TR bgcolor=#2E6287><TD height=20>推薦↓</TD><TD style='CURSOR: hand' onclick=searchspe.style.visibility='hidden' width=30>關 閉</TD></TR></TABLE>廣告內容</DIV>
漂浮廣告代碼
<div id="img" style="position:absolute;; width: 200; height: 151">廣告內容</div>
<script LANGUAGE="JavaScript">
var xPos = 20;
var yPos = 10;
img.style.left= xPos;
img.style.top = yPos;
var step = 1;
var delay = 30;
var width,height,Hoffset,Woffset;
var y = 1;
var x = 1;
var interval;
img.visibility = "visible";
function changePos()
{
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = img.offsetHeight;
Woffset = img.offsetWidth;
if (y)
{
yPos = yPos + step;
}
else
{
yPos = yPos - step;
}
if (yPos < 0)
{
y = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset))
{
y = 0;
yPos = (height - Hoffset);
}
if (x)
{
xPos = xPos + step;
}
else
{
xPos = xPos - step;
}
if (xPos < 0)
{
x = 1;
xPos = 0;
}
if (xPos >= (width - Woffset))
{
x = 0;
xPos = (width - Woffset);
}
img.style.left = xPos + document.body.scrollLeft;
img.style.top = yPos + document.body.scrollTop;
}
function start()
{
interval = setInterval('changePos()', delay);
}
function pause_resume()
{
clearInterval(interval);
}
start();
</script>
固定對聯
<DIV id=searchspe style='Z-INDEX: 100; right: 5px; POSITION: absolute; TOP: 50px;'><TABLE cellSpacing=0 cellPadding=0 width=150 style='font-size:12px;color:#ffffff'><TR bgcolor=#C54A00><TD height=20>推薦↓</TD><TD style='CURSOR: hand' onclick=searchspe.style.visibility='hidden' width=30>關 閉</TD></TR></TABLE>
廣告內容</DIV><DIV id=searchspe2 style='Z-INDEX: 100; left: 5px; POSITION: absolute; TOP: 50px;'><TABLE cellSpacing=0 cellPadding=0 width=150 style='font-size:12px;color:#ffffff'><TR bgcolor=#12BDFF><TD height=20>推薦↓</TD><TD style='CURSOR: hand' onclick=searchspe2.style.visibility='hidden' width=30>關 閉</TD></TR></TABLE>
廣告內容</DIV>
隨動對聯
<script language=javascript>function close163news(){searchspe.style.visibility='hidden';searchspe2.style.visibility='hidden';} var specialcode="<DIV id=searchspe style='Z-INDEX: 100; right: 1px; POSITION: absolute; TOP: 30px;'><TABLE cellSpacing=0 cellPadding=0 width=150 style='font-size:12px;color:#ffffff'><TR bgcolor=#C54A00><TD height=20>推薦↓</TD><TD style='CURSOR: hand' onclick='close163news()' width=30>關 閉</TD></TR></TABLE>廣告內容</DIV>";document.write(specialcode);lastScrollX=0;function heartBeat0(){diffY=document.body.scrollTop;percent=.1*(diffY-lastScrollX);if(percent>0)percent=Math.ceil(percent);else percent=Math.floor(percent);document.all.searchspe.style.pixelTop+=percent;lastScrollX=lastScrollX+percent;}window.setInterval("heartBeat0()",1);var specialcode2="<DIV id=searchspe2 style='Z-INDEX: 100; left: 1px; POSITION: absolute; TOP: 30px;'><TABLE cellSpacing=0 cellPadding=0 width=150 style='font-size:12px;color:#ffffff'><TR bgcolor=#12BDFF><TD height=20>推薦↓</TD><TD style='CURSOR: hand' onclick='close163news()' width=30>關 閉</TD></TR></TABLE>廣告內容</DIV>";document.write(specialcode2);lastScrollY=0;function heartBeat1(){diffY=document.body.scrollTop;percent=.1*(diffY-lastScrollY);if(percent>0)percent=Math.ceil(percent);else percent=Math.floor(percent);document.all.searchspe2.style.pixelTop+=percent;lastScrollY=lastScrollY+percent;}window.setInterval("heartBeat1()",1);</script>
qq好友上線廣告代碼
<!-- 代碼開始 請將下面的代碼放到body結束標簽之前-->
<DIV id=eMeng
style="BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX: 99999; LEFT: 64px; VISIBILITY: hidden; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: 168px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: 374px; HEIGHT: 115px; BACKGROUND-COLOR: #c9d3f3">
<TABLE style="BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid"
cellSpacing=0 cellPadding=0 width="100%" bgColor=#cfdef4 border=0>
<TBODY>
<TR>
<TD
style="FONT-SIZE: 12px; BACKGROUND-IMAGE: none; COLOR: #0f2c8c"
width=30 height=24> </TD>
<TD
style="PADDING-LEFT: 4px; FONT-WEIGHT: normal; FONT-SIZE: 12px; BACKGROUND-IMAGE: none; COLOR: #1f336b; PADDING-TOP: 4px"
vAlign=center width="100%"><span class="style13">本站提示</span></TD>
<TD vAlign=center align=right width=19 2px? padding-top: 2px;
padding-right:><SPAN title=關閉
style="FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: red; MARGIN-RIGHT: 4px"
onclick=closeDiv()>×</SPAN></TD></TR>
<TR>
<TD
style="PADDING-RIGHT: 1px; BACKGROUND-IMAGE: none; PADDING-BOTTOM: 1px"
colSpan=3 height=90><DIV
style="BORDER-RIGHT: #b9c9ef 1px solid; PADDING-RIGHT: 13px; BORDER-TOP: #728eb8 1px solid; PADDING-LEFT: 13px; FONT-SIZE: 12px; PADDING-BOTTOM: 13px; BORDER-LEFT: #728eb8 1px solid; WIDTH: 100%; COLOR: #1f336b; PADDING-TOP: 18px; BORDER-BOTTOM: #b9c9ef 1px solid; HEIGHT: 100%">
<div align="left"> <span style="text-decoration: none">
<FONT
color=#FF0000>仿造qq好友上線<br>
<center> </center>
</FONT></span></div>
</DIV></td></tr></table>
<SCRIPT language=JavaScript>
window.onload = getMsg;
window.onresize = resizeDiv;
window.onerror = function(){}
var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i = 0;
function getMsg()
{
try{
divTop = parseInt(document.getElementById("eMeng").style.top,10)
divLeft = parseInt(document.getElementById("eMeng").style.left,10)
divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10)
divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10)
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("eMeng").style.top = parseInt(document.body.scrollTop,10) + docHeight + 10;// divHeight
document.getElementById("eMeng").style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth
document.getElementById("eMeng").style.visibility="visible"
objTimer = window.setInterval("moveDiv()",10)
}
catch(e){}
}
function resizeDiv()
{
try{
divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10)
divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10)
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("eMeng").style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10)
document.getElementById("eMeng").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10)
}
catch(e){}
}
function moveDiv()
{
try
{
if(parseInt(document.getElementById("eMeng").style.top,10) <= (docHeight - divHeight + parseInt(document.body.scrollTop,10)))
{
window.clearInterval(objTimer)
objTimer = window.setInterval("resizeDiv()",1)
}
divTop = parseInt(document.getElementById("eMeng").style.top,10)
document.getElementById("eMeng").style.top = divTop - 1
}
catch(e){}
}
function closeDiv()
{
document.getElementById('eMeng').style.visibility='hidden';
if(objTimer) window.clearInterval(objTimer)
}
</SCRIPT>
<!-- 代碼復制結束 -->
4. div+css裡面左浮動 右浮動 到底是什麼意思
都是相對於父元素進行的浮動,確切來說就是在這個元素的左邊或者右邊位置;
我們用代碼實現左浮動,建設父子元素,把父元素設置為300PX的寬高,
子元素設置100PX的寬高,然後把子元素(div2)左浮動一下,代碼:float:left;
css浮動擴展定義
浮動的框可以向左或向右移動,直到它的外邊緣碰到包含框或另一個浮動框的邊框為止。
由於浮動框不在文檔的普通流中,所以文檔的普通流中的塊框表現得就像浮動框不存在一樣。
5. html中浮動窗口怎麼做啊就是一個小窗口飄在在頁面上那種
浮動窗口可以用js實現。帶關閉窗口的簡單全屏浮動代碼如下:
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<title>帶關閉按鈕的浮動窗口</title>
</head>
<styletype="text/css">
#fdck{border:1pxsolid#c0c0c0;margin:0auto;padding:5px;background:#f0f0f0}
</style>
<body>
<divid="img"style="position:absolute;left:311;top:815;visibility:hidden;"onmouseover="clearInterval(interval)"onmouseout="interval=setInterval('changePos()',delay)"align="middle">
<spanstyle="CURSOR:hand;color:red;font-weight:bold;font-size:12px"onclick="clearInterval(interval);img.style.visibility='hidden'">關閉</span>
<divid="fdck">
浮動測試TEST
</div>
</div>
<scriptlanguage=javascript>
varxPos=20;
varyPos=document.body.clientHeight;
varstep=1;
vardelay=30;
varheight=0;
varHoffset=0;
varWoffset=0;
varyon=0;
varxon=0;
varpause=true;
varinterval;
img.style.top=yPos;
functionchangePos(){
width=document.body.clientWidth;
height=document.body.clientHeight;
Hoffset=img.offsetHeight;
Woffset=img.offsetWidth;
img.style.left=xPos+document.body.scrollLeft;
img.style.top=yPos+document.body.scrollTop;
if(yon){
yPos=yPos+step;
}
else{
yPos=yPos-step;
}
if(yPos<0){
yon=1;
yPos=0;
}
if(yPos>=(height-Hoffset)){
yon=0;
yPos=(height-Hoffset);
}
if(xon){
xPos=xPos+step;
}
else{
xPos=xPos-step;
}
if(xPos<0){
xon=1;
xPos=0;
}
if(xPos>=(width-Woffset)){
xon=0;
xPos=(width-Woffset);
}
}
functionstart(){
img.style.visibility="visible";
interval=setInterval('changePos()',delay);
}
start();
</script>
</body>
</html>
粘貼到本地一個記事本,保存為HTML格式打開即可看見。
如果只是固定在一個位置不動,可以在div的style設置『position:fixed;』即可。
6. 左側浮動廣告代碼跟隨頁面滾動,急急急!跪求!!!!
用DOCTYPE聲明文檔類型,然後加如下代碼:
<div id="left_layer" style="position:fixed; top:40px; left:0px;">
<img src="圖片"><br>
<a href="javascript:;" onclick="javascript:document.getElementById('left_layer').style.display='none';">關閉</a>
</div>
如果有共用的頁眉頁腳,或是模版專頁之內的,加進去就可以屬顯示在所有頁了.如果沒有,就一頁頁的加吧.
7. 請教CSS圖片左側定位代碼
<style type="text/css">
.left-img{float:left; position:fixed; top:20px; left:10px;}
</style>
<img class="left-img" src="img.png" width="180" height="180" alt=""/>
註解:
<style type="text/css">....</style>/ 頁內定義(CSS樣式標簽)
.left-img / 定義樣式名稱
{....} /定義樣式
float:left; //左浮動(float: right; 右浮動)
position:fixed; //固定元素不隨滾動條滾動 (position: absolute;絕對定位,隨滾動)
top:20px; //距離頁面頂部距離
left:10px; //距離頁面左側距離
<img class="left-img" /指定給圖像Img標簽css樣式.left-img
以上可以實現你需要的效果,但還是建議你系統化的學習下
網路關鍵詞css 第一個站點w3school比較全面,前端架構師必讀~
8. js左浮動代碼急
用這個把那個地址改成你的就行了。<DIV id=divStay style="POSITION: absolute">
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top width="7%"> </TD></TR></TBODY></TABLE></DIV>
<SCRIPT language=javascript>
function picsize(obj,MaxWidth){
img=new Image();
img.src=obj.src;
if (img.width>MaxWidth)
{
return MaxWidth;
}
else
{
return img.width;
}
}
function CloseXX()
{
divStayTopleft.style.display="none";
return true;
}
var online= new Array();
</SCRIPT>
<div id="divStayTopleft" style="POSITION: absolute">
<script type='text/javascript' src='http://改這個地址/js/s.js'></script>
<script type='text/javascript'>BAIDU_CLB_singleFillSlot('43906');</script>
</div>
<script type="text/javascript">
function FloatTop()
{
var startX1 =document.body.offsetWidth-0 ,startY1 = 0;
var startX2 =0,startY2 = 95;
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function ml(id,startX,startY)
{
var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
if(d.layers)el.style=el;
el.sP=function(x,y){this.style.left=x;this.style.top=y;};
el.x = startX;
el.y = startY;
return el;
}
window.stayTopLeft=function()
{
var pY = ns ? pageYOffset : document.body.scrollTop;
ftlObj.y += (pY + startY1 - ftlObj.y)/8;
ftlObj1.y += (pY + startY2 - ftlObj1.y)/8;
ftlObj.sP(document.body.scrollLeft+document.body.offsetWidth-25, ftlObj.y);
ftlObj1.sP(ftlObj1.x, ftlObj1.y);
setTimeout("stayTopLeft()", 30);
}
// ftlObj = ml("divStay",document.body.scrollLeft+document.body.offsetWidth-125,0);
// ftlObj1 = ml("divStayTopLeft",0,30);
ftlObj = ml("divStay",(document.body.scrollLeft+document.body.offsetWidth)/2+450,0);
ftlObj1 = ml("divStayTopLeft",(document.body.scrollLeft+document.body.offsetWidth)/2+490,130);
stayTopLeft();
}
FloatTop();
</script>