我想让input字段在每个div viz中垂直居中。color-1 color-2 color-3
在每个div或input中使用vertical-align: middle都不起作用。
html, body {
height: 100%;
margin: 0;
padding: 0;
}
input[type="text"] {
width:150px;
height: 30px;
text-align: center;
}
#color-1 {
height: 33%;
background: {{yourName}};
text-align: center;
vertical-align: middle;
}
#color-2{
height: 33%;
background: {{color_2}};
text-align: center;
vertical-align: middle;
}
#color-3{
height: 33%;
background: {{color_3}};
text-align: center;
vertical-align: middle;
}<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div id="color-1">
<input type="text" ng-model="color_1" placeholder="Enter Color #1">
<h1>{{color_1}}</h1>
</div>
<div id="color-2">
<input type="text" ng-model="color_2" placeholder="Enter Color #2">
<h1>{{color_2}}</h1>
</div>
<div id="color-3">
<input type="text" ng-model="color_3" placeholder="Enter Color #3">
<h1>{{color_3}}</h1>
</div>
发布于 2015-07-29 18:40:04
有两种方法可以做到这一点,一种是使用display:flex,另一种是使用需要包装在另一个div中的display:table,display:table-row and display:table-cell。
使用display:flex更好,因为您不需要将模板包装在另一个div中
为所有的颜色div添加类color
“color”类的样式
.color{
height:33%;
display: flex;
justify-content: center;
align-items:center;
}有关更多信息,请参阅此https://css-tricks.com/snippets/css/a-guide-to-flexbox/
发布于 2015-07-29 18:14:32
我做了demo
#color-1
{
height: 33%;
background: {{yourName}};
vertical-align: top;
background: red;
display: flex;
justify-content: center;
flex-direction: column;
}并创建div
align=“中心”
https://stackoverflow.com/questions/31697211
复制相似问题