创建固定填充
Create a fixed padding
当前填充处于流动状态。我想要一个相同大小(固定)的填充。
如果我输入 width 或 box-size.. 文本会溢出。
如何在不丢失 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>
使用 min-width
怎么样?按钮将采用该宽度,除非内部文本的长度需要更多 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 {
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;
}
<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>
或
像以前一样使用 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;
}
<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>
当前填充处于流动状态。我想要一个相同大小(固定)的填充。 如果我输入 width 或 box-size.. 文本会溢出。 如何在不丢失 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>
使用 min-width
怎么样?按钮将采用该宽度,除非内部文本的长度需要更多 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 {
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;
}
<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>
或
像以前一样使用 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;
}
<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>