资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java盒子模型代码 盒子模型的代码

盒子模型示例代码

--定义样式 border-style:

站在用户的角度思考问题,与客户深入沟通,找到长乐网站设计与长乐网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站设计、成都做网站、企业官网、英文网站、手机端网站、网站推广、国际域名空间、网络空间、企业邮箱。业务覆盖长乐地区。

!DOCTYPE html

html

head

meta charset="utf-8"

title菜鸟教程(runoob点抗 )/title

style type="text/css"

.block {

  width: 200px;

height:200px;

  padding: 30px;

background-color: red;

border-style:solid;

border-width:10px;

border-color:green;

//border:10px solid yellow;

//border-radius: 20px;

//margin:auto;

}

/style

/head

body

div class="block"border/div

/body

/html

--兄弟元素margin合并

!DOCTYPE html

html lang="en"

head

meta charset="UTF-8"

titleTitle/title

style type="text/css"

    body {

        background: pink;

    }

  .div {

        //overflow: hidden;

        //margin: 0 auto;

        width: 300px;

        height: 600px;

        background: #aaa;

    }

  .div1 {

        width: 200px;

        height: 200px;

        background: red;

        //margin: 50px 0px;

        //float: left;

    }

  .div2 {

        width: 200px;

        background: green;

        //margin: 50px 0px;

        height: 200px;

        //float: left;

    }

/style

/head

body

div class="div"

    div class="div1"/div

    div class="div2"/div

/div

/body

/html

----父子元素margin合并

!DOCTYPE html

html

head

meta charset="utf-8"

title菜鸟教程(runoob点抗 )/title

style type="text/css"

    body {

        background: pink;

    }

  .div1 {

        //margin-top: 20px;

        width: 450px;

        height: 450px;

        background: #aaa;

//overflow:hidden;

//border:1px solid red;

    }

  .div2 {

        width: 200px;

        height: 200px;

        background: red;

        //margin-top: 50px;

    }

/style

/head

body

div class="div1"

    div class="div2"/div

/div

/body

/html

--box-sizing

!DOCTYPE html

html

head

meta charset="utf-8"

title菜鸟教程(runoob点抗 )/title

style type="text/css"

.group {

  /* background-color: blue; */

  overflow: hidden;

}

.block {

  width: 33.33%;

  padding: 20px;

  float: left;

  //box-sizing: border-box ;

}

.red {

  background-color: red;

//box-sizing: conten-box ;

//overflow: hidden;

//outline:#00FF00 dotted thick;

}

.green {

  background-color: green;

}

.gray {

  background-color: gray;

//box-sizing: border-box  ;

}

/style

/head

body

div class="group"

div class="block red"1/div

div class="block green"2/div

div class="block gray"3/div

/div

/body

/html

--盒子显示(display)类型

!DOCTYPE html

html

head

meta charset="utf-8"

title菜鸟教程(runoob点抗 )/title

style

.background{

background-color:#F60;

margin-bottom:5px;

margin-left:5px;

height:50Px;

}

.display1{

display:block;

}

.display2{

display:inline ;

//display:inline-block;

}

/style

div class="background "Div默认为 block/div

div class="background "Div默认为 block/div

div class="background "Div默认为 block/div

div class="background display2"修改为 inline/div

div class="background display2"修改为 inline/div

div class="background display2"修改为 inline/div

span class="background display1"加了block属性/span

span class="background display1"加了block属性/span

span class="background display1"加了block属性/span

span class="background"没加block属性/span

span class="background"没加block属性/span

span class="background"没加block属性/span

/body

/html

盒子模型 边框 内边框外边框代码

!doctype html

html lang='en'

head

meta charset='utf8'

title盒子模型/h1

style type='text/css'

