简单更改样式

来源:互联网 发布:淘宝分销一件代发 编辑:程序博客网 时间:2024/06/07 13:58

简单更改块的样式

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><script type="text/javascript">    window.onload = abc;    function abc(){        var obtn=document.getElementById('btn');        var ofloat=document.getElementById('float');        var odiv1=document.getElementById('div1');        var oa1=document.getElementById('red');        var oa2=document.getElementById('yellow');        var oa3=document.getElementById('blue');        var ow2=document.getElementById('w-200');        var ow3=document.getElementById('w-300');        var ow4=document.getElementById('w-400');        var oh2=document.getElementById('h-200');        var oh3=document.getElementById('h-300');        var oh4=document.getElementById('h-400');        var oresrt=document.getElementById('resrt');        var oconfirm=document.getElementById('confirm');        obtn.onclick=function(){            ofloat.style.display='block';        }        oresrt.onclick=function(){            odiv1.style.background='#fff';            odiv1.style.width='100px';            odiv1.style.height='100px';        }        oconfirm.onclick=function(){            ofloat.style.display='none';        }        oa1.onclick=function(){            odiv1.style.background='red';        }        oa2.onclick=function(){            odiv1.style.background='yellow';        }        oa3.onclick=function(){            odiv1.style.background='blue';        }        ow2.onclick=function(){            odiv1.style.width='200px';        }        ow3.onclick=function(){            odiv1.style.width='300px';        }        ow4.onclick=function(){            odiv1.style.width='400px';        }        oh2.onclick=function(){            odiv1.style.height='200px';        }        oh3.onclick=function(){            odiv1.style.height='300px';        }        oh4.onclick=function(){            odiv1.style.height='400px';        }    }</script><style type="text/css">    body{         background: #efefef;        width: 100%;        height: 646px;        margin:0;        }    .span1 {        font-family: "黑体";        font-size: 25px;        font-weight: bold;        color: green;        vertical-align: middle;    }    #btn {        width: 100px;        height: 35px;        background: red;        border: none;        color: white;        font-weight: bold;        font-size: 16px;        vertical-align: middle;    }    #div1 {        width: 100px;        height: 100px;        border: 2px solid #999;        background: #fff;        margin-top: 25px;    }    #float {        width: 100%;        height: 100%;        background: #000;        opacity: 0.5;filter:alpha(opacity=50);        text-align: center;        font-family: "黑体";        color: #000;        position: absolute;        top: 0;left: 0;        display: none;    }    #float .box1 {        height: 100%;        vertical-align: middle;        display: inline-block;    }    #box {        width: 300px;        height: 200px;        border: 20px solid #8e8e8e;        background: #fff;        display: inline-block;        vertical-align: middle;    }    .border {        width: 34px;        height: 30px;        color: #3c3c3c;        border: 1px solid #999;        display: inline-block;        font-size: 13px;        line-height: 30px;        margin-top: 10px;        text-decoration: none;    }    #button {        padding-top: 18px;    }    #resrt,#confirm {        width: 80px;        height: 35px;        background: blue;        color: white;        font-weight: bold;        font-size: 16px;    }</style><body>    <span class="span1">请为下面的DIV设置样式:</span>    <input id="btn" type="button" name="" value="点击设置">    <div id="div1"></div>    <div id="float">        <span class="box1"></span><div id="box">            请选择背景色:            <span class="border" id="red"></span>            <span class="border" id="yellow"></span>            <span class="border" id="blue"></span></br>            请选择宽(px):            <span class="border" id="w-200">200</span>            <span class="border" id="w-300">300</span>            <span class="border" id="w-400">400</span></br>            请选择高(px):            <span class="border" id="h-200">200</span>            <span class="border" id="h-300">300</span>            <span class="border" id="h-400">400</span></br>            <div id="button">                <input id="resrt" type="button" name="" value="恢复">                <input id="confirm" type="button" name="" value="确定">            </div>        </div>    </div></body></html>

注意点:
1、var obtn=document.getElementById(‘btn’);分号不要忘
2、vertical-align: middle;意思是字体垂直居中
3、opacity: 0.5;filter:alpha(opacity=50);透明度为50%,后面半句为兼容性

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 手机用久了变慢了怎么办 免税店买的皮带太短了怎么办 小米手机自拍照片是反的怎么办 华为p20旅行助手被删了怎么办 假如手机点击一个链接是病毒怎么办 华为手机自带铃声没了怎么办 华为手机升级后铃声没了怎么办 华为平板电脑激活锁忘记了怎么办 华为手机不小心删了系统应用怎么办 华为畅想6s开机键坏了怎么办 浏览网页是进入有病毒的网页怎么办 华为荣耀7清理加速那么慢怎么办 华为手机自带天气卸载了怎么办 手机被病毒感染了开不了机了怎么办 小米手机系统桌面已停止运行怎么办 三星手机应用锁密码忘了怎么办 手机管家应用加密密码忘记了怎么办 下载东西呗安全管家制止了该怎么办 手机百度时不小心中毒扣话费怎么办 手机扫二维码中了木马病毒要怎么办 电脑管家微信扫描语音打不开怎么办 遇到花心老公又爱玩没有担当怎么办 软件全闪退返回键不管用了怎么办 为什么下载了我的世界打不开怎么办 问道手游安全锁忘记了怎么办 电脑显示网络电缆没有插好怎么办 手机扣扣的密码忘记了怎么办 扣扣忘记密码和密保怎么办 以前用的扣扣密码忘记了怎么办 我忘记扣扣支付密码了怎么办 百度云盘下载后怎么打不开怎么办 节奏大师领钻石卡丢了怎么办? 节奏大师体力赠送关了打不开怎么办 微信钱包转账转错账号怎么办 激活微信账号电话号码输错了怎么办 爱思助手加强版下载不了软件怎么办 苹果手机用爱思助手游戏闪退怎么办 新买的手机号支付宝被注册了怎么办 王者荣耀以前领的东西忘记换怎么办 科目三停车时把油门踩成刹车怎么办 澳邮奶粉快递过程中破了怎么办