3
I have a child element that is mounted dynamically, the contents of this element can sometimes be long, it makes such element exceed the parent as in the following example:
Parent Element:
margin: 5px 30px 10px 40px;
Elemento Filho:
$("#divcritica").append("<div id='divvalorcontabil"+ divvalorcontabil +"' class='operacao btn btn-info dashed-black-border' value='ValorContabil/"+marcados+"' style='margin:3px; 0px; 0px; 5px; box-shadow: rgb(0, 0, 0) 1px 1px 7px -2px; border-radius: 3px; border: 2px;' ondblclick='removeButton(this)' onclick='setClass(this)'></div>");
Upshot:
How can I adjust so that it does not exceed the parent element?
Note: The content of this element is variable.
Do not use
pre-wrap
because it adds line break before the element. And yet, this property alone does not break the text.– Sam
@Sam maybe I got it wrong Sequences of white space are preserved. Lines are broken in new line characters, in <br> and when necessary to fill the lines of boxes (boxes). Source: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space and I saw it preserves line breaks, spaces, <br> and yes it wraps http://prntscr.com/p5qn0v
– hugocsl
Testing here, in addition to not breaking the text, still adds a
<br>
before it: https://i.stack.Imgur.com/4HxNv.png– Sam
In fact, the correct print is this: https://i.stack.Imgur.com/N6oud.png ... the other print has the
word-break
that breaks the text.– Sam
@Sam here on Win10 and Chrome did not add BR no, in addition to his question he uses a div and not a http://prntscr.com/p5qq75 button
– hugocsl
Does not add a
<br>
in DOM, it adds a line break at the beginning of the element, as if it were a <br>. Either div or button, the effect is the same. The question is that your answer does not solve the problem :X– Sam
The
pre-wrap
it’s still mt bad because it keeps the spaces as they are in the source code, as if it were a tag<pre></pre>
.– Sam
@Sam, what if he wants to preserve the spaces? He did not say how he wanted to render the text, and as I said here he did not add any space before the text http://prntscr.com/p5qu1i
– hugocsl
It is because you did not indent the text in the div, put everything in the same line, but try to do so for you see: https://i.stack.Imgur.com/pRcuf.png .. in short, the pre-wrap is not good for this. It will render HTML as if it were a WYSIWYG.
– Sam
@Sam doesn’t even have it in the AP code. So we can have more than one answer and it’s up to him to choose which one looks best for his particular case. Abs
– hugocsl
I used the pre-rep in my son element, it worked perfectly, respect the padding of the parent element.
– Victor Henrique
@Victorhenrique cool young, good that worked there, in CSS almost always there is more than one way to do the same thing. Success
– hugocsl