私はいくつかの JS で遊んでいますが、体のマージンにスタイリングを追加すると、他の要素が消えるのはなぜですか?
window.onload = function() {
with(document.body.style) {
margin = "0px 0px 0px 0px";
}
var header = document.createElement('header');
with(header.style) {
height = '2px';
marginBottom = '30px';
backgroundColor = '#333';
width = '100%';
margin = '0';
padding = '0';
}
document.body.appendChild(header);
var h1 = document.createElement('h1');
var name = document.createTextNode("Header1");
h1.appendChild(name);
document.body.appendChild(h1);
}
私がやろうとしているのは、マージンとパディングが要素に適用されないようにすることです。CSS では、次のようにします。
* { margin: 0; padding: 0; }