Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7002949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:59:48+00:00 2026-05-27T20:59:48+00:00

I have a long pre block, I want it to be view in mobile

  • 0

I have a long pre block, I want it to be view in mobile browsers, such as iPhone

e.g.

a very long pre block start here here here here here here here here here here
    2nd line with intent
        3rd line with intent

How to make make the wordwrap, but keep the indentations?

e.g.
    a very long pre block start here here here here here here 
    here here here here
        2nd line with intent
            3rd line with intent

I don’t want to have scrollbar for mobile device, so better to have some way to auto word-wrap the sentence.

The most similar method I have tried is to use CSS

 pre {
            white-space: pre-line;
        }

But not exactly as I want as demonstrated above.

Updated: Link: http://pastehtml.com/view/bisxytioa.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:59:49+00:00Added an answer on May 27, 2026 at 8:59 pm

    Here’s a way to do it with Javascript. This goes through the <pre> and wraps each section in a <div> with padding-left equal to the number of spaces of indentation. In the demo I made the size of the <pre> the size of an iPhone screen to demonstrate the wrapping.

    Demo: jsFiddle

    Script:

    var pre = document.getElementById( 'pre' ),
        sections = pre.textContent.trim().split( '\n' ),
        paddingPerChar = 9;
    
    for( var index=0, html='', padding=0; index < sections.length; index++ ) {
        padding = ( sections[index].length - sections[index].trim().length ) *  paddingPerChar;
        html += '<div style="padding-left:' + padding + 'px;">' + sections[index].trim() + '</div>';
    };
    
    pre.innerHTML = html;
    

    HTML:

    <pre id="pre">
    1. a very long pre block start here here here here here here here here here here
        A. 2nd line with indent long pre block start here here here here here here here here here
            a. 3rd line with indent
        B. 4th line th indent long pre block start here here here here here here here her
        C. 5th line
    2. 6th Line
    </pre>
    

    CSS:

    pre {
        border: 1px solid black;
        height: 460px;
        width: 320px;    
        white-space:pre-wrap;
    }
    

    Output:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very long list in a numpy.array . I want to generate
Apple have long blocked mobile Safari from playing sounds – the usual JavaScript commands
I have a long SQL Script which I run to pre-populate some temp tables.
I have a very long string ( 60MB in size) in which I need
It have source code that contains sections like this: <pre> text </pre> long long
I have HTML code like this: <div id=paragraph> <pre> <p>First Line in the paragraph
Newly registered user here after being a long time lurker! I have an Apache
I have long cycles of GC. from checks I saw there are too many
I have long HTTP request ( generating large Excel file - about 60K records
I have long file with the following list: /drivers/isdn/hardware/eicon/message.c//add_b1() /drivers/media/video/saa7134/saa7134-dvb.c//dvb_init() /sound/pci/ac97/ac97_codec.c//snd_ac97_mixer_build() /drivers/s390/char/tape_34xx.c//tape_34xx_unit_check() (PROBLEM)/drivers/video/sis/init301.c//SiS_GetCRT2Data301() /drivers/scsi/sg.c//sg_ioctl()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.