.box1{

/*

使用width来设置盒子内容区的宽度

使用height来设置盒子内容区的高度

width和height只是设置的盒子内容区的大小,而不是盒子的整个大小,盒子可见框的大小由内容区,内边距和边框共同决定

/

width: 300px;

height: 300px;

/ 设置背景颜色 /

background-color: #bfa;

/ 为元素设置边框

要为一个元素设置边框必须指定三个样式

border-width:边框的宽度

border-color:边框颜色

border-style:边框的样式

/

/ border-width: 10px; /

/

使用border-width可以分别指定四个边框的宽度

如果在border-width指定了四个值

则四个值会分别设置给上、右、下、左,按照顺时针的方向设置的

如果指定三个值

则三个值会分别设置给上、左右、下

如果指定两个值

则两个值会分别设置给上下、左右

如果指定一个值,则四边全都是该值

border-style: solid dotted dashed double;

/style

/head

body

div class='boxl'/div

!doctype html

html lang='em'

head

meta charset=utf8

title盒子模型/title

style type='text'/css

.box1

/ 为元素设置边框

要为一个元素设置边框必须指定三个样式

border-width:边框的宽度

border-color:边框颜色

border-style:边框的样式

/

/ border-width: 10px;/

/*

使用border-width可以分别指定四个边框的宽度

如果在border-width指定了四个值

则四个值会分别设置给上、右、下、左,按照顺时针的方向设置的

如果指定三个值

则三个值会分别设置给上、左右、下

如果指定两个值

则两个值会分别设置给上下、左右

如果指定一个值,则四边全都是该值

border-style:solid dotted dashed double;

/style

/head

body

div class='box1'/div

/body

/html

!doctype html

html lang='em'

head

meta charset='utf8'

style type=/'text/css'

.box1

width:200px

height:200px

background-color;#bfa

/ 设置边框 /

border:10px red solid

padding: 100px 200px 300px 400px

}

创建一个子元素box2占满box1 /

.box2{

width:100%px

height:100%px

background-color:yellow;

}

/style

body

div clas='box1'

/div

/body

!doctype html

html lang='em'

head

meta charset=utf8

title外边框/title

style type='text'/css

.box1{

width:200px

height 200px

background-color:#bfa

bborder ;10px solid red;

/*

外边距指的是当前盒子与其他盒子之间的距离,他不会影响可见框的大小,而是会影响到盒子的位置

盒子有四个方向的外边距:

margin-top

margin-right

margin-bottom

margin-left

由于页面中的元素都是靠左靠上摆放的,所以注意当我们设置上和左外边距时,会导致盒子自身的位置发生改变,而如果是设置右和下外边距会改变其他盒子的位置

/

/ 设置上外边距,即盒子的上边框与其他盒子的距离 /

/ margin-top: 100px; /

/ 左外边距 /

/ margin-left: 100px; /

/ 设置右和下外边距 /

/ margin-right: 100px;

margin-bottom: 100px; /

/

外边距也可以指定为一个负值,如果外边距设置的是负值,则元素会向反方向移动

/

/ margin-left: -100px;

margin-top: -100px;

margin-bottom: -100px; /

/ margin-bottom: -100px;*/

/*

margin还可以设置为auto,auto一般只设置给水平方向的margin

如果只指定,左外边距或右外边距的margin为auto则会将外边距设置为最大值

垂直方向外边距如果设置为auto,则外边距默认就是0

如果将left和right同时设置为auto,则会将两侧的外边距设置为相同的值,就可以使元素自动在父元素中居中

所以我们经常将左右外边距设置为auto,以使子元素在父元素中水平居中

/

/ margin-left: auto;

margin-right: auto; /

/ margin-top: auto; /

/

外边距同样可以使用简写属性 margin,可以同时设置四个方向的外边距,规则和padding一样

/

/ margin: 10px 20px 30px 40px;*/

margin: 0 auto;

box2{

/stype

/head

body

div class='box1'/div

div class='box2'.div

/doby

/html

用JAVA编写:设计并实现类Box,所包含的实例数据表示盒子的高度、宽度和厚度,一个boolean型实例数据

public class Box {

private double height, width, thickness;

private boolean full;

Box(double height, double width, double thickness){

this.height=height;

this.width=width;

this.thickness=thickness;

full=false;

}

public double getHeight(){

return height;

}

public double getWidth(){

return width;

}

public double thickness(){

return thickness;

}

public boolean getFull(){

return full;

}

public void setHeight(double height){

this.height=height;

}

public void setWidth(double width){

this.width=width;

}

public void setThickness(double thickness){

this.thickness=thickness;

}

public void setFull(boolean full){

this.full=full;

}

public String toString(){

String s="";

if(getFull()==true)

s="The height of the box is "+getHeight()+";"

+"The height of the box is "+getHeight()+";"

+"The height of the box is "+getHeight()+";"

+"and the box is full";

else

s="The height of the box is "+getHeight()+";"

+"The height of the box is "+getHeight()+";"

+"The height of the box is "+getHeight()+";"

+"and the box is not full";

return s;

}

public static void main(String args[]){

Box b1=new Box(12.1,10.3,9.5);

Box b2=new Box(5.3,3.5,2.5);

System.out.println(b1);

System.out.println(b2);

b1.setFull(true);

b1.setHeight(15);

b1.setWidth(13);

b1.setThickness(14);

b2.setHeight(6);

b2.setWidth(4);

b2.setThickness(8);

System.out.println(b1);

System.out.println(b2);

}

}


当前标题:java盒子模型代码 盒子模型的代码
文章转载:http://cdkjz.cn/article/ddsjdoc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220