"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Avoid Double Borders in CSS: Outline vs. Negative Margins?

How to Avoid Double Borders in CSS: Outline vs. Negative Margins?

Published on 2024-11-12
Browse:299

How to Avoid Double Borders in CSS: Outline vs. Negative Margins?

Avoiding Duplicated Borders in CSS

When adjacent elements with borders are placed next to each other, a visual artifact known as "double borders" can occur at the border intersection. To eliminate this undesirable effect, consider these CSS approaches:

Option 1: Using Outline Property

For situations where the order of elements is unpredictable, using the outline property can effectively prevent double borders:

.collection {
  /* Optional styling */
  margin-top: -1px;
  margin-left: -1px;
}

.collection .child {
  outline: 1px solid; /* Replaces border */
  margin-top: 1px;
  margin-left: 1px;
}

Note that outline is not supported in older browsers (IE7 and earlier).

Option 2: Negative Margins with Borders

If using borders is preferred, employ negative margins to offset the double border:

.collection .child {
  margin-top: -1px;
  margin-left: -1px;
}
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3