/    Sign up×
Community /Pin to ProfileBookmark

Css Equivalent Of <center> Tag

What is the equivalent in css of the html center tag? (For images and text). I know you can line up the image or text with x/y coordinates but it doesn´t exactly centrally line up, specially when browser resolution varies.

Thanks your help.

to post a comment
CSS

7 Comments(s)

Copy linkTweet thisAlerts:
@VladdyMay 11.2004 — text-align: center;

for the [b]parent[/b]
Copy linkTweet thisAlerts:
@fredmvMay 11.2004 — Good call Vlad. Though I suggested the above because [font=courier]<center>[/font] also centers block-level elements as well as text. So I guess what you're looking for, ideally, is both.
Copy linkTweet thisAlerts:
@Ben_RogersMay 11.2004 — Also, margin: auto; for DIVs will set the margins on either side to their maximum value, creating effective centering in most cases.
Copy linkTweet thisAlerts:
@VladdyMay 11.2004 — [i]Originally posted by fredmv [/i]

[B]Good call Vlad. Though I suggested the above because [font=courier]<center>[/font] also centers block-level elements as well as text. So I guess what you're looking for, ideally, is both. [/B][/QUOTE]


He was asking for "images and text" that are inline elements by default - therefore my answer.

I do not think a "universal solution" is the best one. I prefer "divide and conquer" approach:

inline elements: use text-align: center on parent;

block elements: use margin: [X] auto;

simple and works.
Copy linkTweet thisAlerts:
@klebauthorMay 11.2004 — OK thanks guys. That did it. Great help and I appreciate the fast answers.
Copy linkTweet thisAlerts:
@fredmvMay 11.2004 — [i]Originally posted by Vladdy [/i]

[B]He was asking for "images and text" that are inline elements by default - therefore my answer.

I do not think a "universal solution" is the best one. I prefer "divide and conquer" approach:

inline elements: use text-align: center on parent;

block elements: use margin: [X] auto;

simple and works. [/B]
[/QUOTE]
I agree. I should've read the question more closely. ?
×

Success!

Help @kleb 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 5.25,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...