Solved

How to add to or override part of a class definition

Posted on 2014-12-12
3
131 Views
Last Modified: 2014-12-12
In my file, I have a pre-set definition of a class, say ".nav", and it has a number of properties:

.nav {position: relative; width: 980px; display: inline-block; border-bottom: 1px solid #126a13; padding: 12px 0 8px 0; background: url('images/nav_bg.gif') repeat-x top center; clear: both; text-transform: uppercase; line-height: 1em; font-weight: 400;}

Lower in the page, I want to be able to replace just one property, the background, with a new value e.g.

.nav {background: url('../../../image-new/nav_bg_new.gif')}

The problem is that it seems to replace the entire first definition of .nav, instead of replacing just the one value, for backgroun. Alternatively I can get the desired effect by repeating the entire first class definition with the one value changed, but I wonder if there is a way in CSS to say "keep all the existing properties, just replace this one". Thanks in advance.
0
Comment
Question by:opalcomp
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40495695
"keep all the existing properties, just replace this one".
No but that is the way it works.  However the original background defintion is "background: url('images/nav_bg.gif') repeat-x top center;" and your replacement is "background: url('../../../image-new/nav_bg_new.gif')".  Note that you do not have a ';' at the end of your replacement.  Under some circumstances that can throw things off.  It never hurts to add it like "background: url('../../../image-new/nav_bg_new.gif');".
0
 
LVL 1

Author Closing Comment

by:opalcomp
ID: 40496029
Excellent, and thank you. I had not noticed the additional values that I omitted. I also added the trailing ";" to be safe. Now everything works and is cleanly coded. Much better. If interested, the site is http://tildet.com.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40496846
You're welcome, glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This article discusses four methods for overlaying images in a container on a web page
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now