
public class Box {
private double height, width, thickness;
private boolean full;
Box(double height, double width, double thickness){
thisheight=height;
thiswidth=width;
thisthickness=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){
thisheight=height;
}
public void setWidth(double width){
thiswidth=width;
}
public void setThickness(double thickness){
thisthickness=thickness;
}
public void setFull(boolean full){
thisfull=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(121,103,95);
Box b2=new Box(53,35,25);
Systemoutprintln(b1);
Systemoutprintln(b2);
b1setFull(true);
b1setHeight(15);
b1setWidth(13);
b1setThickness(14);
b2setHeight(6);
b2setWidth(4);
b2setThickness(8);
Systemoutprintln(b1);
Systemoutprintln(b2);
}
}
如果是顶层(父层标签是<body>),也就是不嵌套到其他标签,直接设置style为:position:absolute;left:50px;right:50px;也可以不设置position,设置margin-left:50px;margin-right:50px;或者padding-left:50px;padding-right:50px;如果用javascript,则可以用
windowonresize=function(){
documentgetElementById("box")width=(function(){
var x=documentbodyclientWidth-100;
return x;
})();
}参考楼上那位的
运用js获取div宽度,原生JS获取DIV的属性有两种方法,js 获取方法命令如下:
currentStyle和getComputedStyle,前者是兼容IE端的,后者也兼容W3C,两者内核不同,所以就有两种兼容的写法。
如果只是单独的获取某个属性值可以这样写:
objcurrentStyle[属性名];这种不兼容-webkit-内核的,
所以一般是封装成一个函数可以到处调用,而且不止针对某个属性值。
function getStyle(obj,styleName){if(objcurrentStyle){return objcurrentStyle[styleName];}else{return getComputedStyle(obj,null)[styleName];}
}
上面是封装好一个函数,可以直接调用。
DIV是层叠样式表中的定位技术,全称DIVision,即为划分。有时可以称其为图层。DIV在编程中又叫做整除,即只得商的整数。 DIV元素是用来为HTML(标准通用标记语言下的一个应用)文档内大块(block-level)的内容提供结构和背景的元素。
子盒子内容不会超出父盒子的范围。当子盒子为绝对定位absolute,fixed等,子盒子不设置固定宽度,此时子盒子的最小宽度就是自身内容的宽度,最大宽度就是父盒子宽度-left偏移量。在不设置子盒子固定宽度的情况下,盒子没有借用版心模块,是因为子盒子内容不会超出父盒子的范围而出现宽度。但是,在平时业务需求中,我们需要的是如果子盒子内容较多,他的宽度和父盒子一样的宽度。
IE5以上的浏览器以及其他的浏览器已经统一了盒模型尺寸的计算方式。即: 实际高度=预设高度+padding-top+padding-bottom margin是不计算在内的。另外你忽略了文字默认的行高。 你得把A的display定义成block,然后加上尺寸。 一般来说。font还有一个默认的行高,也即line-height , 如果不定义高度,默认的a的高度应该是font的行高,而不是font-size的值。综合盒模型高的计算公式,你现在的高度应该是 实际高度=line-height+5px+5px 建议 1定义一下行高。 2或者定义a为block,并加尺寸。(推荐)
意思就是设置成他父元素宽度的400%。
如果是这样并且你希望这个width:400%的元素可以完全显示,最好再加一句,overflow-x:scroll,意思就是长度不够,使用横向滚动条。
以上就是关于用JAVA编写:设计并实现类Box,所包含的实例数据表示盒子的高度、宽度和厚度,一个boolean型实例数据全部的内容,包括:用JAVA编写:设计并实现类Box,所包含的实例数据表示盒子的高度、宽度和厚度,一个boolean型实例数据、如何利用JavaScript调整盒子大小使盒子适应浏览器大小、js 怎样获取div的宽度等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)