Here is my HTML code. I want to set some margin between border of .main div and .field div.
<div class="main">
<div class="field">
<label for="input1" class="block">Name</label>
<input type="text" id="input1">
</div>
<div class="field">
<label for="input2" class="block">Email</label>
<input type="email" id="input2">
</div>
<div class="field">
<label for="input3" id="block">Another input field</label>
<input type="email" id="input3">
</div>
</div>
And below is CSS.
.field {
margin-top: 2%;
}
/* For each input field in new line */
input {
display: block;
}
The above margin: 2%
property is applying to all subsequent div elements with field class but not the first div element. Instead it moves down entire div with .main class.
Here is the code in tryit editor. https://www.w3schools.com/code/tryit.asp?filename=GHO4LCR8K8NT