当前填充处于流动状态。我想要一个相同大小(固定)的填充。 如果我把宽度或盒子大小...文本将溢出。 如何在不丢失css效果的情况下进行固定填充。
#buttons {
list-style: none;
}
.first {
background: #f7a63d;
}
@-webkit-keyframes a1 {
0% {
left: -170%;
}
100% {
left: 100%;
}
}
@keyframes a1 {
0% {
left: -170%;
}
100% {
left: 100%;
}
}
.a-1 {
white-space: nowrap;
top: 50%;
left: 50%;
transform: translate(-50%);
display: inline-block;
text-align: center;
padding: 10px 50px;
font-size: 26px;
line-height: 30px;
border-radius: 10px;
position: relative;
cursor: pointer;
border: 0px;
margin: 15px 0px;
transition: 0.5s;
overflow: hidden;
vertical-align: middle;
text-decoration: none;
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2);
color: #8cffadf;
}
.a-1:before {
content: "";
position: absolute;
width: 150%;
height: 20px;
background: rgba(255, 255, 255, 0.125);
box-shadow: 0px 0px 50px rgba(255, 255, 255, 0.35);
top: 10px;
left: -10%;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-animation: a1 2s ease infinite;
animation: a1 2s ease infinite;
}

<ul id="buttons">
<li><a class="a-1 first a-btn-COLOR" href="#">TEST</a></li>
<li><a class="a-1 first a-btn-COLOR" href="#">EXAMPLE</a></li>
<li><a class="a-1 first a-btn-COLOR" href="#">EXAMPLE 2</a></li>
</ul>
&#13;
答案 0 :(得分:1)
如何使用min-width
?按钮将采用该宽度,除非内部文本的长度需要更多空间,在这种情况下按钮将变宽:
#buttons {
list-style: none;
}
.first {
background: #f7a63d;
}
@-webkit-keyframes a1 {
0% {
left: -170%;
}
100% {
left: 100%;
}
}
@keyframes a1 {
0% {
left: -170%;
}
100% {
left: 100%;
}
}
.a-1 {
white-space: nowrap;
top: 50%;
left: 50%;
transform: translate(-50%);
display: inline-block;
text-align: center;
padding: 10px 50px;
font-size: 26px;
line-height: 30px;
border-radius: 10px;
position: relative;
cursor: pointer;
border: 0px;
margin: 15px 0px;
transition: 0.5s;
overflow: hidden;
vertical-align: middle;
text-decoration: none;
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2);
color: #8cffadf;
min-width: 245px; /* I have added it here */
}
.a-1:before {
content: "";
position: absolute;
width: 150%;
height: 20px;
background: rgba(255, 255, 255, 0.125);
box-shadow: 0px 0px 50px rgba(255, 255, 255, 0.35);
top: 10px;
left: -10%;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-animation: a1 2s ease infinite;
animation: a1 2s ease infinite;
}
&#13;
<ul id="buttons">
<li><a class="a-1 first a-btn-COLOR" href="#">TEST</a></li>
<li><a class="a-1 first a-btn-COLOR" href="#">EXAMPLE</a></li>
<li><a class="a-1 first a-btn-COLOR" href="#">EXAMPLE 2</a></li>
<li><a class="a-1 first a-btn-COLOR" href="#">A REALLY REALLY LONG BUTTON</a></li>
</ul>
&#13;
或强>
使用width
样式,但不要通过不更改white-space
样式来阻止内部文本包装:
#buttons {
list-style: none;
}
.first {
background: #f7a63d;
}
@-webkit-keyframes a1 {
0% {
left: -170%;
}
100% {
left: 100%;
}
}
@keyframes a1 {
0% {
left: -170%;
}
100% {
left: 100%;
}
}
.a-1 {
top: 50%;
left: 50%;
transform: translate(-50%);
display: inline-block;
text-align: center;
padding: 10px 50px;
font-size: 26px;
line-height: 30px;
border-radius: 10px;
position: relative;
cursor: pointer;
border: 0px;
margin: 15px 0px;
transition: 0.5s;
overflow: hidden;
vertical-align: middle;
text-decoration: none;
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2);
color: #8cffadf;
width: 245px;
}
.a-1:before {
content: "";
position: absolute;
width: 150%;
height: 20px;
background: rgba(255, 255, 255, 0.125);
box-shadow: 0px 0px 50px rgba(255, 255, 255, 0.35);
top: 10px;
left: -10%;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-animation: a1 2s ease infinite;
animation: a1 2s ease infinite;
}
&#13;
<ul id="buttons">
<li><a class="a-1 first a-btn-COLOR" href="#">TEST</a></li>
<li><a class="a-1 first a-btn-COLOR" href="#">EXAMPLE</a></li>
<li><a class="a-1 first a-btn-COLOR" href="#">EXAMPLE 2</a></li>
<li><a class="a-1 first a-btn-COLOR" href="#">A REALLY REALLY LONG BUTTON</a></li>
</ul>
&#13;