/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Center <LI> within a DIV container, HELP!!!

Please help…. The <LI> centers in IE 6 and 7, but aligns to the left margin in every other browser. What am I doing wrong or missing?

[URL=”http://www.maiocv.com/button-test.php”]button-test.php[/URL]

I’m assuming this is the best way to create a centralised button within a <DIV>, or is there a fool proof method?

Many thanks,

Mark.

All the code has been validated against W3 validators.

HTML Source Code:

[code=html]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />
<title>Button Test</title>
<link href=”button-test.css” rel=”stylesheet” type=”text/css” />
</head>

<body>
<div class=”MaioCVButton” style=”width:250px; height:250px; border: 1px dashed #777777;”>
<br /><br />
<div class=”MaioCVButton”>
<ul>
<li>
<a href=”www.tacv.cv”>&nbsp;&nbsp;Register your interest</a>
</li>
</ul>
<div style=”clear: both;”></div>
</div>
</div>
</body>
</html>
[/code]

CSS Code:

[CODE]
.MaioCVButton ul{
border: 0;
list-style-type: none;
text-align: center;
padding: 0;
margin: auto;
}

.MaioCVButton ul li{
text-align: center;
padding: 0;
margin: auto;
}

.MaioCVButton ul li a{
cursor: pointer;
display: block;
margin: auto;
border: outset 1px #ccc;
color: #f9f9f9;
padding: 5px 0 0 0;
font: bold 12px/14px “Lucida Sans Unicode”,verdana,sans-serif;
background: #aaccee url(images/buttonbg.gif) repeat-x top left;
height: 22px;
width: 80%;
text-align: center;
overflow: hidden;
white-space: normal;
text-decoration: none;
clear: both;
}

.MaioCVButton ul li a:hover{
color: #f9f9f9;
background: #6699cc url(images/email.gif) no-repeat left top;
[/CODE]

to post a comment
CSS

5 Comments(s)

Copy linkTweet thisAlerts:
@WebJoelJun 03.2008 — Well other instead of making your "<li>" be "width:80%;" (of it's parent element "<ul>"), you could make the "<ul>" be "width:80%;" and the "<li>" be "width:auto;" (or "width:100%;").

I checked this code on Firefox and it looks the same as IE... if you are getting different appearances, can you clear your browsers' cache and see if you are not re-loading a 'snapshot' of a previous build?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>Button Test</title> <link href="button-test.css" rel="stylesheet" type="text/css" />

<style>

.MaioCVButton ul{

border: 0;

list-style-type: none;

text-align: center;

padding: 0;

margin: auto; width:80%;

}

.MaioCVButton ul li{ list-style-type:none;

text-align: center;

padding: 0;

margin: 0 auto 0;

}

.MaioCVButton ul li a{

cursor: pointer;

display: block;

margin: 0 auto 0;

border: outset 1px #ccc;

color: #f9f9f9;

padding: 5px 0 0;

font: bold 12px/14px "Lucida Sans Unicode",verdana,sans-serif;

background: #aaccee url(images/buttonbg.gif) repeat-x top left;

height: 22px;

text-align:center;

overflow: hidden;

white-space: normal;

text-decoration: none;

}

.MaioCVButton ul li a:hover{

color: #f9f9f9;

background: #6699cc url(images/email.gif) no-repeat left top;}

</style>

</head>

<body>

<div class="MaioCVButton" style="width:250px; height:250px; border: 1px dashed #777777;">

<br /><br /> <div class="MaioCVButton">

<ul>

<li><a href="www.tacv.cv">&nbsp;&nbsp;Register your interest</a></li>

</ul>

<div style="clear: both;"><!-- required comment --></div>


</div>

</div>

</body>

</html>[/QUOTE]
I noted that you omitted the required " [B]}[/B] " from "[B].MaioCVButton ul li a:hover[/B]" A typo error, no doubt.
Copy linkTweet thisAlerts:
@bluestartechJun 03.2008 — you could also set the div width to something less than 100%
Copy linkTweet thisAlerts:
@WebJoelJun 03.2008 — you could also set the div width to something less than 100%[/quote] ? You've lost me... setting the width of the DIV is not going change the centering of the UL in it... If the DIV is a set width and the desired width of the UL (or the LI) is set to 80%, that is 80% of the width of the DIV... see.. I'm not sure what you're suggesting here... ? Can you elaborate?
Copy linkTweet thisAlerts:
@Barton68authorJun 03.2008 — Thanks both for the quick resposes.

I used browsershots to test the PHP, that's how I knew it had failed, and yes I missed the end braces on the :hover :-(

The DIV will act a container for data and the users can email regarding each container of data, if that makes sense?

Thanks again, I'll the try the UL LI code.
Copy linkTweet thisAlerts:
@Barton68authorJun 03.2008 — Thank you, worked first time...

Brilliant.
×

Success!

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