From 863641afa60f46d271bf89dea256b2d42fe18de1 Mon Sep 17 00:00:00 2001
From: mjfernez
For any HTML tag, you can set an attribute that applies everytime it appears in an HTML document that links to the CSS file. A common formatting I use for paragraphs is:
-p {
- margin-top: 1.5%;
- margin-bottom: 1.5%;
-}
+
+ p {margin-top: 1.5%;
+ margin-bottom: 1.5%;
+ }
And to highlight code, like you've been seeing, I use:
-code {
- display: inline-block;
- font-size: 125%;
- background-color: #d8d8d8;
- white-space: pre-wrap;
- word-wrap: break-all;
-}
+
+ code {display: inline-block;
+ font-size: 125%;
+ background-color: #d8d8d8;
+ white-space: pre-wrap;
+ word-wrap: break-all;
+ }
I get pretty much all the attribute names just by looking them up here. But in order these lines:
Images get more styles in CSS than I can document in detail, but one important bit you'll want to probably add to all images is the following.
-img {
- max-width: 100%;
- height: auto;
- width: auto;
-}
+
+ img {max-width: 100%;
+ height: auto;
+ width: auto;
+ }
This does the following:
In addition to this basic stuff, you can style your images heavily using the filter option like so:
-img.gray {
- filter: grayscale(100%)
-}
+.gray {
+ imgfilter: grayscale(100%)
+ }
Applied:
You can read lots more options for image formatting here and about
@@ -520,19 +520,19 @@ the filter property For one, that will only dim black-and-white images; anything else
will just turn to mush like this: Instead, I'd like it to just apply to select elements; I can do so by
extending the tag with a class. On the CSS side: And to implement it in HTML:img {
- filter: invert(50%);
-}
+
+ img {filter: invert(50%);
+ }
+img.icon {
- filter: invert(50%);
-}
.icon {
+ imgfilter: invert(50%);
+ }
+<img class="icon" src="/static/media/rss.svg" />
.svg" /> <img class="icon" src="/static/media/rss
Use the div tag to make
sections
@@ -542,19 +542,19 @@ Let's say you wanted to center a heading, a paragraph, and a picture,
and constrain them to only part of the page, so that there's some
margins on the left and right. We can put them all in one content
section like this:
.content {
- text-align: center;
- max-width: 85%;
-}
+.content {
+text-align: center;
+ max-width: 85%;
+ }
Notice, no leading tag. This can be applied to any element, but usually we use a placeholder tag called "div." You can think of "div" like a divider for content of similar style. In the present example, we can use the class we made with a div tag:
-<div class="content">
-<h1>My cat</h1>
-<p>He's a cool cat</p>
-<img src="/cat.jpg" />
-</div>
+<div class="content">
+<h1>My cat</h1>
+<p>He's a cool cat</p>
+<img src="/cat.jpg" />
+</div>
In early development, reading this site on my phone was a painful experience. Fortunately, in addition to some tricks above like the @@ -563,12 +563,12 @@ allow you to directly manipulate your website based on properties of the user's device or web browser.
I won't go into as gory details as here or here, but for your basic smartphone, you can copy and paste this block:
-@media screen and (max-device-width: 480px) {
- // override your tags here
- body {
- font-size: 125%;
- }
-}
+@media screen and (max-device-width: 480px) {
+// override your tags here
+
+ body {font-size: 125%;
+
+ } }
This basic example makes the text slightly bigger on smartphone screens, but you can change everything you need to. I typically find I need to adjust the padding or the margins since it seems mobile browsers @@ -577,9 +577,9 @@ add a little more style than a typical desktop web browser.
your CSS attributes, so that size is always defined relative to all the other elements. This makes functions like zoom work a lot better. You can for example put a pixel value like this: -body {
- font-size: 14px;
-}
+
+ body {font-size: 14px;
+ }
But this binds the size to 14 pixels which may look great on desktop, but small on a smart phone.