Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJamie Reardon
Treehouse Project ReviewerHow can I center align the contact ul with the background images of the li a elements?
Hi there! I am really enjoying experiencing the content that TeamTreeHouse has to offer! I have been following along with the course: How to Make A Website with Nick Pettit and I am practicing what I have learned on a new mobile view web page of my own. I am curious with how Nick has used the text-align: center declaration to center align the element's content on certain areas of the page, how can I further use that by center aligning the content ul element with the background images of the li a elements? I have experimented and figured out that the contact li a text will align in the center of the browser, however the background images stay to the left of the browser.
HTML:
<section id="secondary">
<h3>Contact Details</h3>
<ul class="contact-info">
<li class="phone"><a href="tel:555-6425">555-6425</a></li>
<li class="mail"><a href="mailto:nick@example.com">nick@example.com</a></li>
<li class="twitter"><a href="http://twitter.com/intent/tweet?screen_name=nickrp">@nickrp</a></li>
</ul>
</section>
CSS:
.contact-info {
list-style: none;
margin: 0;
padding: 0;
font-size: 0.9em;
}
.contact-info a {
display: block;
min-height: 20px;
background-repeat: no-repeat;
background-size: 20px 20px;
padding: 0 0 0 30px;
margin: 0 0 10px;
}
.contact-info li.phone a {
background-image: url('../img/phone.png');
}
.contact-info li.mail a {
background-image: url('../img/mail.png');
}
.contact-info li.twitter a {
background-image: url('../img/twitter.png');
}
Any help would be appreciated! Thanks.
2 Answers
Milan Pankhania
3,734 PointsHi Jamie, centring the images is possible, however they will always end up behind the text (as they are background images). There are many many ways of going around this, but I think the easiest solution would be to first remove the background images from your css, and instead add them as inline images in the html. This will give you more control over their position.
Give this a try:
Modified HTML: (I'm not sure if the image paths are correct here, you might need to remove the '../' for it to load)
<section id="secondary">
<h3>Contact Details</h3>
<ul class="contact-info">
<li class="phone"><img src="../img/phone.png" alt=""><a href="tel:555-6425">555-6425</a></li>
<li class="mail"><img src="../img/mail.png" alt=""><a href="mailto:nick@example.com">nick@example.com</a></li>
<li class="twitter"><img src="../img/twitter.png" alt=""><a href="http://twitter.com/intent/tweet?screen_name=nickrp">@nickrp</a></li>
</ul>
</section>
Modified CSS:
.contact-info {
list-style: none;
margin: 0;
padding: 0;
font-size: 0.9em;
}
.contact-info a {
display: block;
min-height: 20px;
background-repeat: no-repeat;
background-size: 20px 20px;
padding: 0 0 0 30px;
margin: 0 0 10px;
}
/* Background images have been removed, additional code below: */
.contact-info a,
.contact-info img {
display: inline-block;
vertical-align: middle;
}
.contact-info a {
padding-left: 15px;
margin-bottom: 0;
}
.contact-info li {
margin-bottom: 10px;
text-align: center;
}
Does this help?
Jamie Reardon
Treehouse Project ReviewerThat works perfectly! Thanks alot!
Jamie Reardon
Treehouse Project ReviewerHi Milan, Thanks for your fast reply! I have edited my question to contain my code! Sorry, it's my first time asking a question on this website :P Thanks!
Milan Pankhania
3,734 PointsMilan Pankhania
3,734 PointsHi Jamie, if you could post the code that will be helpful in seeing what you're trying to achieve, thanks