I'm using flexbox and margin:auto
to center an element both horizontally and vertically within a page. Is it possible to keep the content of this element centered in both axis but allow the text to wrap as it expands?
In the demo below I keep adding text to show how the element soon exceeds the width of the browser window when it's centered this way using flexbox. I want to wrap the text and keep everything on screen. Suggestions?
// \ \ \ \ \ \ \ \ \ TYPE WRITER EFFECT / / / / / / / / / / / / / / / / / / ///
function type( i, t, ie, oe ){
input = document.getElementById( ie ).textContent;
document.getElementById( oe ).textContent += input.charAt( i );
setTimeout(
function(){
(
( i < input.length - 1 ) ? type( i+1, t, ie, oe) : false
);
},
t
);
}
type( 0, 100, 'input', 'output' );
/* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ INITIAL /////////////////////////////// */
html,
body {
height: 100%;
}
body {
display: flex;
flex-wrap: wrap; /* also...this isn't working */
margin: 0;
font-family: sans-serif;
}
p {
margin: auto;
text-align: center;
}
p:nth-child( 2 ) {
display: none;
}
<p id="output"></p>
<!-- \\ \ VERY LONG STRING OF TEXT TO EXTEND PAST SCREEN /////////// // -->
<p id="input">
So I have a long string of text with no spaces. Here I'm using non‑breaking space character entities to simulate that. The problem is I'm using flexbox to center the effected element here, but I don't want all the text to stay on one line like this. There's no spaces, I'm using flexbox, and I want it to wrap. Help?
</p>
ps: flex-wrap: wrap
doesn't seem to be doing the trick. ( it's in my code ).