CSS: how to add a style to everything, unless it is defined


Tags: css

Problem :

If I add a style like:

* {
  font-size: 14px;
}

and later I define for an element:

#myElement {
  font-size: 18px;
}

The fist one will override the second one.

Is there a way to define the first one, such as the second one will override it, and the 14px size will be applied to all the elements that don't define a size?

(I would like alternatives to the use of classes)



Solution :

The element #myElement will override the first rule as it is more specific. If #myElement has children then the children will match the global selector. Try setting the rule on body.


    CSS Howto..

    How do I add extra slides to this pure CSS text rotator?

    How to make a background-color transition that eventually covers div to center? [closed]

    how to create circle that cut off one piece with css

    How do I lock a sidebar to the height of a window even when a user scrolls?

    “Best fit” font size - how do I measure a sentence width?

    Primefaces: how to change the default icon on the button of the calendar field?

    How to use animation with transform CSS

    Only Javascript code to show a class without onclick

    How to align an icon to the right of content

    How do I add HTML files to a GitHub repo?

    CSS How to get height between header and footer?

    How can I put styleName (css) on ui.xml to HTML5 input element (range)

    CSS selector: how to style items [1-2][5-6][9-10] etc by pair

    How can I align unsorted list horizontly ?

    How to enable -webkit-animation/transition-property for :before and :after pseudo elements?

    Hide all, show a class with css

    how to dynamically change the property of css using jquery

    CSS How to make text align background-color top line

    How to change an image in CSS that has no class?

    How can I allow resizable() to increase size beyond initial size?

    How to set a css style to the last item of CListView?

    How to show local html file into webview?

    How do I use CSS to reposition this image?

    How to prevent span from growing with content

    how to use both fixed and relative position property in same page using css?

    Bootstrap css, how to make always visible navbar-toggle?

    Why are items showing up in my instead of [closed]

    How to design a web page with multiple color panes without tables [duplicate]

    How to stop text in div pushing other divs down the page?

    How to find all possible CSS Styles and Attributes of an Element?