我已经使用CSS制作了以下按钮:Screenshot of the buttons
使用以下CSS代码:
.boton-cabezera {
position: relative;
display: inline-block;
margin: 0px 8px 15px;
}
.boton-cabezera a {
color: white;
font-family: Helvetica, sans-serif;
font-weight: bold;
font-size: 14px;
text-align: center;
text-decoration: none;
background-color: #FFA12B;
display: block;
position: relative;
padding: 12px 12px;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
text-shadow: 0px 1px 0px #000;
filter: dropshadow(color=#000, offx=0px, offy=1px);
-webkit-box-shadow: inset 0 1px 0 #FFE5C4, 0 10px 0 #915100;
-moz-box-shadow: inset 0 1px 0 #FFE5C4, 0 10px 0 #915100;
box-shadow: inset 0 1px 0 #FFE5C4, 0 10px 0 #915100;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.boton-cabezera a:active {
top: 10px;
background-color: #F78900;
-webkit-box-shadow: inset 0 1px 0 #FFE5C4, inset 0 -3px 0 #915100;
-moz-box-shadow: inset 0 1px 0 #FFE5C4, inset 0 -3pxpx 0 #915100;
box-shadow: inset 0 1px 0 #FFE5C4, inset 0 -3px 0 #915100;
}
.boton-cabezera:after {
content: "";
height: 100%;
width: 100%;
padding: 4px;
position: absolute;
bottom: -14px;
left: -4px;
z-index: -1;
background-color: #2B1800;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
要创建按钮,您只需要创建一个带有类“ boton-cabezera”的'div'并添加一个'a'标签。
按下按钮时,外观如下:Screenshot of button pressed.
我为扫雷游戏做了这个按钮。
我的问题是,游戏中使用的按钮之一看起来不像我的其他按钮。我认为这是z-index问题,但我似乎无法自行解决。
我制作了一个模态,要求玩家在结束游戏时要求其名字。Screenshot of the modal and the button.如您所见,在SS中,按钮看起来不像标题中的按钮。它没有那种按钮容器的外观。我在CSS中包含的“:after”在这里似乎不起作用。
这是模式CSS代码:
.mensaje-bg {
/*El display se cambia a block con jquery*/
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100vh;
background-color: rgba(0, 0, 0, 0.4);
}
.mensaje {
background-color: #f4f4f4;
margin: 12% auto;
padding: 20px;
width: 380px;
height: 260px;
border: solid #0f0f0f 2px;
border-radius: 3px;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
border-bottom: solid 5px black;
}
这是模式部分的HTML代码:
<div id="mensaje-bg" class="mensaje-bg">
<div class="mensaje">
<estado-carita id="emoji">
<i class="fas fa-frown"></i>
</estado-carita>
<estado-final id="estado-final">
¡Perdiste!
</estado-final>
<tiempo-total id="tiempo-total">
Tu tiempo fue de 00:00 en dificultad media.
</tiempo-total>
<label id="label-nombre" for="nombre">¿Cual es tu nombre?</label>
<input id="j" type="text" placeholder="Tu nombre">
<div class="boton-cabezera">
<a href="#" id="siguiente" class="nuevo_juego">
Siguiente
<i class="fas fa-arrow-right">
</i>
</a>
</div>
</div>
</div>
基本上,您需要为z-index:1
样式指定boton-cabezera a
,还需要为z-index:0
样式设置.boton-cabezera:after
.boton-cabezera a {
/*...Other Styles...*/
z-index: 1;
}
.boton-cabezera:after {
/*...Other Styles...*/
z-index: 0;
}