StoopidNerd
StoopidNerd

Reputation: 15

Create a fixed padding

The current padding is in fluid. I want a same-sized(fixed) padding. If i put width or box-size..the text will overflow. How do i make a fixed padding without losing the css effect.

#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>

Upvotes: 1

Views: 59

Answers (1)

George
George

Reputation: 36786

How about using a min-width? The buttons will take on that width, unless length of the text inside requires more space, in which case the button will become wider:

#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>

Or

Use the width style, as you were, but don't prevent the text inside from wrapping, by not changing the white-space style:

#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>

Upvotes: 1

Related Questions