/    Sign up×
Community /Pin to ProfileBookmark

Assigning a width..can’t center??

I’ve been negotiating around this issue for a while but its become to much of a hinderance.
I can’t seem to assign a width to an element whilst at the same time using text-align:center; in the same div #.
Any reasons?? I bet i’m missing something simple here but its time to face up to my ignorance haha.

Cheers

to post a comment
HTML

4 Comments(s)

Copy linkTweet thisAlerts:
@Frank62Aug 24.2011 — Can you post the code? That probably makes it easier to understand what exactly you're trying to achieve. See my signature for how to post the code.
Copy linkTweet thisAlerts:
@cbVisionAug 24.2011 — I've created an example here to show you how text-align and div centering works:

http://jsfiddle.net/dfreema1/PQMnd/

As you can see, both have a width of 300px; however only the 2nd div is actually centered. The key is the "margin 0 auto;" piece. The text-align property centers the text within the div; however doesn't center the div itself. I'm guessing this is the issue you're running into.
Copy linkTweet thisAlerts:
@Major_PayneAug 25.2011 — The text-align: center; does just that...align text to center. If you want the containing element centered, use margin: 0 auto; . Examples:

[CODE]body {
width: 90%;
height: 600px; /* optional */
margin: 0 auto;
background: #fff url(path to non-tiled image) no-repeat center scroll;
}[/CODE]


Example as a Class:

[CODE].selector_name {
width: 90%;
height: 600px; /* optional */
margin: 0 auto;
background: #fff url(path to non-tiled image) no-repeat center scroll;
}[/CODE]


HTML for Class: [CODE]<div class="selector_name">Content here</div>[/CODE]

Example as an ID:

[CODE]#selector_name {
width: 90%;
height: 600px; /* optional */
margin: 0 auto;
background: #fff url(path to non-tiled image) no-repeat center scroll;
}[/CODE]


HTML for Class: [CODE]<div id="selector_name">Content here</div>[/CODE]

Change parameters as you need. Set "#fff" to background color you want. Set "scroll" to "fixed" if you want page contents to scroll over background image. CSS was given for an image that does not tile. Doesn't have to be the body tag, but you should get the idea.
Copy linkTweet thisAlerts:
@ajmcloughlinauthorAug 25.2011 — perfect thanks a lot people, problem sorted! x
×

Success!

Help @ajmcloughlin 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,
)...