javascript - Make div height respond to content -


i have div being filled using .text() method when enter long text entry, height of div doesn't respond , text overflows div.

i have text area , button, when button pressed value of text area inserted div.

image: http://prntscr.com/et5ja5

things tried:

height: auto; display: inline-block; overflow: visible/auto; etc

full example upon request

html:

<body>         <div data-role="page" id="article1">             <div data-role="header" data-theme="a" data-position="fixed">                 <h1>notes</h1>             </div>              <div data-role="content">                 <div id="addcontainer">                     <button id="addnotebtn" data-role="button">add note</button>                     <textarea id="noteinput" class="textarea" rows="10" cols="50"></textarea>                      <button id="savenotesbtn" data-role="button">save</button>-->                 </div>                 <div id="displaycontainer">                 </div>             </div> 

css:

#addcontainer {     margin: 20px 20px 50px 20px; }  #displaycontainer {     margin: 20px 20px 20px 20px; }  .notedisplay {     display: inline-block;     color: white;     background-color: #96c56f;     width: 100%;     padding: 5px, 0px, 5px, 0px;     border: solid 2px black;     border-radius: 5px;     margin-bottom: 5px; }  .textarea {     width: 100%;     height: 100%;     font: 1em arial;     color: rgba(50, 82, 50, 1.0); }  .textarea:focus {     color: rgba(50, 82, 50, 1.0);     border: 2px solid #96c56f;     box-shadow: 0px 1px 1px #888888; } 

js:

$(document).ready(function () {     var savesnotesbtn = document.getelementbyid("savenotesbtn");     var addnotebtn = document.getelementbyid("addnotebtn");      var notecount = localstorage.getitem("notecount");      if (notecount === null) {         notecount = 0;     }       addnotebtn.addeventlistener("click", addnotes);      //add notes     function addnotes() {         notecount++;         var note = $("#noteinput").val();         console.log("note: " + note);         console.log("note count: " + notecount);         var display = document.createelement("div");         document.getelementbyid("displaycontainer").appendchild(display);         display.classname = "notedisplay";         display.id = "note" + notecount;         $("#note" + notecount).text(note);          localstorage.setitem("notecount", notecount);     } }); 

based on comment op, saying it overflows right of div, if 1 add word-break: break-all notedisplay rule break line properly

updated fiddle

.notedisplay {     display: inline-block;     color: white;     background-color: #96c56f;     width: 100%;     padding: 5px, 0px, 5px, 0px;     border: solid 2px black;     border-radius: 5px;     margin-bottom: 5px;     word-break: break-all;          /*  added property  */ } 

regarding difference between break-all , break-word, when text entered in chinese, japanese, , korean, better distributed on each line break-all

src: https://www.w3.org/tr/css-text-3/#break-all


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -