Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to add to or override part of a class definition

Posted on 2014-12-12
3
Medium Priority
?
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 84

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
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…
Suggested Courses

636 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