\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Bikathi Martin} \pdfinfo{ /Title (css3.pdf) /Creator (Cheatography) /Author (Bikathi Martin) /Subject (CSS3 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{18AB70} \definecolor{LightBackground}{HTML}{F0F9F6} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{CSS3 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Bikathi Martin} via \textcolor{DarkBackground}{\uline{cheatography.com/146580/cs/31729/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Bikathi Martin \\ \uline{cheatography.com/bikathi-martin} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 18th April, 2022.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{1.976 cm} x{3.344 cm} x{2.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{CSS Selectors}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Selector}} & {\bf{Target}} & {\bf{Example}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Element Selector & Select a HTML element. & `p \{ CSS Code Here \}` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Id Selector & Select HTML element by ID & `\# \{ CSS Code Here \}` \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Class Selector & Select HTML element by Class & `. \{ CSS Code Here \}` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Element + Class Selector & Select elements marked with a specific Class & `p.par1 \{ CSS Code Here \}` \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} Universal Selector & Select every element in a HTML file & ` * \{ CSS Code Here \}` \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} Grouping Selector & Select multiple elements at once & `h1,p,tr \{ CSS Code Here \}` \tn % Row Count 17 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{0.988 cm} x{3.344 cm} x{3.268 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Adding CSS Into HTML}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Option}} & {\bf{Example Code}} & {\bf{Use Case}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{External} CSS & `\textless{}link rel="stylesheet" href="mystyle.css"\textgreater{}` & Link to an external CSS file \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{Internal} CSS & `\textless{}style\textgreater{}\{ CSS Code Here\}\textless{}/style\textgreater{}` & Add CSS to the `\textless{}head\textgreater{}` section of your HTML file \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{Inline} CSS & `\textless{}p style="color:red;"\textgreater{}This is a paragraph.\textless{}/p\textgreater{}` & Add CSS directly into a HTML element \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{{\bf{Note}} that the order of preference for selecting which CSS to run is: Inline Style has highest priority, then External and Internal Styles, and finally browser default styles.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.9 cm} x{2.812 cm} x{2.888 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{CSS Borders}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Property}} & {\bf{Example Values}} & {\bf{Effects}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{`border-style`} & `dotted`, `dashed`, `solid`, `double`, `groove`, `ridge`, `inset`, `outset`, `none`, `hidden` & Kind of border to display. Values can be combined \tn % Row Count 9 (+ 7) % Row 2 \SetRowColor{LightBackground} \seqsplit{`border-width`} & `medium`, `thick`, `2px`, `2in` ... & Specify width of the four borders \tn % Row Count 12 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{`border-color`} & RGB, names, HSL, HEX... & Color of the borders \tn % Row Count 14 (+ 2) % Row 4 \SetRowColor{LightBackground} `border-\{side\}-\{property\}` & & Specify a \seqsplit{border-property} for a specific side \tn % Row Count 17 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{`border-radius`} & `2px`, `10px` ... & How much the border corners should be rounded \tn % Row Count 20 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{`border-spacing`} & `20px, 30px` (horizontal then vertical space) ... & Set space between cells of table \tn % Row Count 24 (+ 4) % Row 7 \SetRowColor{white} \seqsplit{`border-collapse`} & `collapse`, `separate` & Whether borders of table cells should be joint or not \tn % Row Count 28 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{Note that none of the other border properties will work without specifying a `border-style` first. \newline If `border-color` is not set, it inherits the color of the parent. \newline To set border-\{property\} for specific sides do: `border-\{property\}: \{top\} \{right\} \{bottom\} \{left\}` or `border-\{property\}: \{top\&bottom\} \{right\&left\}` or `border-\{property\}: \{top\} \{right\&left\} \{bottom\}` \newline {\bf{Border shorthand}} is `border: \{width\} \{style\} \{color\}`. \newline `border-collapse` can be used with `border-spacing` to style tables.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{CSS Margins}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Property}} & {\bf{Use Case}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `margin-\{individual-side\}` & Which border sides do you want to add margin to \tn % Row Count 3 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Margin is the space around the border of an element. Available sides are {\bf{top}}, {\bf{bottom}}, {\bf{left}}, {\bf{right}}. \newline Margin values should be in {\bf{px}}. `margin: auto` means horizontally center the element within its container, and `margin: inherit` means inherit margin from parent element. \newline Shorthand `margin` applies margin values to all four sides of a border. \newline When two margins border each other, they {\bf{collapse}} into one, the largest one. (Only for top and bottom margins)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.2 cm} x{4.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{CSS Padding}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Property}} & {\bf{Use Case}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `padding-\{individual-side\}` & Which border side do you want to add padding to \tn % Row Count 3 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Padding}} is the distance between an element and its border. Values can be in {\bf{length}} e.g 2px, {\bf{\%}} (percentage of the width of the containing element), or {\bf{inherit}} (from parent element). \newline You can use the shorthand `padding` to set padding on all sides. \newline If an element has a specified width, adding padding will add to the initial width.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.76 cm} p{0.76 cm} p{0.76 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{CSS Outlines}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.204 cm} x{2.66 cm} x{2.736 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{CSS Color Options}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Option}} & {\bf{?}} & {\bf{Example}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Color names & Use the exact color name & red, green, blue etc. \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} RGB (Red Green Blue) & Use RGB values to produce a color & `rgb(255, 255, 255)` produces white \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} RGBA (Red Green Blue Aplha) & Use RGB with an opacity (alpha) & `rgba(123, 45, 67 0.4)` produces a color that `40\%` transparent \tn % Row Count 11 (+ 5) % Row 4 \SetRowColor{LightBackground} HEX & Use hexadecimal values to produce colors & `\#ffffff` produces white \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} HSL (Hue Saturation Light) & Use HSL to produce colors & `hsl(120, 50\%, 100\%)` produces a 50\% green color \tn % Row Count 18 (+ 4) % Row 6 \SetRowColor{LightBackground} HSLA(Hue Saturation Light Alpha) & Use HSL with opacity (alpha) & `hsla(120, 50\%, 100\%, 0.4)` produces a 50\% green color that's 40\% opaque \tn % Row Count 24 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.064 cm} x{3.496 cm} x{3.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{CSS Width, Max-Width, and Height}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Property}} & {\bf{Example Values}} & {\bf{Use Case}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{`height`} & `auto`, `length`, `initial`, `inherit`, `2\%`, & Set the height of an element \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{`width`} & `auto`, `length`, `initial`, `inherit`, `2\%`, & Set the width of an element \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{`max-width`} & `"..."`, `none` & Set the maximum width of an element \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{{\bf{auto}} means the computer will calculate the heights and widths for you. {\bf{Initial}} means default value. {\bf{Inherit}} means get values from parent element. \newline For `width`, use the `\%` so that it can be scaled as a percentage of the parent width. {\bf{max-width}} allows the browser to better handle horizontal scrollbars when the available view port width becomes smaller than, say, the size of a `div`. \newline When using `max-width`, don't give an element a `width`. The latter overrides the former.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{CSS Box Model}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/bikathi-martin_1650263089_Screenshot from 2022-04-18 09-21-15.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Every HTML element has layers around it, which we call a {\bf{box}}. {\bf{Content}} is what's in the layers e.g text. {\bf{Padding}} is transparent area around the content. {\bf{Border}} is area enclosing content and padding. {\bf{Margin}} is transparent area around the border. \newline Setting the `width` and `height` of an element with CSS, just sets the width and height of the content area. To calculate the full size of an element, you must also add `padding`, `borders` and `margins`.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.672 cm} x{2.964 cm} x{2.964 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{CSS Backgrounds}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Property}} & {\bf{Example Values}} & {\bf{Effects}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{`background-color`} & `red`, `rgba(0, 123, 45, 0.6)`, hsl(65, 34\%, 100\%) & Color for the background \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{`opacity`} & `0.0` (0\% opaque), `1.0` (100\% opaque) & Opacity for the background color \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{`background-image`} & url("\{ link to image \}") & Background image for your page \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{`background-repeat`} & `repeat-x` (horizontally), `repeat-y` (vertically), `no-repeat` & Image should be repeated/ no image repetition \tn % Row Count 17 (+ 5) % Row 5 \SetRowColor{white} \seqsplit{`background-position`} & `top`, `bottom`, `left`, `right`, `center` `bottom 10px` (offset from position) & Position of the background image \tn % Row Count 23 (+ 6) % Row 6 \SetRowColor{LightBackground} \seqsplit{`background-attachment`} & `fixed`, `scroll` & Image should scroll with the page or not \tn % Row Count 26 (+ 3) % Row 7 \SetRowColor{white} \seqsplit{`background-size`} & `100\%` (100\% of available screen width) & Size of the background image \tn % Row Count 29 (+ 3) % Row 8 \SetRowColor{LightBackground} \seqsplit{`background-clip`} & `border-box`, `padding-box`, `content-box` & How far the background (image or color) should extend within an element \tn % Row Count 34 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{1.672 cm} x{2.964 cm} x{2.964 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{CSS Backgrounds (cont)}} \tn % Row 9 \SetRowColor{LightBackground} \seqsplit{`background-origin`} & `border-box`, `padding-box`, `content-box` & Origin position of a background image \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{{\bf{NOTE}} that the background-\{property\} properties can be combined into one shorthand like this: \newline `background: `\{-color\}` `\{-image\}` `\{-repeat\}` `\{-attachment\}` `\{-position\}`;` \newline For `background-clip`, {\bf{border-box}} makes background to extend beyond the border, {\bf{padding-box}}, background extends to the inside edge of the border, {\bf{content-box}}, background extends to the edge of the content box e.g around a paragraph. With `background-origin`, it's the same dimensions.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}