今天学习了JS的入门课程,听的不多,做了个小练习,给DIV设置宽高,背景色一点点都是进步核心代码如下。:
<!DOCTYPE html>
<html lang =“en”>
<head>
<meta charset =“UTF-8”>
<title> JS入门_设置div宽,高,背景色</ title>
<style>
* {
margin :0;
填充:0;
}
h2 {
float:left;
}
#span1 {
width:100px;
高度:40像素;
背景:红色;
text-align:center;
line-height:40px;
display:inline-block;
}
#box {
width:100px;
高度:100像素;
边界:2px solid#000;
}
#con {
width:300px;
高度:200像素;
背景:#fff;
border:10px solid#d2d2d2;
保证金:0自动;
填充:20px;
位置:固定;
上:300px;
右:300像素;
z-index:2;
}
#red,#yellow,#blue,#width1,#width2,#width3,#height1,#height2,#height3 {
display:inline-block;
宽度:36px;
高度:33px;
text-align:center;
行高:33px;
保证金:5px;
}
#width1,#width2,#width3,#height1,#height2,#height3 {
background:#f1f1f1;
边框:1px solid#000;
}
#red {
background:red;
}
#yellow {
background:yellow;
}
#blue {
background:blue;
}
.btn1,.btn2 {
width:60px;
高度:30PX;
颜色:#fff;
背景:蓝色;
border:1px solid#02f;
border-radius:2px;
保证金:10px;
}
</ style>
<script>
window.onload = function(){
oBody = document.getElementById('body');
oSpan1 =的document.getElementById( 'SPAN1');
OCON =的document.getElementById( 'CON');
oBox =的document.getElementById( '盒子');
或运算=的document.getElementById( '红');
oYellow =的document.getElementById( '黄色');
oBlue =的document.getElementById( '蓝');
oWidth1 =的document.getElementById( '宽度1');
oWidth2 =的document.getElementById( '宽度2');
oWidth3 =的document.getElementById( 'width3');
oHeight1 =的document.getElementById( 'height1');
oHeight3 =的document.getElementById( 'height3');
oSpan1.onclick = function(){
oCon.style.display ='block';
oBody.style.background = '#c1c1c1';
}
oRed.onclick = function(){
box.style.background ='red';
}
oYellow.onclick = function(){
box.style.background ='yellow';
}
oBlue.onclick = function(){
box.style.background ='blue';
}
oWidth1.onclick = function(){
box.style.width ='200px';
}
oWidth2.onclick = function(){
box.style.width ='300px';
}
oWidth3.onclick = function(){
box.style.width ='400px';
}
oHeight1.onclick = function(){
box.style.height ='200px';
}
oHeight2.onclick = function(){
box.style.height ='300px';
}
oHeight3.onclick = function(){
box.style.height ='400px';
}
}
</ script>
</ head>
<body id =“body”>
<div id =“top”>
<h2>请为下面的DIV设置样式:</ h2>
<span id =“span1”>点击设置</ span>
</ div>
<div id =“box”> </ div>
<div id =“con”>
<p>请选择背景色:<span id =“red”>红</ span> < span id =“yellow”>黄</ span> <span id =“blue”>蓝</ span> </ p>
<p>请选择宽(px):<span id =“width1”> 200 </ span> <span id =“width2”> 300 </ span> <span id =“width3”> 400 </ span> </ p>
<p>请选择高(px):<span id =“height1”> 200 </ span> <span id =“height2”> 300 </ span> <span id =“height3”> 400 </ span> </ p>
<button class =“btn1”>恢复</ button>
<button class =“btn2”>确定</ button>
</ div>
</ body>
</ html>
运行效果:

2541




被折叠的 条评论
为什么被折叠?



