Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move a div's border "up" one pixel with css

Tags:

css

I have a div, which I have given a border on top. The border needs to be shifted one pixel higher. Is this possible with CSS.

like image 353
Ankur Avatar asked Jan 18 '11 15:01

Ankur


People also ask

How do you change the border position in CSS?

For example, if you have have a 2px left border and want it to appear as an inner border, you can just offset the whole container to the right, like this: position: relative; left: 2px; You might have to do other corrections, such as reducing the width of the container by 2px .

How do I move a border within a div?

Answer: Use the CSS box-shadow property If you want to place or draw the borders inside of a rectangular box there is a very simple solution — just use the CSS outline property instead of border and move it inside of the element's box using the CSS3 outline-offset property with a negative value.

How do you put a border on one side in CSS?

If you want to set a border to just one side of the element, use four values (write none to the side you want no border to appear). If you want to set a border to the top and bottom sides, use two values (write none to the second value).


2 Answers

You can accomplish this with a negative top margin

{ margin-top: -1px; }

very basic example: http://jsfiddle.net/zW6yD/

like image 163
hunter Avatar answered Oct 18 '22 02:10

hunter


You can do

div { position: relative; margin-top: -1px; }
like image 36
deadlock Avatar answered Oct 18 '22 04:10

deadlock