HTML, CSS
More on Git
- ‘Branching’ is a feature of Git that allows a project to move in multiple different directions simultaneously. There is one
masterbranch that is always usable, but any number of new branches can be created to develop new features. Once ready, these branches can then be merged back intomaster. - When working in a Git repository,
HEADrefers to the current branch being worked on. When a different branch is ‘checked out’, theHEADchanges to indicate the new working branch. - When merging a branch back into
master, there is the possibility for merge conflicts to arise. These can be resolved in the same way discussed in Lecture 0. - Some Git commands related to branching:
git branch: list all the branches currently in a repositorygit branch <name>: create a new branch callednamegit checkout <name>: switch current working branch tonamegit merge <name>: merge branchnameinto current working branch (normallymaster)
- Any version of a repository that is not stored locally on a device is called a ‘remote’. ‘Origin’ is used to refer to the remote from which the local repository was originally downloaded from.
- Some Git commands related to remotes:
git fetch: download all of the latest commits from a remote to a local devicegit merge origin/master: mergeorigin/master, which is the remote version of a repository normally downloaded withgit fetch, into the local, preexesitingmasterbranch- Note that
git pullis equivalent to runninggit fetchand thengit merge origin/master
- Note that
- A ‘fork’ of a repository is an entirely separate repository which is copy of the original repository. A forked repository can be managed and modified like any other, all without affecting the original copy.
- Open source projects are often developed using forks. There will be one central version of the software which contributors will fork and improve on, and when they want these changes to be merged into the central repository, they submit a ‘pull request’.
- A pull request can be made to merge a branch of a repository with another branch of the same repository or even a different repository. Pull requests are a good way to get feedback on changes from collaborators on the same project.
- Note that forks and pull requests are both GitHub specific features.
More on HTML
- More useful HTML tags:
<a href="path/to/hello.html">Click here!</a>: link tohello.html, some URL, or some other content marked byidby passing#idtohref<input type="radio"> Option 1: radio-button option for a form, where only 1 out of all the options may be selected ``` html
- There are lots of new useful tags with HTML5, but not all browsers, especially older browsers, will support these new features. Nonetheless, these new features can be used with increasing confidence that they will be rendered appropriately for a significant portion of users.
More on CSS
- CSS selectors are used to select different parts of a website to style in particular ways.
- Some common CSS selectors:
- Select
h1andh2h1, h2 { color: red; } - Select all
lithat are descendants ofol(not necessarily immediate descendantsol li { color: red; } - Select all
lithat are immediate children ofolol > li { color: red; } - Select all
inputfields with the attributetype=textinput[type=text] { background-color: red; } - Select all
buttons with the pseudoclasshoverbutton:hover { background-color: orange; }- A ‘pseudoclass’ is a special state of an HTML element. In this example, the state is whether or not the cursor is hovering over a button.
- Select all
beforepseudoelements of the elementaa::before { content: "\21d2 Click here: "; font-weight: bold; }- A ‘pseudoelement’ is a way to affect certain parts of an HTML element. In this example, the
beforeselector appliescontentwith its included styling before the contents of allaelements. \21d2is a hexadecimal value for a Unicode icon, which can represent symbols like emoji.
- A ‘pseudoelement’ is a way to affect certain parts of an HTML element. In this example, the
- Select all
selectionpseudoelements of the elementpp::selection { color: red; background-color: yellow; }
Responsive Design
- Responsive design is the idea that a website should look good regardless of the platform its viewed from.
- One way we can do this is by using a ‘media query’:
<style> @media print { .screen-only { display: none; } } </style> <body> <p class="screen-only">This will not appear when printed</p> </body>@mediais a media query, which means the following CSS will be applied only in certain situations, namely, when the webpage is being printed..screen-onlyis a class selector which identifies what content we want to be print only@media (min-width: 500px) { body { background-color: red; } } @media (max-width: 499px) { body { background-color: yellow; } }- When the width of the screen is at least 500px, the background color of
bodywill be red, while if it is less than 499px, the background color ofbodywill be yellow. - In order to interact with the screen size, the following must be included in
head:<meta name="viewport" content="width=device-width, initial-scale=1.0">viewportis the visible area on which the screen is being displayed.contentrefers to the entire webpage thewidthof which is being set todevice-width.
- Another tool is ‘flexbox’. Flexbox allows for the reorganization of content based on the size of the viewport.
.container { display: flex; flex-wrap: wrap; }- By setting
display: flexandflex-wrap: wrap, content will wrap vertically if necessary, so no content is lost when the width of the screen is shrunk.
- By setting
- A grid of content can be achieved in a similar fashion.
.grid { display: grid; grid-column-gap: 20px; grid-row-gap: 10px; grid-template-columns: 200px 200px auto; }- By setting
display: grid, all the different characteristics of a grid layout can be used to format content. In particular, when defininggrid-template-colummns, the final column can be set toauto, filling up however much screen space may be left. If multiple columns are set toauto, they will equally share the remaining space.
- By setting
Bootstrap
- Bootstrap is a CSS library written to help make clean, responsive, and nice-looking websites without having to remember the gritty details about flexboxes or grids everytime a layout needs to be set up.
- The only thing needed to use Bootstrap is by adding a single line which links Bootstrap’s CSS stylesheet:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">. - Bootstrap’s CSS will make everything look a little cleaner and more modern, but its real power comes with its layout system. Bootstrap uses a column-based model where every row in a website is divided into 12 individual columns, and different elements can be alloted a different number of columns to fill.
- Bootstrap’s columns and rows are referenced in HTML with
class="row"andclass="col-3"attributes, where the number aftercol-is the number of columns the element should use.- Elements can take up a different number of columns based on the size of the screen with attributes like
class="col-lg-3 col-sm-6. On a small screen, 6 columns will be used, but in a large screen, 3 columns will be used. If another row has to be added, Bootstrap will do so automatically. This is a much easier alternative to something like flexbox (Bootstrap does so behind the scenes).
- Elements can take up a different number of columns based on the size of the screen with attributes like
- Bootstrap has a whole host of other pretty components which can easily be applied by simply adding the appropriate
classattribute to an element. See Bootstrap’s documentation for an extensive list.
Sass
- Sass is an entirely new language built on top of CSS which gives it a little more power and flexibility when designing CSS stylesheets and allows for the generation of stylesheets in a programmatic way. Ultimately, Sass just makes writing CSS easier.
- In order to use Sass, it must first be installed. Once installed, we can execute
sass style.scss style.cssto compile our Sass filestyle.scssintosass.css, which can actually be linked to and interpreted by an HTML file.- If recompiling gets annoying,
sass --watch style.scss:style.cssto automatically recompilestyle.scssasstyle.csswheneverstyle.scssis modified. Additionally, many website deployment systems, like GitHub Pages, have built in support for Sass. For example, if an.scssfile is pushed to GitHub, GitHub Pages will compile it automatically.
- If recompiling gets annoying,
- One feature of Sass is variables, which are defined as so:
$color: red;. Anywhere$coloris passed as a value for a CSS property, e.g.color: $color,redwill be used. - Another feature is nesting, which is a more concise way to style elements which are related to other elements in a certain way.
div { font-size: 18px; p { color: blue; } ul { color: green; } }- In this example, all
ps insidedivs will be havecolor: blue, but alsofont-size: 18px, whileuls insidedivs will havecolor: greeninstead, but still alsofont-size: 18px.
- In this example, all
- One more useful feature is inheritance, which is similar to the object-oriented concept. Sass’s inheritance allows for slight tweaking of a general style for different components.
%message { font-family: sans-serif; font-size: 18px; font-weight: bold; } .specificMessage { @extend %message; background-color: green; }%messagedefines a general pattern that can be inherited in other style definitions using the@extend %messagesyntax. In addition, other style properties can be added.