Border added outside height and width?

0 views
Skip to first unread message

Shuchi

unread,
Feb 5, 2010, 1:22:13 PM2/5/10
to EDUC 176 Programming Lab
If I add a 2px border to a div that's supposed to have a height &
width of x & y, should that 2px be subtracted from x & y when I set
the height and width?

Troy

unread,
Feb 5, 2010, 1:50:33 PM2/5/10
to EDUC 176 Programming Lab
Good question!

So good, in fact, I wasn't really sure what the answer was, but I
found this thread:

http://bytes.com/topic/html-css/answers/542711-borders-inside-out

Based on this discussion, if you set the width and height of a div to
500 with a 2px border, when the div is rendered, it will have a width
and height of 504.

So, yes, if you have a 2px border around the entire div, you need to
subtract *4* px from the width and height.

Troy

Shuchi Grover

unread,
Feb 5, 2010, 2:04:58 PM2/5/10
to educ-176-pro...@googlegroups.com
Thanks, makes sense - my layout was off by a few pixels here and there - coz of the borders, I guess :)
Reply all
Reply to author
Forward
0 new messages