Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheriting CSS how do I stop it?

Tags:

html

css

I am new to CSS and I know what the problem I am having is but I can't figure out how to stop it.

I have an element with an id of footer, and another element inside that one with a class of socialmedia. I am using a sprite to handle the media icons. The problem I am having is that #footer ul li's padding (padding: 9px 0px 9px 13px) is being inherited by .socialmedia.

I have tried adding .socialmedia ul li {margin: 0px; padding: 0px;} to stop it and I have also added !Important but the padding still seems to get through.

I want to remove the left padding of 13px from the social media icons so they aren't so spaced. Can someone please tell me what I am doing wrong?

I have created a JFiddle if you want to see it live here: http://jsfiddle.net/2Nv59/3/

HTML:

<div id="footer">
        <ul>
    <li><a href="#">Home</a></li>
            <li><a href="#">Company Overview</a></li>
            <li><a href="#">Our Services</a></li>
            <li><a href="#">Registration</a></li>
            <li><a href="#">News & Blog</a></li>
            <li><a href="#">Links</a></li>
            <li><a href="#">Contact us</a></li>
        </ul>

        <div class="FooterAddress"><strong>ABC Comp</strong><br>555 My Street.<br>Boonton, CA 07005<br>1 (800) 555-1111<br><br>

          <div class="socialmedia">
            <ul>
                <li><a href="http://facebook.com" title="Be our friend" target="_blank" class="facebook"></a></li>
                <li><a href="http://www.linkedin.com" title="Let's connect" target="_blank" class="linked"></a></li>
                <li><a href="http://www.twitter.com" title="Follow us!" target="_blank" class="twitter"></a></li>
            </ul>
          </div>

       </div>


    </div>

CSS:

/* Footer */

#footer {background-color: #3B3014; height: 150px; margin-top: 10px;}
#footer ul {padding: 0px; margin: 0px;}
#footer ul li{display: inline-block; padding: 9px 0px 9px 13px;}
#footer ul li a {text-decoration: none; color: #fff; font-weight: bold;font-size: 11px;}
#footer ul li a:hover {text-decoration: none; color: #FF6600; font-weight: bold;}
.FooterAddress {float: right; color: #FFC50B; font-size: 11px; margin-right: 13px; margin-top:-20px; text-align:right;}
.developedby {float: left; color: #fff; font-size: 11px; margin-left: 13px; margin-top: 94px;}
.developedby a {color: #FFC50B; text-decoration:none;}
.developedby a:hover {color: #CCC;cursor:hand;}

/* Soecial Media Sprites */
.nopadding {padding: 0px;float: right; color: #fff; background: #000;}
.socialmedia ul li {margin: 0px; padding: 0px;}
.socialmedia ul li a {display: block; width: 26px; height: 27px; background: url(../images/socialmedia_sprite_sm.png) no-repeat; padding: 0px;}
.socialmedia ul li:last-child {margin-right: 0;}

.socialmedia a.facebook {background-position: -27px -27px;}
.socialmedia a.facebook:hover {background-position: -27px 0;}
.socialmedia a.linked {background-position: -52px -27px;}
.socialmedia a.linked:hover {background-position: -52px 0;}
.socialmedia a.twitter {background-position: left bottom;}
.socialmedia a.twitter:hover {background-position: left top;}
like image 780
Frank G. Avatar asked Jan 13 '23 00:01

Frank G.


2 Answers

Just get more specific.

Change:

.socialmedia ul li {margin: 0px; padding: 0px;}

to

#footer .socialmedia ul li {margin: 0px; padding: 0px;}

jsFiddle example

You had the right idea but the #footer ul li rule is more specific, so it's CSS was overriding your other rule. You can learn more about CSS specificity at https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

like image 92
j08691 Avatar answered Jan 22 '23 06:01

j08691


try adding #footer .socialmedia ul li {margin: 0px; padding: 0px;} to override css rules in children elements your css selector should be more specific than the one you are trying to override.

like image 38
what is sleep Avatar answered Jan 22 '23 07:01

what is sleep