您可以使用:only-of-type选择器覆盖width属性,如下面的代码段所示.
.container {
width: 200px;
height: 50px;
border: 1px solid red;
}
/* if button is input tag */
input[type='button'] {
float: left;
width: 50%;
border: 1px solid green;
background: blue;
color: white;
}
input[type='button']:only-of-type {
width: 100%;
background: blue;
color: white;
}
/* if button is button tag */
button {
float: left;
width: 50%;
border: 1px solid green;
background: blue;
color: white;
}
button:only-of-type {
width: 100%;
background: blue;
color: white;
}
For Buttons using input tag
For Buttons using buton tag
Button 1
Button 2
Button 1