I am new to HTML programming. Is it possible to make a border to the margin instead of the padding? I need this just for design purposes only.
Border to margin in HTML
707 views Asked by Matthew At
3
There are 3 answers
5
On
I don't think this is possible but if you want to enclose the margin within a border then there can be a workaround. Enclose the element with span and set the border for that span element as,
.inner{
padding: 5px;
margin: 5px;
}
.outer{
border: 1px solid black;
}
<div class="outer">
<p class="inner">Hello</p>
</div>
Yes. The closest way I can think of to achieve this effect is using the CSS
background-clip
property:This clips any backgrounds in the element not to be rendered in the border region, thus treating it like a margin rather than padding.
Below is an example of the difference:
In the "corrected" div, the border becomes part of the margin visually rather than part of the padding.