I have a problem with increasing div element height. To see this problem, you need to insert a new "field for error case" element . Then you need to click the top right div / top left div . You can type 1 letter and then delete it (or just set the focus and delete it) → you can see the div element increasing. I do not understand why this is happening. Sorry for my bad english. Thanks!
I also notice that this happens if you do not comment innerDiv1.setAttribute("data-text", "Full Name of the Case");
The problem occurs in the Safari browser.
[contentEditable=true]:empty:not(:focus):before {
content:attr(data-text)
}
.boxed {
margin: 5px;
border: 2px solid black;
max-width: calc(100% - 10px);
}
.inline {
display: inline-block;
vertical-align: middle;
max-width: calc(100% - 10px);
}
.divTable {
display: table;
border-collapse: separate;
border-spacing: 5px;
}
.divRow {
display:table-row;
}
.divCell {
display:table-cell;
border: 2px solid black;
}
<script>
function insert(elem) {
document.getElementById("mainDiv").focus();
var sel = window.getSelection();
var range = sel.getRangeAt(0);
range.insertNode(elem);
}
function legalCaseBox() {
var innerDiv1 = document.createElement('div');
innerDiv1.contentEditable = 'true';
innerDiv1.style.minWidth = '50pt';
innerDiv1.style.minHeight = '50pt';
innerDiv1.classList.add('divCell');
var innerDiv2 = document.createElement('div');
innerDiv2.contentEditable = 'true';
innerDiv2.style.minWidth = '50pt';
innerDiv2.style.minHeight = '50pt';
innerDiv2.classList.add('divCell');
innerDiv2.setAttribute("data-text", "Year");
var firstDiv = document.createElement('div');
firstDiv.contentEditable = 'false';
firstDiv.classList.add('divTable');
var rowDiv = document.createElement('div');
rowDiv.classList.add('divRow');
rowDiv.appendChild(innerDiv1);
rowDiv.appendChild(innerDiv2);
firstDiv.appendChild(rowDiv);
var secondDiv = document.createElement('div');
secondDiv.style.minWidth = '150pt';
secondDiv.style.minHeight = '80pt';
secondDiv.contentEditable = 'true';
secondDiv.classList.add('boxed');
secondDiv.setAttribute("data-text", "Case summary");
var div = document.createElement('div');
div.contentEditable = 'false';
div.classList.add('inline');
div.classList.add('boxed');
div.appendChild(firstDiv);
div.appendChild(secondDiv);
insert(div);
}
</script>
<body id="main" spellcheck="false">
<button onclick="legalCaseBox()">legalCaseBox</button>
<div id="mainDiv" contenteditable="true"></div>
</body>
Run codeHide resulthttp://jsfiddle.net/Lfysfz6k/3/