distante distante - 1 year ago 73
CSS Question

Is there a way to add overlapping borders to ALL div with css?

I did a search here but some talk about adjacent borders. Does anybody know if it is possible to add borders to all divs just to see how the current layout works.

If you just add a border, it will add 2px (side by side) and will - sometimes - break the current layout.

I'm wondering this just for control purposes, something to turn on/off, no for production.


Answer Source

You can better use outline property instead of border, because

  • Outlines do not take up space, because they always placed on top of the box of the element which may cause them to overlap other elements on the page.
  • Unlike borders, outlines won't allow us to set each edge to a different width, or set different colors and styles for each edge.
  • An outline is the same on all sides.
  • Outlines don't have any impact on surrounding elements apart from overlapping.
  • Unlike borders, outlines don't change the size or position of the element.

  border:solid 1px blue;
  border:solid 1px red;
  outline:solid 1px red;
<div class="outline-outer">
  <div class="outline"></div>
  <div class="outline"></div>Outlined
<div class="border-outer">
  <div class="border"></div>
  <div class="border"></div>Bordered

Fiddle Here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download