foop
foop

Reputation: 523

css element border include margin-top

I have a div tag that has a style set of at margin-top: 25px

Now when I try to add a border surrounding the div tag it does not include the margin-top. Is it even possible?

I've been googling around and so far have found nothing.

Upvotes: 4

Views: 5121

Answers (2)

gillytech
gillytech

Reputation: 3686

You need to add padding-top instead of margin and your markup/CSS should look something like this pen: http://codepen.io/gillytech/pen/yCAnE

HTML:

<div id="box"></div>

CSS

#box {
  height: 100px;
  width: 200px;
  background-color: #eee;
  padding-top: 25px;
  border: 1px solid #666;
}

Upvotes: 0

uber5001
uber5001

Reputation: 3964

You need to use padding-top instead. The border shows up between the margin box and the padding box.

Upvotes: 4

Related Questions