I created a custom word generator based on this example code:
<html>
<head>
<title>random words</title>
<style>
#output {
font-family:fantisy;
}
</style>
</head>
<body>
<h2>random word generator</h2>
<div>
<button>generate</button>
</div>
<div>
<div id="output"></div>
<script>
var btn = document.querySelector("button");
var out = document.getElementById("output");
btn.addEventListener("click", getSentence);
function getSentence(){
var theSentence= [
'Pneumonoultramicroscopicsilicovolcanoconiosiseumonoultramicroscopicsilicovolcanoconiosiseumonoultramicroscopicsilicovolcanoconiosiseumonoultramicroscopicsilicovolcanoconiosiseumonoultramicroscopicsilicovolcanoconiosiseumonoultramicroscopicsilicovolcanoconiosiseumonoultramicroscopicsilicovolcanoconiosis',
'A long sentence that doesn\'t wrap correctly, A long sentence that doesn\'t wrap correctly, A long sentence that doesn\'t wrap correctly, A long sentence that doesn\'t wrap correctly, A long sentence that doesn\'t wrap correctly, A long sentence that doesn\'t wrap correctly, A long sentence that doesn\'t wrap correctly.',
];
var sentenceNum = Math.floor(Math.random() * theSentence.length);
output.textContent = theSentence[sentenceNum];
}
</script>
</body>
</html>
My problem is that the output text doesn’t wrap when the viewport is not wide enough. It’s a problem, especially on mobile.
I‘ve tried setting word-wrap or overflow-wrap but that doesn’t work.
How can I make the output wrap?