Some HTML elements have default sizes. For example, default for paragraph (<p>) text, is 16px.
You can change the size of text with the “font-size:” property in CSS
Relative Sizes in CSS
Relative sizes and measurements are a bit confusing to us newbies.
The em is simply the font size. In an element with a 2in font, 1em thus means 2in. Expressing sizes, such as margins and paddings, in em means they are related to the font size, and if the user has a big font (e.g., on a big screen) or a small font (e.g., on a handheld device), the sizes will be in proportion. Declarations such as text-indent: 1.5em and margin: 1em are extremely common in CSS.
Using an emvalue creates a dynamic or computed font size (historically the em unit was derived from the width of a capital “M” in a given typeface.). The numeric value acts as a multiplier of the font-size property of the element on which it is used. Consider this example:
In this case, the font size of <p> elements will be double the computed font-size inherited by <p> elements. By extension, a font-size of 1em equals the computed font-size of the element on which it is used.
If a font-size has not been set on any of the <p>‘s ancestors, then 1em will equal the default browser font-size, which is usually 16px.
So, by default 1em is equivalent to 16px, and 2em is equivalent to 32px.
If you were to set a font-size of 20px on the <body> element say, then 1em on the <p> elements would instead be equivalent to 20px, and 2em would be equivalent to 40px.
In order to calculate the em equivalent for any pixel value required, you can use this formula:
em = desired element pixel value / parent element font-size in pixels
For example, suppose the font-size of the <body> of the page is set to 16px. If the font-size you want is 12px, then you should specify 0.75em (because 12/16 = 0.75). Similarly, if you want a font size of 10px, then specify 0.625em (10/16 = 0.625); for 22px, specify 1.375em (22/16).
The em is a very useful unit in CSS since it automatically adapts its length relative to the font that the reader chooses to use.
When the font-size is specified as a percentage, it is relative to the parent element’s font size
Percent (%): The percent unit is much like the “em” unit, save for a few fundamental differences. First and foremost, the current font-size is equal to 100% (i.e. 12pt = 100%). While using the percent unit, your text remains fully scalable for mobile devices and for accessibility.
You can use percentage values. They act like em values.
The value is relative to the parent‘s font-size. As a result, the value will cascade if used on child elements.
The value is relative to the root element‘s font-size, which is the <html> element. As a result, the value will not vary depending on the depth of the element in the HTML hierarchy, and will reamin context independent.
“ the em unit means “my parent element’s font-size” in the case of typography”
The thing with percentages is that they are always set relative to some other value. For example, if you set an element’s font-size as a percentage, it will be a percentage of the font-size of the element’s parent. If you use a percentage for a width value, it will be a percentage of the width of the parent.
By default, in UK, USA etc. the text will be left aligned.
“text-align: center;” will align the text in the middle of the page or the element
Text-align: justify, will stretch the text across the page. Sounds weird but usually looks quite nice. I used to use this in Word for my uni assignments.
There are lots of ways to use “display” to present the text on your webpage.
W3 schools has a table full of all the values, including “inline” which is a pretty popular option
Let’s say you have made a grid, with 6 items, but you want the first one to be different to the rest. Probably the easiest way to achieve this, is to add a “.grid-item-1” styles section, below the CSS you’ve created for the rest of the grid items.
If you use the W3 try it yourself tool, remember to click “Run” on the top left, as the code doesn’t update real time.
css grid equal height rows
If you add the value/property thing in CSS, to the .grid-container section of the CSS (assuming you’ve named the class of your container .grid-container) to “grid-auto-rows: 1fr;” – then all the rows should be equal height. Or you could just set the heights to 100px each
I’ve made some notes on how to use the Inspect Element Tool – AKA Chrome Developer Tools.
Sorry about the change in layout for the images, I drafted this post on various computers and devices and used different software to annotate the screenshots.
The main thing that I use inspect element for at the moment, is to work out what’s cuasing
To launch Inspect Element right click and from the drop-down menu that appears, click “Inspect” at the bottom.
When you hover over any element, such as a H1 in the inspect-window, the element will also be highlighted in the view of the webpage.
The small horizontal bar shows the location of the element you’re hovering over or selected
Elements > Styles Tab
The styles tab, shows you the styles, or CSS for any element you’re hovering over on the webpage.
You can turn styles off and on, using the check box
on the opposite side of the style, it shows the location, or path of the CSS file
I use this tab a lot to find out where spacing i.e. margins and padding is coming from – if it’s not from the individual element, that I can click on the container (usually a “div) and check the marings and padding values on that.
You can also turn CSS styles on and off – a checkbox will appear next to each style when you hover over it
Right click – copy element – and you can paste headers, images etc into another location on the page
You can click & drag elements too
You can also search for specific styles using the box shown below:
-Computed Styles Tab
Computed styles, are the result of all the CSS in the Styles tab.
You can also clock the + icon to the right of .click, to add a new style to the elements tab. Remember to copy the css if you want to keep itz or you’ll lose it when you refresh the page.
You can use the horizontal box near the middle to search for styles and elements
– Forced Element State
With the Forced Element State menu open, you can tick different boxes and check how an element appears – for example a link, when it’s been clicked, or hovered over with the mouse.
– Console Tab
I’ve never got my head around this tab, but here goes.
Can use it to check code is working, for example any “if/else” code, you can check which “option” your code took
You can also see error messages
Refresh the page whilst you have the Console Tab open, you can check the console tab for any error messages
You’ll likely get a load of error messages if you have an Ad Blocker extension
You’ll get warnings and “violation” messages in yellow if you are using out of date frameworks or libraries e.g. JS
The “no entry” icon will clear the console messages
The two Youtube tutorial below, should start at the sections talking about the Console tab:
You can run your own JS in the console tab. For example type “alert(1)” and click enter, you’ll get a pop up with the text “1” within it
If you type in code, the line below will usually give you the return value. E.g. if you type “1+3” the return value will be “4”
“undefined” means there is no return value
$0 will return the last item you selected, $1 returns the second to last item you selected, $2 the third to last, etc.
Editing HTML in Visual Studio or another Code Editor
You can also type code into the “webpage window” to the left, in this example:
**You will probably have to refresh the page to see the code output if you don’t have a visual studio plugin**
In this tab, you can see every element, and when it has been loaded
Using the “time bar” at the top, you can click and drag over different time periods and see what loaded.
For example, you can see what took the longest to load
You may have to refresh the page for this to work ‘properly’
In the sources tab, you can navigate different files related to the webpage.
If you are on the homepage, clicking “index” will show you all the HTML code
It’s good for trying to fix code without editing to source files
I needed a way of combining a load of commerce product identifier numbers into one cell, separated by columns.
You can download the spreadsheet with the formula here.
Textjoin Formula Example
The comma in speech marks, adds the comma between the numbers Not sure what “TRUE” does to be honest! The F6:F35 is just the cells that the original list, that’s aligned vertically in this case, was in.