Я не могу центрировать текст на кнопке с CSS - PullRequest
0 голосов
/ 08 мая 2020

Я супер-нуб. Я пытаюсь просто центрировать эти два элемента. Текст и кнопка.

@import url(https://fonts.googleapis.com/css?family=Open+Sans:600);

body {
  font-family: 'Open Sans', sans-serif;
  font-weight: 600;
  font-size: 50px;
  animation-name: example;
  animation-duration: 3s;
  animation-timing-function: ease-in-out;
}

.text {
  position: absolute;
    /* comment */
    display: inline-block;
    text-align: center;
  width: 500px;
  height: 40px;
  top: 20%;
  margin-top: -60px;
}

p {
  display: inline-block;
  vertical-align: top;
  margin:0px;
    text-align: center;
}


.word {
  position: absolute;
  width: 520px;
  opacity: 0;
}


.letter {
  display: inline-block;
  position: relative;
  float: left;
  transform: translateZ(25px);
  transform-origin: 50% 50% 25px;
}

.letter.out {
  transform: rotateX(90deg);
  transition: transform 0.22s cubic-bezier(0.55, 0.055, 0.675, 0.19);
}

.letter.behind {
  transform: rotateX(-90deg);
}

.letter.in {
  transform: rotateX(0deg);
  transition: transform 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.wisteria {
  color: #8e44ad;
}

.belize {
  color: #2980b9;
}

.pomegranate {
  color: #c0392b;
}

.green {
  color: #16a085;
}

.midnight {
  color: #2c3e50;
}

.wrap {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.button {
  min-width: 300px;
  min-height: 80px;
  font-family: 'Open Sans', sans-serif;
  font-size: 22px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  font-weight: 700;
  color: #313133;
  background: #4FD1C5;
  background: linear-gradient(90deg, rgba(129,230,217,1) 0%, rgba(79,209,197,1) 100%);
  border: none;
  border-radius: 1000px;
  box-shadow: 12px 12px 24px rgba(79,209,197,.64);
  transition: all 0.3s ease-in-out 0s;
  cursor: pointer;
  outline: none;
  position: absolute;
  padding: 10px;
  }

button::before {
content: '';
  border-radius: 1000px;
  min-width: calc(300px + 12px);
  min-height: calc(60px + 12px);
  border: 6px solid #00FFCB;
  box-shadow: 0 0 60px rgba(0,255,203,.64);
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: all .3s ease-in-out 0s;
}

.button:hover, .button:focus {
  color: #313133;
  transform: translateY(-6px);
}

button:hover::before, button:focus::before {
  opacity: 0.1;
  color: red;
}

button::after {
  content: '';
  width: 30px; height: 30px;
  border-radius: 100%;
  border: 6px solid #00FFCB;
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: ring 1.5s infinite;
}

button:hover::after, button:focus::after {
  animation: none;
  display: none;
}

@keyframes ring {
  0% {
    width: 30px;
    height: 30px;
    opacity: 1;
  }
  100% {
    width: 300px;
    height: 300px;
    opacity: 0;
  }
}

@keyframes example {
0% {opacity: 0.0}
100% {opacity: 1.0}
</style>```


    ```<body>
    <div class="wrap">
      <button class="button">ENTER</button>
    </div>
    <div class="backstretch animated">
    </div>

    <div class="text">
      <p>Cornerstone is&nbsp;</p>

        <span class="word wisteria">compassionate.</span>
        <span class="word midnight">accomodating.</span>
        <span class="word belize">knowledgable.</span>
        <span class="word pomegranate">attentive.</span>
        <span class="word green">polite.</span>
        <span class="word belize">professional.</span>
        <span class="word wisteria">qualified.</span>
        <span class="word midnight">experienced.</span>
        <span class="word pomegranate">skilled.</span>
        <span class="word green">accessible.</span>
        <span class="word belize">friendly.</span>

        <span class="word wisteria">attentive.</span>
        <span class="word pomegranate">receptive.</span>

        <span class="word green">proficient.</span>
        <span class="word midnight">innovating.</span>



    </div>

Ответы [ 5 ]

0 голосов
/ 08 мая 2020
<style>
 span .word{ 
     text-align:center;
 }
</style>
0 голосов
/ 08 мая 2020

Можно сделать примерно так:

var words = document.getElementsByClassName('word');
var wordArray = [];
var currentWord = 0;

words[currentWord].style.opacity = 1;
for (var i = 0; i < words.length; i++) {
  splitLetters(words[i]);
}

function changeWord() {
  var cw = wordArray[currentWord];
  var nw = currentWord == words.length-1 ? wordArray[0] : wordArray[currentWord+1];
  for (var i = 0; i < cw.length; i++) {
    animateLetterOut(cw, i);
  }

  for (var i = 0; i < nw.length; i++) {
    nw[i].className = 'letter behind';
    nw[0].parentElement.style.opacity = 1;
    animateLetterIn(nw, i);
  }

  currentWord = (currentWord == wordArray.length-1) ? 0 : currentWord+1;
}

function animateLetterOut(cw, i) {
  setTimeout(function() {
        cw[i].className = 'letter out';
  }, i*80);
}

function animateLetterIn(nw, i) {
  setTimeout(function() {
        nw[i].className = 'letter in';
  }, 340+(i*80));
}

function splitLetters(word) {
  var content = word.innerHTML;
  word.innerHTML = '';
  var letters = [];
  for (var i = 0; i < content.length; i++) {
    var letter = document.createElement('span');
    letter.className = 'letter';
    letter.innerHTML = content.charAt(i);
    word.appendChild(letter);
    letters.push(letter);
  }

  wordArray.push(letters);
}

changeWord();
setInterval(changeWord, 2000);
body {
  font-family: 'Open Sans', sans-serif;
  font-weight: 600;
  font-size: 40px;
  animation-name: example;
  animation-duration: 3s;
  animation-timing-function: ease-in-out;
}

p {
  display: inline-block;
  vertical-align: top;
  margin: 0;
  text-align: center;
}

.word {
  position: absolute;
  width: 520px;
  opacity: 0;
}

.letter {
  display: inline-block;
  position: relative;
  float: left;
  transform: translateZ(25px);
  transform-origin: 50% 50% 25px;
}

.letter.out {
  transform: rotateX(90deg);
  transition: transform 0.22s cubic-bezier(0.55, 0.055, 0.675, 0.19);
}

.letter.behind {
  transform: rotateX(-90deg);
}

.letter.in {
  transform: rotateX(0deg);
  transition: transform 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.wisteria {
  color: #8e44ad;
}

.belize {
  color: #2980b9;
}

.pomegranate {
  color: #c0392b;
}

.green {
  color: #16a085;
}

.midnight {
  color: #2c3e50;
}

.wrap {
  display: flex;
  align-items: center;
  text-align: center;
  justify-content: center;
}

.text {
  display: flex;
  width: 100%;
  height: 60px;
  top: 25%;
  margin-top: 60px;
}

.first {
  width: 50%;
  text-align: right;
}

.second {
  width: 50%;
  text-align: left;
}

.button {
  min-width: 300px;
  min-height: 80px;
  font-family: 'Open Sans', sans-serif;
  font-size: 22px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  font-weight: 700;
  color: #313133;
  background: #4FD1C5;
  background: linear-gradient(90deg, rgba(129, 230, 217, 1) 0%, rgba(79, 209, 197, 1) 100%);
  border: none;
  border-radius: 1000px;
  box-shadow: 12px 12px 24px rgba(79, 209, 197, .64);
  transition: all 0.3s ease-in-out 0s;
  cursor: pointer;
  outline: none;
  position: absolute;
  padding: 10px;
}

button::before {
  content: '';
  border-radius: 1000px;
  min-width: calc(300px + 12px);
  min-height: calc(60px + 12px);
  border: 6px solid #00FFCB;
  box-shadow: 0 0 60px rgba(0, 255, 203, .64);
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: all .3s ease-in-out 0s;
}

.button:hover,
.button:focus {
  color: #313133;
  transform: translateY(-6px);
}

button:hover::before,
button:focus::before {
  opacity: 0.1;
  color: red;
}

button::after {
  content: '';
  width: 30px;
  height: 30px;
  border-radius: 100%;
  border: 6px solid #00FFCB;
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: ring 1.5s infinite;
}

button:hover::after,
button:focus::after {
  animation: none;
  display: none;
}

@keyframes ring {
  0% {
    width: 30px;
    height: 30px;
    opacity: 1;
  }
  100% {
    width: 300px;
    height: 300px;
    opacity: 0;
  }
}

@keyframes example {
  0% {
    opacity: 0.0
  }
  100% {
    opacity: 1.0
  }
<head>
  <meta name="format-detection" content="telephone=no" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
  <script src="https://kit.fontawesome.com/2658befe8e.js" crossorigin="anonymous"></script>
  <style type="text/css">
    @import url(https://fonts.googleapis.com/css?family=Open+Sans:600);
  </style>
</head>

<body>
  <div class="wrap">
    <button class="button">ENTER</button>
  </div>
  <div class="backstretch animated">
  </div>

  <div class="text">
    <div class="first">
      <p>Cornerstone is&nbsp;</p>
    </div>
    <div class="second">
      <span class="word wisteria">compassionate.</span>
      <span class="word midnight">accomodating.</span>
      <span class="word belize">knowledgable.</span>
      <span class="word pomegranate">attentive.</span>
      <span class="word green">polite.</span>
      <span class="word belize">professional.</span>
      <span class="word wisteria">qualified.</span>
      <span class="word midnight">experienced.</span>
      <span class="word pomegranate">skilled.</span>
      <span class="word green">accessible.</span>
      <span class="word belize">friendly.</span>

      <span class="word wisteria">attentive.</span>
      <span class="word pomegranate">receptive.</span>

      <span class="word green">proficient.</span>
      <span class="word midnight">innovating.</span>
    </div>






  </div>

  <script>
  </script>
</body>

</html>
0 голосов
/ 08 мая 2020

Вы пытаетесь сделать что-то подобное?

HTML

<div class="wrap">
      <button class="button">ENTER</button>

    <div class="backstretch animated">
    </div>

    <div class="text">
      <p>Cornerstone is&nbsp;</p>

        <span class="word wisteria">compassionate.</span>
        <span class="word midnight">accomodating.</span>
        <span class="word belize">knowledgable.</span>
        <span class="word pomegranate">attentive.</span>
        <span class="word green">polite.</span>
        <span class="word belize">professional.</span>
        <span class="word wisteria">qualified.</span>
        <span class="word midnight">experienced.</span>
        <span class="word pomegranate">skilled.</span>
        <span class="word green">accessible.</span>
        <span class="word belize">friendly.</span>

        <span class="word wisteria">attentive.</span>
        <span class="word pomegranate">receptive.</span>

        <span class="word green">proficient.</span>
        <span class="word midnight">innovating.</span>
    </div>

CSS

@import url(https://fonts.googleapis.com/css?family=Open+Sans:600);

body {
  font-family: 'Open Sans', sans-serif;
  font-weight: 600;
  font-size: 50px;
  animation-name: example;
  animation-duration: 3s;
  animation-timing-function: ease-in-out;
}

.text {
  position: absolute;
    /* comment */
    display: inline-block;
    text-align: center;
  width: 500px;
  height: 40px;
  top: 40%;
  margin-top: -60px;
}

p {
  display: inline-block;
  vertical-align: top;
  margin:0px;
    text-align: center;
}


.word {
  position: absolute;
  width: 520px;
  opacity: 0;
}


.letter {
  display: inline-block;
  position: relative;
  float: left;
  transform: translateZ(25px);
  transform-origin: 50% 50% 25px;
}

.letter.out {
  transform: rotateX(90deg);
  transition: transform 0.22s cubic-bezier(0.55, 0.055, 0.675, 0.19);
}

.letter.behind {
  transform: rotateX(-90deg);
}

.letter.in {
  transform: rotateX(0deg);
  transition: transform 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.wisteria {
  color: #8e44ad;
}

.belize {
  color: #2980b9;
}

.pomegranate {
  color: #c0392b;
}

.green {
  color: #16a085;
}

.midnight {
  color: #2c3e50;
}







.wrap {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.button {
  min-width: 300px;
  min-height: 80px;
  font-family: 'Open Sans', sans-serif;
  font-size: 22px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  font-weight: 700;
  color: #313133;
  background: #4FD1C5;
  background: linear-gradient(90deg, rgba(129,230,217,1) 0%, rgba(79,209,197,1) 100%);
  border: none;
  border-radius: 1000px;
  box-shadow: 12px 12px 24px rgba(79,209,197,.64);
  transition: all 0.3s ease-in-out 0s;
  cursor: pointer;
  outline: none;
  position: absolute;
  top: 50%;
  padding: 10px;
  }

button::before {
content: '';
  border-radius: 1000px;
  min-width: calc(300px + 12px);
  min-height: calc(60px + 12px);
  border: 6px solid #00FFCB;
  box-shadow: 0 0 60px rgba(0,255,203,.64);
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: all .3s ease-in-out 0s;
}

.button:hover, .button:focus {
  color: #313133;
  transform: translateY(-6px);
}

button:hover::before, button:focus::before {
  opacity: 0.1;
  color: red;
}

button::after {
  content: '';
  width: 30px; height: 30px;
  border-radius: 100%;
  border: 6px solid #00FFCB;
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: ring 1.5s infinite;
}

button:hover::after, button:focus::after {
  animation: none;
  display: none;
}

@keyframes ring {
  0% {
    width: 30px;
    height: 30px;
    opacity: 1;
  }
  100% {
    width: 300px;
    height: 300px;
    opacity: 0;
  }
}

@keyframes example {
0% {opacity: 0.0}
100% {opacity: 1.0}

Пример кода

0 голосов
/ 08 мая 2020

Поскольку ваш .button имеет position:absolute, вы можете добавить для него значение top, left как

.button {
  min-width: 300px;
  min-height: 80px;
  font-family: 'Open Sans', sans-serif;
  font-size: 22px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  font-weight: 700;
  color: #313133;
  background: #4FD1C5;
  background: linear-gradient(90deg, rgba(129,230,217,1) 0%, rgba(79,209,197,1) 100%);
  border: none;
  border-radius: 1000px;
  box-shadow: 12px 12px 24px rgba(79,209,197,.64);
  transition: all 0.3s ease-in-out 0s;
  cursor: pointer;
  outline: none;
  position: absolute;
  padding: 10px;
  top: 5%;
  left: 40%;
  }

JSFiddle https://jsfiddle.net/viethien/6msqnc9w/3/

0 голосов
/ 08 мая 2020

, если вы хотите использовать абсолютное позиционирование, попробуйте добавить это в свой класс «.button».

Css:

margin-left: 50%;

Также, если вы хотите применить ваш. класс кнопки ко всем кнопкам, просто удалите символ "." от начала ".button" в вашем css.

Надеюсь, это поможет.

EDIT:

Чтобы центрировать ваш класс .text, сделайте следующее:

HTML:

<div class="text">
      <p>Cornerstone is&nbsp;

        <span class="word wisteria">compassionate.</span>
        <span class="word midnight">accomodating.</span>
        <span class="word belize">knowledgable.</span>
        <span class="word pomegranate">attentive.</span>
        <span class="word green">polite.</span>
        <span class="word belize">professional.</span>
        <span class="word wisteria">qualified.</span>
        <span class="word midnight">experienced.</span>
        <span class="word pomegranate">skilled.</span>
        <span class="word green">accessible.</span>
        <span class="word belize">friendly.</span>

        <span class="word wisteria">attentive.</span>
        <span class="word pomegranate">receptive.</span>

        <span class="word green">proficient.</span>
        <span class="word midnight">innovating.</span>


      </p>
    </div>

CSS:

.text { text-align: center }

Кроме того, если вы хотите придать .text больший вид блока y, вы можете установить поля -left и margin-right для .text в css, пока они имеют одно и то же значение .text останется по центру. Не забудьте избавиться от первых двух строк .text, которые у вас есть прямо сейчас (display: inline-block и position: absolute).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...