1

How to write the HTML code for displaying the text in the webpage which should fit to the screen? I tried to write HTML code for that, but it doesn't show me the content within the screen. Simply it extends the screen width and make the scrollbar in the footer till the text ends.

E.g

<body>
Lorem ipsum dolor sit amet, convallis nec fermentum mauris at ut ipsum, velit lobortis netus phasellus, tincidunt suscipit, pede fusce neque, et ipsum in ac aenean. Vulputate id, in odio, aliquam libero rutrum integer sit turpis, laborum id duis wisi vel, volutpat amet morbi in.</body>

These many of lines should fit to the screen, it should not create any horizontal scrollbar.

halfer
  • 19,824
  • 17
  • 99
  • 186
dinesh
  • 11
  • 1
  • 2

2 Answers2

1

You should use css word wrap property..

p.test {
    word-wrap: break-word;
}

Here p is your element of html in which you wrote the code and test is the class...

p.test {
    word-wrap: break-word;
}
<p class="test">
  sadasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasassaddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsaddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsad
  </p>

A opposed to

<p class="test">
  sadasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasassaddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsaddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsad
  </p>
Captain Man
  • 6,997
  • 6
  • 48
  • 74
Tirthraj Barot
  • 2,671
  • 2
  • 17
  • 33
0

Put your content in div and provide width to that div. For eg.

    <div style="width: 100px">
      sadasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasassaddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsaddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsad
    </div>
Sachin Bahal
  • 138
  • 1
  • 3
  • 14