/    Sign up×
Community /Pin to ProfileBookmark

Vertically centring text in a div made from a li

Would someone please be able to tell me how I can vertically align the text on the navigation buttons on the follow site I’m trying to develop?

[url=http://atlantis.plastiqueweb.com/2005-6/]http://atlantis.plastiqueweb.com/2005-6/[/url]

The HTML code of the part in question is:

[code] <div id=”left_column”>

<div id=”navigation-container”>
<ul>
<li><a href=”#”>Announcements</a></li>
<li><a href=”#”>Tracking</a></li>
<li><a href=”#”>Mixing</a></li>
<li><a href=”#”>Mastering</a></li>
</ul>

</div>
</div>[/code]

and part of the CSS code:

[code]#left_column {
width: 170px;
}
#navigation-container {
width: 170px;
float: left;
}
#navigation-container ul {
margin: 0;
padding: 0;
list-style-type: none;
text-indent: 24px;
font-weight: bold;
}
#navigation-container a {
width: 170px;
height: 23px;
display: block;
}
#navigation-container a:link, #navigation-container a:visited {
background: #EBEAE8 url(../images/layout/navigation_button.png) no-repeat;
color: #303030;
text-decoration: none;
}
#navigation-container a:hover, #navigation-container a:active {
background: #EBEAE8 url(../images/layout/navigation_button-rollover.png) no-repeat;
color: #303030;
text-decoration: none;
}[/code]

I’ve already tried all sorts of margins and paddings in the CSS, but it always spaces the buttons apart too. And vertical-align: middle doesn’t work either.

Can anyone help?

to post a comment
HTML

7 Comments(s)

Copy linkTweet thisAlerts:
@Paul_JrOct 28.2004 — <i>
</i>#navigation-container a {
width: 170px;
height: 23px;
[b][color=red]line-height: 23px;[/color][/b]
display: block;
}

Adding a line-height that is the same as the height of the element will vertically center the text.
Copy linkTweet thisAlerts:
@Atlantis-ARauthorOct 28.2004 — Thank you so much, Paul Jr. You have no idea how long I've been pondering with that stupid little problem, and no one seemed to have answer for it.

So thanks again. ? It was actually line-height: 22px; that I was after to be exact, but still, I can't thank you enough. ?
Copy linkTweet thisAlerts:
@Atlantis-ARauthorOct 28.2004 — What about the text in the footer on this page? [url=http://atlantis.plastiqueweb.com/2005-9/]http://atlantis.plastiqueweb.com/2005-9/[/url]

I thought it would be the same case of adding a [b]line-height: 29px;[/b] in the [b]#footer h5[/b] property in the CSS, but no, that would be too simple. What else can I do to vertically align this text so that it sits nicely on the white part of the footer background?

I've put a border around the footer div to make it easier to see, and while it appears to look OK now, as soon as I remove the border, the text shoots up to the top of the div again, and no matter what I do after that do I can't get it to move down. ?

&lt;div id="footer"&gt;
&lt;h5&gt;Copyright ©2004-2005 &amp;nbsp;| &amp;nbsp;Atlantean Records &amp;nbsp;| &amp;nbsp;Hosting by PlastiqueWeb &amp;nbsp;| &amp;nbsp;&lt;a href="http://www.plastiqueweb.com/"&gt;<a href="www.plastiqueweb.com">www.plastiqueweb.com</a>&lt;/a&gt; &amp;nbsp;| &amp;nbsp;&lt;a href="http://validator.w3.org/check/referer"&gt;XHTML&lt;/a&gt; &amp;nbsp;| &amp;nbsp;&lt;a href="http://jigsaw.w3.org/css-validator/check/referer"&gt;CSS&lt;/a&gt;&lt;/h5&gt;

<i> </i>&lt;/div&gt;


#footer {
width: 762px;
height: 59px;
margin: 0px auto;
position: relative;
background: #EDEDED url('../images/layout/footer.png') no-repeat;
text-align: center;
clear: both;
border: 1px solid #0000FF;
}
#footer h5 {
font: 10px Tahoma, sans-serif;
color: #1C1C1C;
}
#footer h5 a:link, #footer h5 a:visited {
color: #1C1C1C;
}
#footer h5 a:hover, #footer h5 a:active {
color: #1C1C1C;
background-color: transparent;
}
Copy linkTweet thisAlerts:
@Paul_JrOct 29.2004 — You want it centered in the white part, yes? Well, since the middle of the white part is not the middle of the element, you'll have to sort of guess at the correct line-height to use to get the text where you want it. I found 30px to be pretty good.
Copy linkTweet thisAlerts:
@Atlantis-ARauthorOct 29.2004 — Yes, that's right. But I've tried using line-height: 30px, margin-top: 10px; and vertical-align: middle; already, except none of those work. ?

The text just won't move down unless I put a border around the div, which I obviously don't want.

Someone else suggested putting a table with width and height 100% inside the div and then centring the text in there, but I don't know if that's the best idea…
Copy linkTweet thisAlerts:
@Atlantis-ARauthorOct 29.2004 — Hmm, I really don't know what I keep doing wrong but for some reason I accidently ended up typing a [b]padding-top[/b] property instead of a margin-top this time and now it works.
Copy linkTweet thisAlerts:
@Paul_JrOct 29.2004 — All right. Glad you got it working. ?
×

Success!

Help @Atlantis-AR 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.17,
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,
)...