-1

I am trying to display text inside a container. The value of the text itself is formatted but when I add it to the block the format is condensed and it overflows past the box.

How can I keep the format of the text as well as add a scrollbar in the container to keep it from overflowing?

enter image description here

The span value as shown escapes the container but if you look above in the grey area the value itself is formatted correctly upon inspection

enter image description here

Snippet:

.container-card {
  /* Add shadows to create the "card" effect */
  box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
  height: 20vh;
}
<div class="container">
  <span style="overflow: scroll !important;">Some text</span>
</div>
webta.st.ic
  • 4,781
  • 6
  • 48
  • 98
Jebathon
  • 4,310
  • 14
  • 57
  • 108
  • add the `overflow: scroll` to the `.container-card` not the `span`. – Manuel Otto May 01 '18 at 14:09
  • First of all, you can't keep the formatted markup as you've written it, browser will parse HTML and display it as plain text. Check here if you want to display it as code: https://stackoverflow.com/questions/37789148/how-to-display-html-code-in-a-html-page-in-a-formatted-manner – appostolis May 01 '18 at 14:11

2 Answers2

3

use overflow-y for the container not the span, and use <pre> to display formatted code :

.container {
    /* Add shadows to create the "card" effect */
    box-shadow: 0 2px 2px 0 rgba(0,0,0,0.2);
    transition: 0.3s;
    height: 50vh;
    overflow-y: scroll;
}
<div class="container">
<pre>
DECLARE N INTEGER;
 SET N = 1;
 FOR C 
 AS C_USR_MISE_A_JOUR 
    CURSOR FOR 
       SELECT USR_ID, USR_NOM
       FROM   T_UTILISATEUR_USR
       ORDER  BY USR_ID
    FOR UPDATE OF USR_NOM
 DO
    IF MOD(N, 2) = 0
    THEN
       UPDATE T_UTILISATEUR_USR
       
DECLARE N INTEGER;
 SET N = 1;
 FOR C 
 AS C_USR_MISE_A_JOUR 
    CURSOR FOR 
       SELECT USR_ID, USR_NOM
       FROM   T_UTILISATEUR_USR
       ORDER  BY USR_ID
    FOR UPDATE OF USR_NOM
 DO
    IF MOD(N, 2) = 0
    THEN
       UPDATE T_UTILISATEUR_USR

DECLARE N INTEGER;
 SET N = 1;
 FOR C 
 AS C_USR_MISE_A_JOUR 
    CURSOR FOR 
       SELECT USR_ID, USR_NOM
       FROM   T_UTILISATEUR_USR
       ORDER  BY USR_ID
    FOR UPDATE OF USR_NOM
 DO
    IF MOD(N, 2) = 0
    THEN
       UPDATE T_UTILISATEUR_USR
</pre>
</div>
Taki
  • 17,320
  • 4
  • 26
  • 47
2

You can use pre to keep the formatting and then set the overflow to scroll

I made a codepen example here

The first block of lorem ipsum is styled, the next is default pre to show how it looks without any styling.

Is this what you want?

Marc Hjorth
  • 1,797
  • 2
  • 18
  • 24