Random Quote Generator
Tutorial: https://freshman.tech/random-quote-machine/
by Ayo Isaiah
HTML
<div class="app">
<header>Random Donald Trump Quotes</header>
<section class="quotes">
<div class="quote-text" id="js-quote-text"></div>
</section>
<section class="controls">
<button type="button" id="js-new-quote" class="new-quote button">
Generate a new quote
</button>
<a class="twitter button" id="js-tweet" target="_blank" rel="noreferrer">Tweet it!</a>
</section>
</div>
CSS
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
background-color: #c9bd95;
}
.app {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 600px;
background-color: white;
border-radius: 5px;
box-shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.12);
}
header {
width: 100%;
font-size: 30px;
text-align: center;
padding: 10px;
border-bottom: 1px solid #ebebeb;
}
.quotes {
padding: 20px 50px;
min-height: 200px;
}
.quote-text {
padding-bottom: 20px;
font-size: 25px;
color: black;
}
.controls {
width: 100%;
padding: 20px 50px;
}
.button {
display: block;
color: white;
border-radius: 4px;
border: none;
padding: 10px 20px;
cursor: pointer;
text-align: center;
width: 100%;
font-size: 20px;
box-shadow: 0 2px 2px 0 rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.2), 0 1px 5px 0 rgba(0,0,0,.12);
}
.twitter {
background-color: #1da1f2;
text-decoration: none;
}
.twitter:hover {
background-color: #1e7fbb;
}
.new-quote {
background-color: #4A2B0F;
margin-bottom: 15px;
}
.new-quote:hover {
background-color: #6d3b0e;
}
.new-quote:disabled {
background-color: #cccccc;
color: #666666;
cursor: not-allowed;
}
@media screen and (max-width: 600px) {
.app {
width: 100%;
}
.quote-text {
font-size: 18px;
}
}
JavaScript
const newQuoteButton = document.querySelector('#js-new-quote');