\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{raposinha} \pdfinfo{ /Title (css.pdf) /Creator (Cheatography) /Author (raposinha) /Subject (CSS 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}{A3A300} \definecolor{LightBackground}{HTML}{F9F9EF} \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{CSS Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{raposinha} via \textcolor{DarkBackground}{\uline{cheatography.com/197915/cs/41891/}}} \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}raposinha \\ \uline{cheatography.com/raposinha} \\ \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 8th January, 2024.\\ 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*}{3} \begin{tabularx}{5.377cm}{x{1.55618 cm} x{1.51041 cm} x{1.51041 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Selectors}} \tn % Row 0 \SetRowColor{LightBackground} Style x element(s) with y class & p.first & x.y \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Style selector with x tag & a{[}href{]} & s{[}x{]} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Style selector with x tag with exact y content & a{[}href="http://google.com"{]} & s{[}x="y"{]} \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} Style selector with x tag containing y & a{[}href*="google"{]} & s{[}x*="y"{]} \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} Style selector with x tag starting by y & a{[}href\textasciicircum{}="https"{]} & s{[}x\textasciicircum{}="y"{]} \tn % Row Count 16 (+ 4) % Row 5 \SetRowColor{white} Style selector with x tag ending by y & a{[}href\$="org"{]} & s{[}x\$="y"{]} \tn % Row Count 19 (+ 3) % Row 6 \SetRowColor{LightBackground} Style selector with x tag starting by y and ending by z & a{[}href\textasciicircum{}="https"{]}{[}href\$="org"{]} & s{[}x\textasciicircum{}="y"{]}{[}x\$="z"{]} \tn % Row Count 24 (+ 5) % Row 7 \SetRowColor{white} Style descendant selectors (element inside element) & .class div & s x \tn % Row Count 28 (+ 4) % Row 8 \SetRowColor{LightBackground} Style direct descendant selectors (direct element child inside element) & .class \textgreater{} div & s \textgreater{} x \tn % Row Count 34 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.55618 cm} x{1.51041 cm} x{1.51041 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Selectors (cont)}} \tn % Row 9 \SetRowColor{LightBackground} Style direct sibling to element & .class + div & s + x \tn % Row Count 3 (+ 3) % Row 10 \SetRowColor{white} Select direct siblings after element & .class \textasciitilde{} div & s \textasciitilde{} x \tn % Row Count 6 (+ 3) % Row 11 \SetRowColor{LightBackground} & Concepts & \tn % Row Count 7 (+ 1) % Row 12 \SetRowColor{white} Specificity or weight & If multiple rules target the same element, the browser will apply the most specific. & ID selector \textgreater{} class, attribute selectors \textgreater{} element selector \tn % Row Count 14 (+ 7) % Row 13 \SetRowColor{LightBackground} & To overrule specifity, !important can be used & color: royalblue !important; \tn % Row Count 18 (+ 4) % Row 14 \SetRowColor{white} & Combining id and class will give us higher specificity & \seqsplit{.highlight\#product} \tn % Row Count 23 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.70043 cm} x{1.41887 cm} p{0.4577 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Pseudo-class selectors}} \tn % Row 0 \SetRowColor{LightBackground} Style first child of x element & x \seqsplit{:first-child} & \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Style last child of x element & x :last-child & \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Style each first x child element of each type & x \seqsplit{:first-of-type} & \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Style each last x child element of each type & x \seqsplit{:last-of-type} & \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Style odd child elements of x & x \seqsplit{y:nth-child(odd)} & \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} Style visited URL & a:visited & \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} Style all link anchors & a:link & \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} Style element when hovered over & x:hover & \tn % Row Count 14 (+ 2) % Row 8 \SetRowColor{LightBackground} Style element when selected & x:focus & \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Pseudo-element selectors}} \tn % Row 0 \SetRowColor{LightBackground} Style first letter inside element & p::first-letter \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Style first line inside element & p::first-line \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Change selection to another color & ::selection \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Change selection of element to another color & p::selection \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} Insert content before element and incrust into DOM & ::before \{ content: "..."; display: block\} \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} Insert content after element and incrust into DOM & ::after \{ content: "...";\} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.53367 cm} x{1.44333 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Inheritance}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Child elements autimatically inherit some styles from parents.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} To stop from doing this, we use the 'initial' property on the child & color: initial; \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} Styles that aren't inherited can be forced to be, such as border with 'inherit'. & border: inherit; \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.87657 cm} x{1.87657 cm} x{0.82386 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Colors}} \tn % Row 0 \SetRowColor{LightBackground} RGB & Amount of Red Green and Blue & hsl( 1, 2, 3) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} RGBA & Amount of Red Green and Blue with added Alpha (amount of transparecy) & hsl( 1, 2, 3, 4\%) \tn % Row Count 7 (+ 5) % Row 2 \SetRowColor{LightBackground} HEX & Value representing numbers in the RGB system & \seqsplit{\#abc123} \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} HSL & Hue (tone) Saturation (percentage of saturation) and Lighting (the amount of lightness) & hsl( 1, 2\%, 3\%) \tn % Row Count 16 (+ 6) % Row 4 \SetRowColor{LightBackground} HSLA & Hue (tone) Saturation (percentage of saturation) and Lighting (the amount of lightness), Alpha (Transparency) & hsl( 1, 2\%, 3\%, 4) \tn % Row Count 23 (+ 7) % Row 5 \SetRowColor{white} & {\bf{Gradients}} & \tn % Row Count 24 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{They're technically images, so the properties used for colors don't work the same} \tn % Row Count 26 (+ 2) % Row 7 \SetRowColor{white} Fill background with a linear gradient & background: \seqsplit{linear-gradient(blue},red); & \tn % Row Count 29 (+ 3) % Row 8 \SetRowColor{LightBackground} From left to right & background: \seqsplit{linear-gradient(to} right, blue,red); & \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.87657 cm} x{1.87657 cm} x{0.82386 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Colors (cont)}} \tn % Row 9 \SetRowColor{LightBackground} From bottom right & background: \seqsplit{linear-gradient(to} bottom right, blue,red); & \tn % Row Count 4 (+ 4) % Row 10 \SetRowColor{white} & background: \seqsplit{linear-gradient(45deg}, blue,red); & \tn % Row Count 7 (+ 3) % Row 11 \SetRowColor{LightBackground} Same thing, mostly red & \seqsplit{linear-gradient(45deg}, blue,red 90\%); & \tn % Row Count 10 (+ 3) % Row 12 \SetRowColor{white} 3 color linear gradient & \seqsplit{linear-gradient(45deg}, blue, red, yellow; & \tn % Row Count 13 (+ 3) % Row 13 \SetRowColor{LightBackground} Radial gradient & \seqsplit{radial-gradient(blue}, red) & \tn % Row Count 15 (+ 2) % Row 14 \SetRowColor{white} Radial gradient with rounder center & \seqsplit{radial-gradient(circle}, blue, red) & \tn % Row Count 18 (+ 3) % Row 15 \SetRowColor{LightBackground} Radial gradient with circle centre located at the top left & \seqsplit{radial-gradient(circle} at top left, blue, red) & \tn % Row Count 22 (+ 4) % Row 16 \SetRowColor{white} Websites to generate gardients & cssgradient.io & \tn % Row Count 24 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.78503 cm} x{1.3731 cm} x{1.41887 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Borders}} \tn % Row 0 \SetRowColor{LightBackground} border: & 10px & line width \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & solid, dotted, dashed, & line style \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} & blue & color \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{3}{x{5.377cm}}{border-top} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{border-bottom} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} The order of the border lines matters: & top, right, bottom, left & \seqsplit{border-width:} 10px 20px 10px 30px \tn % Row Count 9 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{If we don't set left, left will inherit right. If we don't set top, bottom will inherit top. And viceversa.} \tn % Row Count 12 (+ 3) % Row 7 \SetRowColor{white} Set a style for each line in borders & \seqsplit{border-style:} dotted, dashed & \tn % Row Count 15 (+ 3) % Row 8 \SetRowColor{LightBackground} Set a color for each line in borders & \seqsplit{border-color:} red, blue, yellow; & \tn % Row Count 18 (+ 3) % Row 9 \SetRowColor{white} Set roundness of borders. If absolute a circle is created. & \seqsplit{border-radius} & px, \% \tn % Row Count 22 (+ 4) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{We can make even more shapes, just look up CSS Shapes} \tn % Row Count 24 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.53827 cm} x{2.43873 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Shadows}} \tn % Row 0 \SetRowColor{LightBackground} The box-shadow property can be used to create shadows around elements. & box-shadow \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Positive values will shift the shadow to the right. & box-shadow: 10px; \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} Negative values will shift the shadow to the left. & box-shadow: -10px; \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} Two positive values will shift the shadow to the right and down. & box-shadow: 10px 10px; \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} One positive value and one negative value will shift the shadow to the right and left. & box-shadow: 10px -10px; \tn % Row Count 19 (+ 5) % Row 5 \SetRowColor{white} One negative value and one positive value will shift the shadow to the left and right. & box-shadow: -10px 10px; \tn % Row Count 24 (+ 5) % Row 6 \SetRowColor{LightBackground} To change the color of the shadow, just add it after size & box-shadow: -10px 10px grey; \tn % Row Count 27 (+ 3) % Row 7 \SetRowColor{white} To change the degradation or blur of the color of the shadow, add a value before color color & box-shadow: -10px 10px 10px grey; \tn % Row Count 32 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.53827 cm} x{2.43873 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Shadows (cont)}} \tn % Row 8 \SetRowColor{LightBackground} For a soft central shadow under a shape, use this trick: & box-shadow: 0 0 30px grey; \tn % Row Count 3 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{We can also use {\bf{shadows for text}}} \tn % Row Count 4 (+ 1) % Row 10 \SetRowColor{LightBackground} We use the property text-shadow just like box-shadow & text-shadow: 0 0 30px grey; \tn % Row Count 7 (+ 3) % Row 11 \SetRowColor{white} For a softer grey shadow, we can use rgba & text-shadow: 0 0 30px rgba(0,0,0,0.2); \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Spacing}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{margin} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{padding} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}