1
我使用flexbox和margin:auto
将元素在页面中水平和垂直居中放置。是否可以保持这个元素的内容在两个轴中居中,但允许文本在展开时换行?允许Flexbox中的中心项目包装
在下面的演示中,我一直使用flexbox添加文本以显示元素很快超过浏览器窗口的宽度。我想包装文本并将所有内容保存在屏幕上。建议?
// \ \ \ \ \ \ \ \ \ 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
似乎并没有做的伎俩。 (它在我的代码中)。
嗯......我知道这一点。大声笑。谢谢。 – savant
@savant哈哈,你打赌:) –
我尝试过'换行:断字'。 – savant