Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute Offset Percentage + Value?

Is it possible with css' absolute positioning element to do something like:

 .myElement{
    width: 385px;
    position: absolute;
    left: 50% - 385px;
 }

and have the element offset by a percentage minus its width, or something similar?

like image 872
user2475940 Avatar asked Jun 11 '13 19:06

user2475940


2 Answers

use a negative margin in the direction you want to go.

.myElement{
    width: 385px;
    position: absolute;
    left: 50%;
     margin-left: -385px;
 }
like image 156
Thomas Jones Avatar answered Oct 15 '22 09:10

Thomas Jones


you can also use calc:

.myElement{
width: 385px;
position: absolute;
left: **calc(50% - 385px)**;}

it's pretty much supported-> http://caniuse.com/#feat=calc

like image 25
webkit Avatar answered Oct 15 '22 09:10

webkit