Sunday, October 14, 2018

stackoverflow - if you're smart enough to ask the questions, it has the answers (e.g. putting breaks in <pre> tags)

I'm revamping my ancient loveblender site. One thing I use there is Ye Olde <pre> Tags - offering my authors precisely finessed spacing control. (And back in the day, giving my site a kind of fun typewritten look.)

Honestly, I think some users use it who don't need to - in particular one author who wrote very long lines that would break the now-shared page. So I figured there might be a way of getting most of the benefits of a <pre> tag but still breaking super-long lines, and sure enough stackoverflow had the answer:

pre {
    white-space: pre-wrap; /* CSS3 */
    white-space: -moz-pre-wrap; /* Mozilla, post millennium */
    white-space: -pre-wrap; /* Opera 4-6 */
    white-space: -o-pre-wrap; /* Opera 7 */
    word-wrap: break-word; /* Internet Explorer 5.5+ */

Stackoverflow has so many answers - in many cases, the problem is just knowing the question. I think this is true in general, for languages you're not using every day, it's ok just to know the concepts, and make good guesses as to what commands are likely available already. Sometimes it seems embarrassing how I write all my personal sites in PHP (as I've said before, not as dumb as it sounds) but how few commands there are that I don't end up looking up. (Then again, I had my own cheatsheet for tropes in Perl...)

No comments:

Post a Comment