两个按钮不会在西蒙游戏中居中
two buttons will not center in simon game
如何将 "start" 和 "strict" 按钮调到相同的显示级别(游戏中心的控件)。并将文本居中。每当我减小显示字体的大小时,圆圈(开始,严格)就会出现,反之亦然。我希望这两个按钮与显示屏一致。他们是,但他们不在一个级别。并且按钮内的文本不是垂直居中的。我找遍了 css 规则来垂直对齐文本,找不到它.. 有人可以帮忙吗?谢谢
link 笔:https://codepen.io/zentech/pen/XaYygR
<div class="container">
<div class="header">
<h1>SIMON</h1>
</div>
<div class="simonBoard">
<div class="pad pad-green"></div>
<div class="pad pad-red"></div>
<div class="pad pad-yellow"></div>
<div class="pad pad-blue"></div>
<div class="board-controls">
<div class="title">SIMON</div>
<div class="display inline">00</div>
<div class="start inline">START</div>
<div class="strict inline">STRICT</div>
<div class="switch">
<h3 class="inline">ON</h3>
<div class="outter-switch inline"><div class="inner-switch"></div></div>
<h3 class="inline">OFF</h3>
</div>
</div>
</div>
</div>
风格
body {
background: url("http://cdn.backgroundhost.com/backgrounds/subtlepatterns/purty_wood.png");
font-family: 'Righteous', cursive;
color: black;
}
.container {
margin: 0 auto;
text-align: center;
}
h1 {
font-size: 70px;
}
.simonBoard {
margin: 0 auto;
/* margin-top: 100px; */
border: solid 10px black;
width: 600px;
height: 600px;
border-radius: 600px;
box-shadow: -10px 10px 7px 0px rgba(50, 50, 50, 0.75);
}
.pad {
margin: 0;
float: left;
position: relative;
width: 290px;
height: 290px;
z-index: 8;
border: 5px solid black;
}
.pad-green {
background-color:#0a0;
-moz-border-radius: 300px 0 0 0;
border-radius: 300px 0 0 0;
}
.pad-red {
background-color: red;
-moz-border-radius: 0 300px 0 0;
border-radius: 0 300px 0 0;
}
.pad-yellow {
background-color: yellow;
-moz-border-radius: 0 0 0 300px;
border-radius: 0 0 0 300px;
}
.pad-blue {
background-color: blue;
-moz-border-radius: 0 0 300px 0;
border-radius: 0 0 300px 0;
}
.board-controls {
border: 15px solid black;
height: 245px;
width: 245px;
border-radius: 150px;
background-color: white;
clear: both;
position: absolute;
z-index: 10;
margin-top: 160px;
margin-left: 160px;
-webkit-box-shadow: -6px 8px 5px 0px rgba(50, 50, 50, 0.75);
}
.title {
font-size: 45px;
margin-top: 30px;
font-weight: bold;
}
.inline {
display: inline-block;
}
.display {
margin-left: 0px;
margin-top: 20px;
border: solid 2px black;
border-radius: 10px;
color: white;
width: 60px;
height: 45px;
font-size: 37px;
background-color: #342626;
}
.start {
text-align: center;
margin: 0;
margin-left: 20px;
border: solid 3px black;
width: 50px;
height: 50px;
border-radius: 30px;
color: black;
background-color: darkred;
}
.strict {
text-align: center;
margin: 0px;
margin-left: 20px;
border: solid 3px black;
width: 50px;
height: 50px;
border-radius: 30px;
color: black;
background-color: yellow;
}
.inner-switch {
background-color: gray;
width: 30px;
height: 25px;
position: relative !important;
}
.outter-switch {
margin-top: 20px;
border: solid 2px black;
width: 60px;
height: 25px;
background-color: black;
}
为了让您的按钮对齐,您需要设置 vertical-align
属性。
.inline {
display: inline-block;
vertical-align: middle;
}
要使文本垂直居中,您必须设置父元素的 line-height
属性。
.start, .strict {
line-height: 50px;
}
此外,从 .display
class 中删除 padding-top: 20px
。
如何将 "start" 和 "strict" 按钮调到相同的显示级别(游戏中心的控件)。并将文本居中。每当我减小显示字体的大小时,圆圈(开始,严格)就会出现,反之亦然。我希望这两个按钮与显示屏一致。他们是,但他们不在一个级别。并且按钮内的文本不是垂直居中的。我找遍了 css 规则来垂直对齐文本,找不到它.. 有人可以帮忙吗?谢谢 link 笔:https://codepen.io/zentech/pen/XaYygR
<div class="container">
<div class="header">
<h1>SIMON</h1>
</div>
<div class="simonBoard">
<div class="pad pad-green"></div>
<div class="pad pad-red"></div>
<div class="pad pad-yellow"></div>
<div class="pad pad-blue"></div>
<div class="board-controls">
<div class="title">SIMON</div>
<div class="display inline">00</div>
<div class="start inline">START</div>
<div class="strict inline">STRICT</div>
<div class="switch">
<h3 class="inline">ON</h3>
<div class="outter-switch inline"><div class="inner-switch"></div></div>
<h3 class="inline">OFF</h3>
</div>
</div>
</div>
</div>
风格
body {
background: url("http://cdn.backgroundhost.com/backgrounds/subtlepatterns/purty_wood.png");
font-family: 'Righteous', cursive;
color: black;
}
.container {
margin: 0 auto;
text-align: center;
}
h1 {
font-size: 70px;
}
.simonBoard {
margin: 0 auto;
/* margin-top: 100px; */
border: solid 10px black;
width: 600px;
height: 600px;
border-radius: 600px;
box-shadow: -10px 10px 7px 0px rgba(50, 50, 50, 0.75);
}
.pad {
margin: 0;
float: left;
position: relative;
width: 290px;
height: 290px;
z-index: 8;
border: 5px solid black;
}
.pad-green {
background-color:#0a0;
-moz-border-radius: 300px 0 0 0;
border-radius: 300px 0 0 0;
}
.pad-red {
background-color: red;
-moz-border-radius: 0 300px 0 0;
border-radius: 0 300px 0 0;
}
.pad-yellow {
background-color: yellow;
-moz-border-radius: 0 0 0 300px;
border-radius: 0 0 0 300px;
}
.pad-blue {
background-color: blue;
-moz-border-radius: 0 0 300px 0;
border-radius: 0 0 300px 0;
}
.board-controls {
border: 15px solid black;
height: 245px;
width: 245px;
border-radius: 150px;
background-color: white;
clear: both;
position: absolute;
z-index: 10;
margin-top: 160px;
margin-left: 160px;
-webkit-box-shadow: -6px 8px 5px 0px rgba(50, 50, 50, 0.75);
}
.title {
font-size: 45px;
margin-top: 30px;
font-weight: bold;
}
.inline {
display: inline-block;
}
.display {
margin-left: 0px;
margin-top: 20px;
border: solid 2px black;
border-radius: 10px;
color: white;
width: 60px;
height: 45px;
font-size: 37px;
background-color: #342626;
}
.start {
text-align: center;
margin: 0;
margin-left: 20px;
border: solid 3px black;
width: 50px;
height: 50px;
border-radius: 30px;
color: black;
background-color: darkred;
}
.strict {
text-align: center;
margin: 0px;
margin-left: 20px;
border: solid 3px black;
width: 50px;
height: 50px;
border-radius: 30px;
color: black;
background-color: yellow;
}
.inner-switch {
background-color: gray;
width: 30px;
height: 25px;
position: relative !important;
}
.outter-switch {
margin-top: 20px;
border: solid 2px black;
width: 60px;
height: 25px;
background-color: black;
}
为了让您的按钮对齐,您需要设置 vertical-align
属性。
.inline {
display: inline-block;
vertical-align: middle;
}
要使文本垂直居中,您必须设置父元素的 line-height
属性。
.start, .strict {
line-height: 50px;
}
此外,从 .display
class 中删除 padding-top: 20px
。