javascript - css layout problem, you can use flex
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-19 10:22:11
0
6
550

  • The design draft now looks like this, it supports 1-6 words, centered vertically and horizontally.

  • Text and pictures are obtained from the reading interface.

  • Here comes the difficulty. When there are four characters, two characters will wrap. When there are five characters, two characters will wrap. There are three characters below. When there are six characters, three characters will wrap. . If I limit the range of the text area, it must be the top three characters first, and then the bottom two characters.
    Is there any layout expert who can help me solve this problem?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(6)
phpcn_u1582

Call this function to process the text

function linefeed(text) {
    var l = text.length;
    if (l <= 3) {
        return text
    }
    var cut = Math.floor(l/2);
    return text.slice(0, cut) + '<br>' + text.slice(cut)
}
Ty80

The text and pictures are all taken from the interface

Then make logical judgment directly in js, why should we use css to solve it

过去多啦不再A梦

Style settings

p {
    white-space: nowrap
}

Then in the retrieved data, determine the length of the text. If it is greater than two, add the <br> newline character after the second text

PHPzhong

Use flex vertically and horizontally to set the text p size separately

習慣沉默

Add newline character with js

过去多啦不再A梦


wrap-reverse can reverse the first and second lines

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!