Alex Rivera | Logout

What is the difference between outline and border CSS properties?

Asked 2009-07-21T11:01:11.647
280

What is the difference between border and outline properties in CSS?

If there is no difference, then why are there two properties for the same thing?

Edit
Report

1 Answer

4

A little bit of an old question, but worth mentioning a Firefox rendering bug (still present as of Jan '13) where the outline will render on the outside of all child elements even if they overflow their parent (through negative margins, box-shadows, etc.)

You can fix this with:

.container {
    position: relative;
}
.container:before {
   content: '';
   margin: 0;
   padding: 0;
   position: absolute;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   outline: 1px solid #ff0000;
}

Super unfortunate that it's still not fixed. I much prefer outlines in many cases since they do not add to the dimensions of an element, saving you from always having to consider border widths when setting dimensions of an element.

After all, which is simpler?

.container {
    width: 960px;
    height: 300px;
    outline: 3px solid black;
}

Or:

.container {
    width: 954px;
    height: 294px;
    border: 3px solid black;
}
answered 2013-01-04T22:12:28.440

Your Answer