css怎么让一个form标签水平垂直居中显示

html-css0137

css怎么让一个form标签水平垂直居中显示,第1张

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html,输入问题基础代码。

2、在index.html中的<style>标签中,输入css代码:body {text-align:center},在<script>标签中输入js代码:

var a = ($(document).height() - $('form').height()) / 2

$('form').css('margin-top', a + 'px')

3、浏览器运行index.html页面,此时form标签成功在页面中水平垂直居中了。

function isdh(ee)

{

var divh=$(ee).offset().top

$(window).scroll(function(){

var wsh=$(window).scrollTop()

if (wsh>=divh)

{ $(ee).css({"position":"fixed","top":"0px"})}

else

{ $(ee).css({"position":"relative"})}

})

}

先获得需要此效果的div的scrolltop,然后在窗口滚动事件里面如果窗口的scrolltop大于div的scrolltop就改变div的css

<SCRIPT language=javascript>

function jthn(v,s)

{var i

for (i=1i<5i++)

{

eval("show"+i).style.background= ""

eval("jthn"+i).style.display= "none"

}

v.style.background= "url(image/bj_2.jpg)"

v.style.color="#FF0000"

eval(s).style.display= ""

}

</SCRIPT>