Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:39:46+00:00 2026-05-31T14:39:46+00:00

I’m hoping there will be a CSS guru out there that can help with

  • 0

I’m hoping there will be a CSS guru out there that can help with this one…
I’m building a responsive layout for a site which includes a horizontal navigation bar across the top. This bar contains 5 buttons each of the same width (although obviously this width needs to be flexible). I would like to use icons instead of text for the buttons for when the menu is viewed on a device with a small viewport width. I will use media queries to adapt the layout to use text once I feel the viewport width has reached a suitable size. This is important because I am not anticipating needing to change the size of the icons themselves. I’m happy for them to be of a fixed size, centered in the button and if the button size itself changes then there will simply be more “padding” around the centered icon.
Ordinarily I would use have all the icons in one image and use the sprite technique to only display the correct part of the image, but I have come across a problem. If I want the anchor element to fill the parent list element then how can I center the sprite?

Here is some example markup:
First the html (snippet)

 <nav>
   <ul class="top_nav">
    <li><a class="link_1" href="#">link 1</a></li>
    <li><a class="link_2" href="#">link 2</a></li>
    <li><a class="link_3" href="#">link 3</a></li>
    <li><a class="link_4" href="#">link 4</a></li>
    <li><a class="link_5" href="#">link 5</a></li>
   </ul>
 </nav>

And I might style it like this:

 nav ul {
          width: 100%;
          overflow: auto;
        }

 nav li {
          float: left;
          width: 20%;
          background: #2c2c2c; /* dark background for light icons */
        }

 nav li a {
            display: block;
            border: 1px solid #e7e7e7;
            background-image: url(path/to/sprite.png);
            background-repeat: no-repeat;
            text-indent: -15000px;
            width: 48px;
            height: 48px;
            margin: 0 auto;
          }

 nav li a.link_1 {
                   background-position: 0 0;
                 }

 nav li a.link_2 {
                   background-position: 0 -49px;
                 }

etc….

But this will only give me a clickable area of 48px x 48px within a button that can change it’s width depending on the size of the parent element. If I make the anchor element fill it’s parent list element then the icon can’t be centered using the margin rule.
I could add another element inside the anchor element which was empty but had the icon as it’s background like this:

 <li><a href="#"><div class="link_1">Link 1</div></a></li>

And style it with:

 nav li a {
            display: block;
            border: 1px solid #e7e7e7;
            width: 100%;
          }

 nav li a div {
                background-image: url(path/to/sprite.png);
                background-repeat: no-repeat;
                text-indent: -15000px;
                width: 48px;
                height: 48px;
                margin: 0 auto;
              }

 nav li a div.link_1 {
                   background-position: 0 0;
                 }

But this isn’t a very semantic or elegant solution. Can anyone think of anything better??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:39:48+00:00Added an answer on May 31, 2026 at 2:39 pm

    You can use:

    • generated content (:before/:after) instead of real elements to keep code clean;
    • background-size property to zoom your background images;
    • Data URIs instead of sprites. Data URIs are supported by all current browsers (IE8 has 32KB limitation of maximum size for each file represented as a Data URI).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.