盒子模型BoxApp
HTML5实现盒子模型显示
<!DOCTYPE html>
<html>
<head>
<metacharset="utf-8">
<title></title>
<style>
.height50 {
height:50px;
}
.height400 {
height:400px;
}
.height300 {
height:300px;
}
.height200 {
height:200px;
}
.height100 {
height:100px;
}
.width400 {
width:400px;
}
.bgred {
background-color:#6AC5AC;
}
.bggreen {
background-color:#414142;
}
.bgyellow {
background-color:#D64078;
}
.box {
display: flex;
flex-direction: column;
flex:1;
position: relative;
color:#FDC72F;
line-height:1em;
}
.label {
top:0;
left:0;
padding:03px3px0;
position: absolute;
background-color:#FDC72F;
color: white;
line-height:1em;
}
.top {
width:100%;
justify-content: center;
display: flex;
align-items: center;
}
.bottom {
width:100%;
display: flex;
justify-content: center;
align-items: center;
}
.right {
width:50px;
display: flex;
justify-content: space-around;
align-items: center;
}
.left {
width:50px;
display: flex;
justify-content: space-around;
align-items: center;
}
.heightdashed {
position: absolute;
right:20px;
height:100%;
border-left:1px solid #FDC72F;
}
.widthdashed {
position: absolute;
left:0px;
width:100%;
bottom:24px;
border-top:1px solid #FDC72F;
}
.margginBox {
position:absolute;
top:100px;
padding-left:7px;
padding-right:7px;
}
.borderBox {
flex:1;
display: flex;
justify-content: space-between;
}
.paddingBox {
flex:1;
display: flex;
justify-content: space-between;
}
.elementBox{
flex:1;
display: flex;
justify-content: space-between;
}
.measureBox {
flex:1;
display: flex;
justify-content: flex-end;
align-items: flex-end;
}
</style>
</head>
<body>
<spanclass="margginBox">
<spanclass="box height400 width400">
<spanclass="label">
margin
</span>
<spanclass="top height50 bgred">
top
</span>
<spanclass="borderBox">
<spanclass="left bgred">
left
</span>
<spanclass="box height300 ">
<spanclass="label">
border
</span>
<spanclass="top height50 bggreen">
top
</span>
<spanclass="paddingBox">
<spanclass="left bggreen">
left
</span>
<spanclass="box height200 ">
<spanclass="label">
padding
</span>
<spanclass="top height50 bgyellow">
top
</span>
<spanclass="elementBox">
<spanclass="left bgyellow">
left
</span>
<spanclass="box height100 ">
<spanclass="label">
element
</span>
<spanclass="widthdashed">
</span>
<spanclass="heightdashed">
</span>
<spanclass="measureBox">
<spanclass="right">
height
</span>
</span>
<spanclass="bottom height50">
width
</span>
</span>
<spanclass="right bgyellow">
right
</span>
</span>
<spanclass="bottom height50 bgyellow">
bottom
</span>
</span>
<spanclass="right bggreen">
right
</span>
</span>
<spanclass="bottom height50 bggreen">
bottom
</span>
</span>
<spanclass="right bgred">
right
</span>
</span>
<spanclass="bottom height50 bgred">
bottom
</span>
</span>
</span>
</body>
</html>
React Native实现盒子模型显示
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
importReact,{
AppRegistry,
Component,
StyleSheet,
Text,
View
}from'react-native';
classDongFangextendsComponent{
render(){
return(
<View style={[BoxStyles.margginBox]}ref="lab1">
<View style={[BoxStyles.box,BoxStyles.height400,BoxStyles.width400]}>
<View style={[BoxStyles.top,BoxStyles.height50,BoxStyles.bgred]}>
<Text style={BoxStyles.yellow}>top</Text></View>
<View style={[BoxStyles.borderBox]}>
<View style={[BoxStyles.left,BoxStyles.bgred]}>
<Text style={BoxStyles.yellow}>left</Text></View>
<View style={[BoxStyles.box,BoxStyles.height300]}>
<View style={[BoxStyles.top,BoxStyles.height50,BoxStyles.bggreen]}>
<Text style={BoxStyles.yellow}>top</Text></View>
<View style={[BoxStyles.paddingBox]}>
<View style={[BoxStyles.left,BoxStyles.bggreen]}>
<Text style={BoxStyles.yellow}>left</Text></View>
<View style={[BoxStyles.box,BoxStyles.height200]}>
<View style={[BoxStyles.top,BoxStyles.height50,BoxStyles.bgyellow]}>
<Text style={BoxStyles.yellow}>top</Text></View>
<View style={[BoxStyles.elementBox]}>
<View style={[BoxStyles.left,BoxStyles.bgyellow]}>
<Text style={BoxStyles.yellow}>left</Text></View>
<View style={[BoxStyles.box,BoxStyles.height100]}>
<View style={[BoxStyles.label]}>
<Text style={BoxStyles.white}>element</Text></View>
<View style={[BoxStyles.widthdashed]}></View>
<View style={[BoxStyles.heightdashed]}></View>
<View style={[BoxStyles.measureBox]}>
<View style={[BoxStyles.right]}>
<Text style={[BoxStyles.yellow]}>height</Text></View>
</View>
<View style={[BoxStyles.bottom,BoxStyles.height50]}>
<Text style={BoxStyles.yellow}>width</Text></View>
</View>
<View style={[BoxStyles.right,BoxStyles.bgyellow]}><Text style={BoxStyles.yellow}>right</Text></View>
</View>
<View style={[BoxStyles.bottom,BoxStyles.height50,BoxStyles.bgyellow]}>
<Text style={BoxStyles.yellow}>bottom</Text></View>
<View style={[BoxStyles.label]}>
<Text style={BoxStyles.white}>padding</Text></View>
</View>
<View style={[BoxStyles.right,BoxStyles.bggreen]}><Text style={BoxStyles.yellow}>right</Text></View>
</View>
<View style={[BoxStyles.bottom,BoxStyles.height50,BoxStyles.bggreen]}>
<Text style={BoxStyles.yellow}>bottom</Text></View>
<View style={[BoxStyles.label]}><Text style={BoxStyles.white}>border</Text></View>
</View>
<View style={[BoxStyles.right,BoxStyles.bgred]}>
<Text style={BoxStyles.yellow}>right</Text></View>
</View>
<View style={[BoxStyles.bottom,BoxStyles.height50,BoxStyles.bgred]}>
<Text style={BoxStyles.yellow}>bottom</Text></View>
<View style={[BoxStyles.label]}><Text style={BoxStyles.white}>margin</Text></View>
</View>
</View>
);
}
}
constBoxStyles=StyleSheet.create({
height50:{
height:50,
},
height400:{
height:400,
},
height300:{
height:300,
},
height200:{
height:200,
},
height100:{
height:100,
},
width400:{
width:400,
},
width300:{
width:300,
},
width200:{
width:200,
},
width100:{
width:100,
},
bgred:{
backgroundColor:'#6AC5AC',
},
bggreen:{
backgroundColor:'#414142',
},
bgyellow:{
backgroundColor:'#D64078',
},
box:{
flexDirection:'column',
flex:1,
position:'relative',
},
label:{
top:0,
left:0,
paddingTop:0,
paddingRight:3,
paddingBottom:3,
paddingLeft:0,
position:'absolute',
backgroundColor:'#FDC72F',
},
top:{
justifyContent:'center',
alignItems:'center',
},
bottom:{
justifyContent:'center',
alignItems:'center',
},
right:{
width:50,
justifyContent:'space-around',
alignItems:'center',
},
left:{
width:50,
justifyContent:'space-around',
alignItems:'center',
},
heightdashed:{
bottom:0,
top:0,
right:20,
borderLeftWidth:1,
position:'absolute',
borderLeftColor:'#FDC72F',
},
widthdashed:{
bottom:25,
left:0,
right:0,
borderTopWidth:1,
position:'absolute',
borderTopColor:'#FDC72F',
},
yellow:{
color:'#FDC72F',
fontWeight:'900',
},
white:{
color:'white',
fontWeight:'900',
},
margginBox:{
position:'absolute',
top:100,
paddingLeft:7,
paddingRight:7,
},
borderBox:{
flex:1,
justifyContent:'space-between',
flexDirection:'row',
},
paddingBox:{
flex:1,
justifyContent:'space-between',
flexDirection:'row',
},
elementBox:{
flex:1,
justifyContent:'space-between',
flexDirection:'row',
},
measureBox:{
flex:1,
flexDirection:'row',
justifyContent:'flex-end',
alignItems:'flex-end',
},
container:{
flex:1,
justifyContent:'center',
alignItems:'center',
backgroundColor:'#F5FCFF',
},
welcome:{
fontSize:20,
textAlign:'center',
margin:10,
},
instructions:{
textAlign:'center',
color:'#333333',
marginBottom:5,
},
});
AppRegistry.registerComponent('DongFang',()=>DongFang);
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
importReact,{
AppRegistry,
Component,
StyleSheet,
Text,
View
}from'react-native';
classBoxextendsComponent{
render(){
return(
<View style={[BoxStyles.box,BoxStyles[this.props.width],BoxStyles[this.props.height]]}>
<View style={[BoxStyles.top,BoxStyles.height50,BoxStyles[this.props.classBg]]}><Text>top</Text></View>
<View style={[BoxStyles[this.props.childName]]}>
<View style={[BoxStyles.left,BoxStyles[this.props.classBg]]}><Text>left</Text></View>
{this.props.children}
<View style={[BoxStyles.right,BoxStyles[this.props.classBg]]}><Text>right</Text></View>
</View>
<View style={[BoxStyles.bottom,BoxStyles.height50,BoxStyles[this.props.classBg]]}><Text>bottom</Text></View>
<View style={[BoxStyles.label]}><Text>{this.props.boxName}</Text></View>
</View>
)
}
}
classMargginBoxextendsComponent{
render(){
return(
<View style={[BoxStyles.margginBox]}>
<Box childName="borderBox" height="height400" width="width400" boxName="margin" classBg="bgred">{this.props.children}</Box>
</View>
)
}
}
classBorderBoxextendsComponent{
render(){
return(
<Box childName="paddingBox" height="height300" width="width300" boxName="border" classBg="bggreen">{this.props.children}</Box>
)
}
}
classPaddingBoxextendsComponent{
render(){
return(
<Box childName="elementBox" height="height200" width="width200" boxName="padding" classBg="bgyellow">{this.props.children}</Box>
)
}
}
classElementBoxextendsComponent{
render(){
return(
<View style={[BoxStyles.box,BoxStyles.height100]}>
<View style={[BoxStyles.measureBox]}>
<View style={[BoxStyles.right]}><Text>height</Text></View>
</View>
<View style={[BoxStyles.bottom,BoxStyles.height50]}><Text>width</Text></View>
<View style={[BoxStyles.label]}><Text>element</Text></View>
<View style={[BoxStyles.widthdashed]}></View>
<View style={[BoxStyles.heightdashed]}></View>
</View>
)
}
}
classDongFangextendsComponent{
render(){
return(
<MargginBox>
<BorderBox>
<PaddingBox>
<ElementBox>
</ElementBox>
</PaddingBox>
</BorderBox>
</MargginBox>
)
}
}
constBoxStyles=StyleSheet.create({
height50:{
height:50,
},
height400:{
height:400,
},
height300:{
height:300,
},
height200:{
height:200,
},
height100:{
height:100,
},
width400:{
width:400,
},
width300:{
width:300,
},
width200:{
width:200,
},
width100:{
width:100,
},
bgred:{
backgroundColor:'#6AC5AC',
},
bggreen:{
backgroundColor:'#414142',
},
bgyellow:{
backgroundColor:'#D64078',
},
box:{
flexDirection:'column',
flex:1,
position:'relative',
},
label:{
top:0,
left:0,
paddingTop:0,
paddingRight:3,
paddingBottom:3,
paddingLeft:0,
position:'absolute',
backgroundColor:'#FDC72F',
},
top:{
justifyContent:'center',
alignItems:'center',
},
bottom:{
justifyContent:'center',
alignItems:'center',
},
right:{
width:50,
justifyContent:'space-around',
alignItems:'center',
},
left:{
width:50,
justifyContent:'space-around',
alignItems:'center',
},
heightdashed:{
bottom:0,
top:0,
right:20,
borderLeftWidth:1,
position:'absolute',
borderLeftColor:'#FDC72F',
},
widthdashed:{
bottom:25,
left:0,
right:0,
borderTopWidth:1,
position:'absolute',
borderTopColor:'#FDC72F',
},
yellow:{
color:'#FDC72F',
fontWeight:'900',
},
white:{
color:'white',
fontWeight:'900',
},
margginBox:{
position:'absolute',
top:100,
paddingLeft:7,
paddingRight:7,
},
borderBox:{
flex:1,
justifyContent:'space-between',
flexDirection:'row',
},
paddingBox:{
flex:1,
justifyContent:'space-between',
flexDirection:'row',
},
elementBox:{
flex:1,
justifyContent:'space-between',
flexDirection:'row',
},
measureBox:{
flex:1,
flexDirection:'row',
justifyContent:'flex-end',
alignItems:'flex-end',
},
container:{
flex:1,
justifyContent:'center',
alignItems:'center',
backgroundColor:'#F5FCFF',
},
welcome:{
fontSize:20,
textAlign:'center',
margin:10,
},
instructions:{
textAlign:'center',
color:'#333333',
marginBottom:5,
},
});
AppRegistry.registerComponent('DongFang',()=>DongFang);
posted @
2016-04-10 20:10
星空守候
阅读(
345)
评论()
编辑
收藏
举报