.search {
margin: 10px;
}
.search::before {
content: "";
position: absolute;
top: 50%;
bottom: auto;
width: 20px;
height: 20px;
transform: translateY(-50%);
background: url('magnifying-glass.svg');
}
input[type="search"] {
height: 30px;
padding-left: 30px;
border: none;
border-radius: 0.25rem;
outline: none;
}
.container {
position: relative;
background-color: cadetblue;
}
<div class="container">
<div class="search">
<form>
<input type="search" placeholder="Search...">
</form>
</div>
</div>
I am fairly new to css. According to my assumptions, my input[type="search"]
should have 10px margin to the borders of the div.container
because I have set the margin
on div.search
, however, as you can see in code snippet above, my input
element and div.container
is sharing borders.
Can you eloborate on what I am missing to make it work? I am especially interested to see the flaw in my reasoning.