|
1 | 1 | # WTF, HTML and CSS?
|
2 | 2 |
|
3 |
| -Open an issue or a pull request to suggest changes or additions. Support for items listed below is not provided. Links to additional resources are provided whenever possible. |
| 3 | +**WTF, HTML and CSS?** is a list of reasons your shit is fucked. Put another way, it's a list of common HTML and CSS quandaries, miscues, and dilemmas created with the goal of making them *less* common. |
4 | 4 |
|
5 |
| -### Contents |
| 5 | +**[Start reading ☞](http://wtfhtmlcss.com)** |
6 | 6 |
|
7 |
| -- [Set your doctype](#set-your-doctype) |
8 |
| -- [Box model math](#box-model-math) |
9 |
| -- [Floats come first](#floats-come-first) |
10 |
| -- [Floats and clearing](#floats-and-clearing) |
11 |
| -- [Floats and computed height](#floats-and-computed-height) |
12 |
| -- [Vertical margins often collapse](#vertical-margins-often-collapse) |
13 |
| -- [Styling table rows](#styling-table-rows) |
14 |
| -- [Firefox fubars `<input>` buttons](#firefox-fubars-input) |
15 |
| -- [Always set a `type` on `<button>`s](#always-set-a-type-on-buttons) |
16 |
| -- [Internet Explorer's selector limit](#internet-explorers-selectors) |
17 |
| -- [Position explained](#position-explained) |
18 |
| -- [Position and width](#position-and-width) |
19 |
| -- [`transform` and `position: fixed`](#transform-and-position-fixed) |
| 7 | +--- |
20 | 8 |
|
21 |
| ------ |
| 9 | +### Contribute |
22 | 10 |
|
23 |
| -### Set your doctype |
24 |
| -Always include the HTML5 doctype, `<!DOCTYPE html>`, otherwise you'll run into tons of issues like malformed tables, inputs, and the like. |
| 11 | +Open an issue or a pull request to suggest changes or additions. |
25 | 12 |
|
26 |
| -### Box model math |
27 |
| -Elements that have a set `width` become *wider* when they have `padding` and/or `border-width`. To avoid these problems, make use of the now common [`box-sizing: border-box` reset](http://www.paulirish.com/2012/box-sizing-border-box-ftw/). |
28 | 13 |
|
29 |
| -### Floats come first |
30 |
| -Floated elements should always come first in the document order. Floats have to have something to wrap around, otherwise they can cause a step down effect. |
| 14 | +### License |
31 | 15 |
|
32 |
| -### Floats and clearing |
33 |
| -If you float it, you *probably* need to clear it. Any content that follows an element with a `float` will wrap around that element until cleared. Use [the micro clearfix](http://nicolasgallagher.com/micro-clearfix-hack/) to clear your floats. Setting `overflow: [hidden|auto]` on the parent of a floated element with will also work, with some side affects. |
| 16 | +Released under MIT by, and copyright 2014, @mdo. |
34 | 17 |
|
35 |
| -### Floats and computed height |
36 |
| -A parent element that has only floated content will have a computed `height: 0;`. Add a clearfix to the parent to trigger a proper computer height. |
37 |
| - |
38 |
| -### Floated elements are block level |
39 |
| -Any element with a `float` set automatically becomes `display: block`, thus you do not need to set a `float` and a `display`. Years ago we had to set `display: inline` for floats to work properly in IE6, but those days have passed. |
40 |
| - |
41 |
| -### Vertical margins often collapse |
42 |
| -Top and bottom margins can and will collapse in many situations, but never for floated or absolutely positioned elements. [Read this MDN article](https://developer.mozilla.org/en-US/docs/Web/CSS/margin_collapsing) to find out more. **Horizontal margins will never collapse.** |
43 |
| - |
44 |
| -### Styling table rows |
45 |
| -Table rows, `<tr>`s, cannot be styled unless you set `border-collapse: separate;` on the parent `<table>`. |
46 |
| - |
47 |
| -### Firefox fubars `<input>` buttons |
48 |
| -Don't use button or submit buttons (e.g., `<input type="button">...</input>` or `<input type="submit">...</input>`). Firefox still sets styles that cannot be overridden by custom CSS, thus causing these buttons to be taller than a `<button>` element. |
49 |
| - |
50 |
| -### Always set a `type` on `<button>`s |
51 |
| -The default value is `submit`, meaning any button in a form can submit the form. Use `type="button"` for anything that doesn't submit the form and `type="submit"` for those that do. |
52 |
| - |
53 |
| -### Internet Explorer's selector limit |
54 |
| -Internet Explorer 9 and below have a max of 4,096 selectors per stylesheet. Anything after this limit is ignored by the browser. Either split your CSS up, or start refactoring. I'd suggest the latter. |
55 |
| - |
56 |
| -### Position explained |
57 |
| -Elements with `position: fixed;` are placed relative to the browser viewport. Elements with `position: absolute;` are placed relative to their closest parent with a position other than `static` (e.g., `relative`, `absolute`, or `fixed`). |
58 |
| - |
59 |
| -### Position and width |
60 |
| -You don't need to set `width: 100%` on an element with `position: [absolute|fixed]` with both `left` and `right` values declared. Use either `width` or `left` and `right`, but not both. |
61 |
| - |
62 |
| -### `transform` and `position: fixed` |
63 |
| -`position: fixed` breaks when an element's parent has a `transform` set. Using transforms creates a new containing block, effectivly forcing the parent to have `position: relative` and the fixed element to behave as `position: absolute`. [See the demo](http://jsbin.com/yabek/1/) and read [Eric Meyer's post on the matter](http://meyerweb.com/eric/thoughts/2011/09/12/un-fixing-fixed-elements-with-css-transforms/). |
64 |
| - |
65 |
| ------ |
66 |
| - |
67 |
| -## Copyright and license |
68 |
| -Copyright Mark Otto and released under the MIT license. |
| 18 | +<3 |
0 commit comments