Making changes to the CSS (Cascading Style Sheet) declarations applying to an HTML element can seem a complex task. However, as long as you approach it systematically, you should be able to make the changes you need without too much stress. A single Web page can use style properties from multiple sources, so your initial task will be to find out where the declarations for your "div" are coming from. Once located, you can stop the declarations from having an effect on the element by altering either the HTML or CSS code.
- Skill level:
Other People Are Reading
Find out where the Web page CSS code is stored. CSS code can appear in-line, which means style declarations are listed as part of an element's markup as in the following example syntax:
If this code appears within your "div" you can remove the entire "style" attribute along with its value. CSS code may appear within the head section of the page as follows:
CSS code may also appear in one or more separate CSS files with links in the page head section as follows:
<link rel="stylesheet" type="text/css" href="pagestyles.css" />
If your page has CSS code in the head or in separate files, you will need to look at all of this CSS code to alter the styling for your "div" element.
Check for CSS code referring to "div" elements. CSS can apply to an element type, as in the following example:
If the CSS in your page head or separate files has the "div" identifier used in this way, the code within the CSS block will be affecting your element. To change the effect on your "div" but leave the code to apply to other "div" elements in the site, you can change the "div" to a different element type. Alternatively, you can alter the CSS code to apply only to "div" elements with a particular class attribute, adding this attribute to those "div" elements you want the CSS to apply to.
Check for CSS code referring to your element class. HTML elements can have class attributes as follows:
<div class="top">Top content</div>
If your "div" has a class attribute, look for the attribute value in your CSS code. The attribute value can appear on its own as follows:
Alternatively it may appear along with the element type as follows:
If either of these appear, you can prevent the declarations from applying to your element by changing or removing its class attribute. Removing the CSS code may affect other elements with the class, not just the element you're working with.
Check for CSS code referring to your element ID. Your element may have a unique ID attribute as follows:
<div id="heading">Top content</div>
If your element has an ID attribute, check for it within the CSS by looking for the following syntax:
Within each page, an ID attribute value should only appear once, as the ID is meant to be unique. Changing the ID attribute value should prevent the CSS code from affecting the "div" element. You can optionally change or remove the CSS code, but this may affect elements with the same ID on other pages in your site if they use the same CSS code.
Check for CSS code affecting the parent or child elements of your "div." CSS code for parent elements will have a knock on effect on your "div" so you may need to make alterations to that code, although these changes may affect the rest of your site. Elements inside your "div" may also have tailored CSS code, so check for this using the same method you used for the "div" itself, working through the child elements in turn.
Tips and warnings
- Browser tools such as Firebug can be helpful when altering HTML and CSS code.
- Changes to an existing website can have unintended consequences. For this reason you may wish to save copies of any files you plan on changing.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for