user2475940
user2475940

Reputation: 53

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?

Upvotes: 5

Views: 3257

Answers (2)

webkit
webkit

Reputation: 3369

you can also use calc:

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

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

Upvotes: 4

Thomas Jones
Thomas Jones

Reputation: 4962

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

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

Upvotes: 6

Related Questions