Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Outside Border

Tags:

css

border

I want to be able to draw a border OUTSIDE of my Div! So if my div is say 20px by 20px, I want a 1px border outside of this (so in essence, I get a div 22x22px large).

I understand that I can just make the div 22x22 to start with, but for reasons I have, I need the borders to be on the outside.

CSS outline works, but I want only border-bottom or border-top thingy, so something like outline-bottom, which does not work, is what I want.

Is there a way to do this?

Thanks

like image 552
user1083320 Avatar asked Feb 01 '12 20:02

user1083320


People also ask

How do you put an outside border in CSS?

Usually by default, 'border:' puts the border on the outside of the width, measurement, adding to the overall dimensions, unless you use the 'inset' value: div {border: inset solid 1px black}; But 'outline:' is an extra border outside of the border, and of course still adds extra width/length to the element.

Is CSS border inside or outside?

Width and height values apply to the element's content only. The padding and border are added to the outside of the box. padding-box : Width and height values apply to the element's content and its padding. The border is added to the outside of the box.

Can you offset a border CSS?

The CSS outline-offset Property sets the amount of space between an outline and the edge or border of an element. An outline is a line drawn around elements outside the border edge. The space between the element and its outline is transparent. Also, the outline may be non-rectangular.


1 Answers

I think you've got your understanding of the two properties off a little. Border affects the outside edge of the element, making the element different in size. Outline will not change the size or position of the element (takes up no space) and goes outside the border. From your description you want to use the border property.

Look at the simple example below in your browser:

<div style="height: 100px; width: 100px; background: black; color: white; outline: thick solid #00ff00">SOME TEXT HERE</div>    <div style="height: 100px; width: 100px; background: black; color: white; border-left: thick solid #00ff00">SOME TEXT HERE</div>

Notice how the border pushes the bottom div over, but the outline doesn't move the top div and the outline actually overlaps the bottom div.

You can read more about it here:
Border
Outline

like image 73
Bear In Hat Avatar answered Sep 19 '22 11:09

Bear In Hat