Styles can be authored in several ways, allowing for varying degrees of reuse and scope when they are specified in a source HTML document. External stylesheets can be reused across HTML documents. Embedded stylesheets apply to the entire document in which they are specified. Inline styles apply only to the individual HTML element on which they are specified.
More on "Collapsing Margins": here.
Media queries are supported in all modern browsers, including Chrome, Firefox, Opera, and Internet Explorer 9 and up.
It is important to note that the orientation
media feature is not limited to mobile devices. It is based on the width and height of the viewport (not window or devices).
Landscape Mode is when the viewport width is larger than viewport height.
Portrait Mode is when the viewport height is larger than viewport width.
This usually translates to a desktop monitor being in landscape mode, but can it sometimes be portrait.
In most cases mobile devices will report their resolution and not their real pixel size which can differ due to pixel density. To force them to report their real pixel size add the following inside your head
tag:
<meta name="viewport" content="width=device-width, initial-scale=1">
As float implies the use of the block layout, it modifies the computed value of the display values in some cases [1]
[1]: https://developer.mozilla.org/en-US/docs/Web/CSS/float MDN
text-shadow
property is not supported by versions of Internet Explorer less than 10.CSS specificity intends to promote code conciseness by allowing an author to define some general formatting rules for a broad set of elements, and then to override them for a certain subset.
::
) instead of just one (:
). This is a way to separate pseudo-classes from pseudo-elements.:
) for defining pseudo-elements.Some older browsers support only vendor-prefixed transition
properties:
-webkit
: Chrome 25-, Safari 6-, Safari & Chrome for iOS 6.1-, Android 4.3- Browser, Blackberry Browser 7-, UC Browser 9.9- for Android.-moz
: Firefox 15-.-o
: Opera 11.5-, Opera Mobile 12-.Example:
-webkit-transition: all 1s;
-moz-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
A whitespace cannot appear between the number and the unit. However, if the value is 0, the unit can be omitted.
For some CSS properties, negative lengths are allowed.
Sometimes you will see double colons (::
) instead of just one (:
). This is a way to separate pseudo-classes from pseudo-elements, but some older browsers like Internet Explorer 8 only supports single colon (:
) for pseudo-elements.
One can use only one pseudo-element in a selector. It must appear after the simple selectors in the statement.
Pseudo-elements are not a part of the DOM, therefore are not targetable by :hover
or other user events.
Normal Flow is the flow of elements if the position of element is static.
Transforms are made according to a 2D X/Y coordiante system. The X axis goes from right to left and the Y axis goes downwards as shown in the following image:
So a positive translateY()
goes downwards and a positive translateX()
goes right.
-ms-
prefix. Older versions and Edge don't need the prefix-moz-
prefix until version 15-webkit-
prefix-webkit-
prefix until version 8-o-
prefix for version 11.5 and the -webkit-
prefix from version 15 to 22-webkit-
prefix from version 2.1 to 4.4.4-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
These properties apply to both <table>
elements (*) and HTML elements displayed as display: table
or display: inline-table
(*) <table>
elements are obviously natively styled by UA/browsers as display: table
HTML tables are semantically valid for tabular data. It is not recommended to use tables for layout. Instead, use CSS.
Vendor prefixes are used to allow preview support for new CSS functionality where the functionality is not yet recommended by the specification.
It is recommended that you do not use vendor prefixes in production environments. These prefixes exist to test new functionality that is not yet finalized, and behavior is inherently unexpected. Simply using prefixes does not grant browser support for old browsers as you cannot guarantee the feature hasn't changed over time to perform differently, and it could still be broken in those old browsers you claim to support.
If supporting older browsers is important, you should instead consider using JavaScript or other solutions to imitate the effects and truly guarantee support for old browsers.
Browsers will use their prefixes and ignore the properties they don't understand.
NOTE: Prefixes should always appear before the official, unprefixed syntax. Otherwise they would be overwritten with the prefixed properties, which can be another implementation in the end.
If a browser supports both an unprefixed and prefixed version of a property, the most recent property to be declared will take precedence.
Meyer's Reset, while effective, makes the same changes to nearly every commonly used element. This has the result of polluting web browser inspector windows with the same applied styles over and over again, and creates more work for the browser (more rules to apply to more elements). The Normalize technique, on the other hand, is much more focused and less of a broad-brush technique. This simplifies the work on the part of the browser, and results in less clutter in the browser inspection tools.
1: https://developer.mozilla.org/en/docs/Web/CSS/padding MDN
Also see this question, "Why does CSS not support negative padding?" and his answers.
Also please consider The Box Model when using padding. Depending on the box-sizing value, padding on an element can either add to the previously defined height/width of an element or not.
Related Properties:
Padding on inline elements will only apply to the left and right of the element, and not the top and bottom, due to the inherent display properties of inline elements.
Since filter is an experimental feature, you should use the -webkit prefix. It may change in syntax and behavior, but the changes are probably going to be small.
It might not be supported in older versions of major browsers. It might be entirely unsupported in mobile browsers.
Due to its relatively limited support, try to use box-shadow
instead of filter: drop-shadow()
. Use opacity
instead of filter: opacity()
.
It can be animated through Javascript/jQuery. For Javascript, use object.style.WebkitFilter
.
W3Schools also has a demo page for all the different type of filter values.
/*
and end with */
Browser Support:
CSS Variables are currently considered an experimental technology.
Firefox: Version 31+ (Enabled by default)
Chrome: Version 49+ (Enabled by default).
"This feature can be enabled in Chrome Version 48 for testing by enabling the experimental Web Platform
feature. Enter chrome://flags/
in your Chrome address bar to access this setting."
IE: Not Supported.
Edge: Under Development
Safari: Version 9.1+
Browser support for the CSS Shapes module is very limited at this point in time.
It is supported in Chrome v37+ and Opera 24+ without browser/vendor prefixes. Safari supports it from v7.1+ but with the -webkit-
prefix.
It is not yet supported in IE, Edge and Firefox.
CSS Grid Layout Module Level 1 is, as of 9 September 2016, a W3C Candidate Recommendation. It is considered to be in the Testing stage (https://www.w3.org/Style/CSS/current-work).
As of 3 July 2017, Microsoft's Internet Explorer 10 and 11 and Edge browsers only support an older version of the specification using a vendor prefix.
Related properties:
border
border-bottom
border-bottom-color
border-bottom-left-radius
border-bottom-right-radius
border-bottom-style
border-bottom-width
border-color
border-image
border-image-outset
border-image-repeat
border-image-slice
border-image-source
border-image-width
border-left
border-left-color
border-left-style
border-left-width
border-radius
border-right
border-right-color
border-right-style
border-right-width
border-style
border-top
border-top-color
border-top-left-radius
border-top-right-radius
border-top-style
border-top-width
border-width
For calc()
, white space is required around the "-
" and "+
" operators, but not the "*
" or "/
" operators.
All units must be of the same type; trying to multiply a height by a time duration, for example, is invalid.
3D transforms are made according to an (x, y, z)
coordinate vector system in Euclidean space.
The following image shows an example of coordinates in Euclidean space:
In CSS,
x
axis represents the horizontal (left and right)y
axis represents the vertical (up and down)z
axis represents the depth (forward and backward/closer and further)The following image shows how these coordinates are translated in CSS:
Counters are not a new topic in CSS. It was a part of the CSS Level 2 Specifications (Revision 1 to be precise) itself and hence has very high browser support.
All browsers except IE6 and IE7 have support for CSS Counters.
If you do not want apply opacity, you can use this instead:
background: rgba(255, 255, 255, 0.6);
Resources:
For some use cases, sprites are slowly falling out of favor, being replaced by icon webfonts or SVG images.
CSS Clipping and Masking are very new concepts and so the browser support for these properties are pretty low.
As at the time of writing (Jul '16), Chrome, Safari and Opera support these properties with the -webkit-
prefix.
Firefox doesn't require prefixes but it supports masks only when used with SVG mask
elements. For inline SVG mask
elements, the syntax is mask: url(#msk)
whereas for using mask
elements in an external SVG file the syntax is mask: url('yourfilepath/yourfilename.svg#msk')
. #msk
in both cases refers to the id
of the mask
element that is being referred to. As indicated in this answer, at present Firefox doesn't support any parameter other than mask-reference
in the mask
property.
Internet Explorer (and Edge) does not offer any support for this property as yet.
The mask-mode
property is currently not supported by any browser with or without prefixes.
As at the time writing (Jul '16) Chrome, Safari and Opera supports clip-path
when the path is created using basic shapes (like circle
, polygon
) or the url(#clipper)
syntax with inline SVG. They don't support clipping based on shapes that are part of external SVG files. Also, they require the -webkit
prefix to be present.
Firefox supports only the url()
syntax for clip-path
whereas Internet Explorer (and Edge) offer no support.
Although the list-style-type
is actually a property that applies only to list items (normally <li>
), it is often specified for the list tag (<ol>
or <ul>
). In this case, the list items inherit the property.
outline
is now described in Basic UI, a CSS Module Level 3 (it was already described in REC CSS2.1)
Outline property is defined by default in browsers for focusable elements in :focus
state.
It shouldn't be removed, see http://outlinenone.com which states:
What does the outline property do?
It provides visual feedback for links that have "focus" when navigating a web document using the TAB key (or equivalent). This is especially useful for folks who can't use a mouse or have a visual impairment. If you remove the outline you are making your site inaccessible for these people. (…)
Interesting related examples on Stack Overflow:
For ease of readability, keep all declarations indented one level from their selector, and the closing curly brace on its own line. Add a single space after selectors and colons, and always place a semicolon after the final declaration.
p {
color: maroon;
font-size: 16px;
}
p{
color: maroon;
font-size:16px }
If there are only one or two declarations, you might get away with this one. Not recommended for most cases. Always be consistent when possible.
p { color: maroon; font-size: 16px; }
There is no page-break property in CSS. Only the 3 properties (page-break-before, page-break-after, page-break-inside).
Related: orphans
, widows
.
When an element is too small to display it's contents, what happens? By default, the content will just overflow and display outside the element. That makes your work look bad. You want your work to look good, so you set the overflow property to handle the overflowing content in a desirable way.
Values for the overflow
property are identical to those for the overflow-x
and overflow-y
properties, exept that they apply along each axis
The overflow-wrap
property has also been known as the word-wrap
property.
Important note: Using the overflow property with a value different to visible will create a new block formatting context.
The CSS Object Model (CSSOM) is a specification on its own.
The current draft can be found here: https://www.w3.org/TR/cssom-1/
Feature detection using @supports
is supported in Edge, Chrome, Firefox, Opera, and Safari 9 and up.
These “hacks” may be used to target a specific browser/client. This may be used to work around browser rendering differences by applying styles in one of those wrappers listed above.
[A block formatting context is a part of a visual CSS rendering of a Web page. It is the region in which the layout of block boxes occurs and in which floats interact with each other.][1]
[1]: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context MDN
This is used when the element's dimensions (width
and height
) are not known or dynamic.
Prefer to use Flexbox over all other options as it is optimized for user interface design.
The properties object-fit
and object-position
are not supported by Internet Explorer.
CSS Multi-column Layout Module Level 1 is, as of 12 April 2011, a W3C Candidate Recommendation. Since then, a few smaller changes were made. It is considered to be in the Stable stage.
As of 3 July 2017, Microsoft's Internet Explorer 10 and 11 and Edge browsers only support an older version of the specification using a vendor prefix.
These examples are for documenting CSS-specific methodologies / design patterns.
These methodologies include but are not exclusive to the following:
These examples are NOT for documenting CSS frameworks like Bootstrap or Foundation. While you may include examples of how to apply one or more CSS methodology / design pattern with a CSS framework, those examples are to focus on the methodologies / design patterns with that particular framework and on the use of the framework itself.