简体   繁体   中英

How do I center a div element with typed.js

How do I center a div element with typed.js

<script>
    var typed = new Typed('#typed', {
      stringsElement: '#typed-strings'
    });
</script>
<script>
  document.addEventListener('DOMContentLoaded', function() { var typed = new Typed("#typed", { stringsElement:'#typed-strings', typeSpeed: 30, }); });
</script>

<br><br>

<div id="typed-strings">


<p>
text here</p>

</div>
<div id="typed"></div>

I tried to use css to center my div where the text is being typed:

#typed-strings {
  top: 50%;
left: 50%;
border: 4px solid #ecf0f1;
}

If you're looking to center the typed text inside the div:

#typed-strings {
  text-align: center;
}

If you're looking to center the div in the center of the screen:

#typed-strings {
  width: 500px;
  margin: auto 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM