概述
软键盘用来模拟真实键盘,我们知道键盘中一些特殊符号键的大小和普通字符键的大小是不一样的,例如空格键。但一般各个键间距是一样的,这样的一种布局适合用flex布局来实现。
我们实现一个简单的例子:
我们实现上述图片布局。代码如下:
<html>
<head>
<style type="text/css">
#app{
width: 800px;
height: 300px;
outline: red dotted 3px;
}
#line_1{
width: 800px;
height: 100px;
display: flex; /*flex 布局*/
}
#line_2{
width: 800px;
height: 100px;
margin-top: 10px;
display: flex;
}
.line1Style{
height: 100px;
background-color: grey;
color: greenyellow;
text-align: center; /*字符水平居中*/
line-height: 100px; /*字符垂直居中*/
margin-right: 5px; /*各个item直接间距*/
flex-shrink: 0; /*不进行缩放*/
}
.line2Style{
height: 100px;
background-color: grey;
color: greenyellow;
text-align: center;
line-height: 100px;
margin-right: 5px;
flex-shrink: 0;
}
</style>
</head>
<body>
<script src="./vue.js"></script>
<div id="app">
<div id="line_1">
<div :id="'line_1_' + i" class="line1Style" :style="line1StyleD()" v-for="(item, i) in listData1">{{item}}</div>
</div>
<div id="line_2">
<div :id="'line_2_' + i" class="line2Style" :style="line2StyleD(i)" v-for="(item, i) in listData2">{{item}}</div>
</div>
</div>
<script>
var app = new Vue({
data : function(){
return {
listData1 : ["Q", "W", "E", "R", "T", "Y", "U"],
listData2 : ["B", "Z", "X", "Space", "N", "M"]
}
},
methods : {
line1StyleD : function(){
return{
width : "100px" //所有item 宽度为100px
}
},
line2StyleD : function(i){
if(i === 3){
return{
width : "205px" //Space 这个item宽度为其他item的1倍
}
}else{
return{
width : "100px"
}
}
}
}
}).$mount("#app");
</script>
</body>
</html>
最后
以上就是沉默往事为你收集整理的用flex布局实现软键盘的全部内容,希望文章能够帮你解决用flex布局实现软键盘所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复