/    Sign up×
Community /Pin to ProfileBookmark

calc() with variable

What can I enter as xxx?

# Goal:

element is centered in window

# Idea:

left: calc(100% – (width/2))

But how do I get width?

.center-div {
position: absolute;
max-width: 500px;
left: calc(xxx)
}

Thanks
-K

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@rootJun 10.2018 — I thought that margin: auto; was the CSS term to centre a DIV element in a page...
Copy linkTweet thisAlerts:
@cootheadJun 10.2018 — Hi there Kalem,

why are you using _"position: absolute"_ ?

This...
``<i>
</i>element {
max-width: 31.25em;
margin: auto;
}<i>
</i>
``

... is the correct method to use. ?

_coothead_
Copy linkTweet thisAlerts:
@KalemauthorJun 10.2018 — Perfect!

margin: auto;

is the correct solution! ?


Thanks!
×

Success!

Help @Kalem spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...