Websites are made of HTML, CSS and JS files. A website can't function with CSS or JS files alone.
But a website can work be made with HTML file alone.
HTML = Hyper Text Markup Language
HyperText = Parts of text that link to other documents
Markup Language = HTML Tags. People used to mark parts of a text with certain rules to denote which needs to be italicized, bold, etc., similarly HTML is a markup language that uses HTML tags to do the same.
Anatomy of HTML Tag
Self closing tags
Some tags require both start and end tag. But some are self closing meaning they don't require a closing tag
For example: the <br> tag
HTML attributes
Attributes lets us specify some rules about the function or appearance of the tag.
For example, the <hr> is called a Horizontal rule tag that creates a horizontal line. with the attribute called size we can define the thickness of the horizontal line
<hr size="3"> will make the line 3 pixel thinkness
For Multiline comment, use the "-->" on a different line and type the text in between them
The HTML Boilerplate
Doctype
The <!DOCTYPE html> tells the browser which version of html the file was written in. The latest version is the html5 and the above line denotes html5
html tag
Every element in the html file will be inside the <html> </html> tag. Actually the contents go inside the body tag and the body tag is inside the html tag itself
html tag has an attribute called lang which denotes in which language the text content of the website is written in. For example, <html> lang="en" denotes that the language is in english
Its not important for those who can see and read the page. But it's important for the people who can't as they rely on some computer narrating tools, which requires to know in which language the content is in for the correct pronounciation
Head tag
Important information required for the website is placed inside <head> </head> tag, but its not visible to the user
<meta charset="UTF-8">
For example, it includes the <meta charset="UTF-8"> to denote which charset that the text in the file should use so that the browser can render them correctly. Some character sets may include emojis and some may not. So, it is good practice to always include and use the right charset for the website
<title>
The title tag denotes the title of the page. Its the text that gets displayed in the tabs of the browser.
There are other things that can go inside the head tag, its not discussed here
Body tag
This is where the content of the website goes
Structuring text in HTML
<P> tag
<i> tag vs. <em> tag
The i and em tags both are used to italicize the words. But the em tag not only italicizes but also tells the system narrator to emphasize the word while it being read
<b> tag vs <strong> tag
Similar to the i and the em tags, strong and b tags both are used the make the text inside them stand out by bolding them
But strong is a logical state and b is a physical state.
HTML lists
Unordered lists (<ul>)
Ordered lists (<ol>)
Both these list tags introduces the use of element tag called <li> for each item in the list
We can customize the list, for eg, using Roman numerals instead of numbers in the ordered lists by using attribute: <ol> type="i"
You can also make the list start at a particular number by using the attribute start="number"
HTML Image elements
<img> tag
the <img> tag requires an attribute called src which is called as source, which is the locaction of the image that needs to be displayed
The source can be an online link or a computer directory
In the case of a computer directory, if the .html file as well as the image are in the same directory, then only file name along with the extension (for eg. src="Wallpaper.png") is enough
But if they are in different directory, then the full path of the image is to be entered
Apart from the src attribute, there is another attribute called as alt which stands for alternative text which is used to display a text in case if a browser can't locate or render the image
the alt tag also helps in search optimization and increases ranking of the website by making it easier for google to fetch relevant information
Also provide an attribute called title="" to get a text displayed when cursor is hovered over the image
HTML Links and Anchor Tags
The <a> (Anchor) tag
<a> tag is used to include links in the website. It requires an attribute called href which contains the link
after the href attribute, type in the text that needs to be displayed for that link
For example: <a href="https://Google.com">Google's Home Page</a> will look like this: Google's Home Page
HTML Tables
<table> tag
attribute: border="1" - creates a border of 1 pixel thickness
<tr> - Table row - creates a table row
<td> - Table data - contains the cell data
<thead> - Table Head
<th> - Table head cell
<th> elements work even without being inside the <thead> tag as most browsers know where th elements need to be
Then the reason or use of these table head is in situations where we would want to stylize the table headers and data in a different way
Rowspan and Colspan - attirbutes that denote the width and height of the cell respectively in terms of cells
<tbody> - Table Body - contains all the data of the table
<tfoot> - Table Foot
Using HTML Tables for Layout
Using tables to arrange the photo on left and the details on right
Cell spacing
This is a deprecated feature which defines the spacing of data inside the cells in terms of pixels or percentage
HTML Forms
<form> tag
<label> tag
It's the name of the details that are asked in a typical form: Name, D.O.B. These are called labels
<input> tag
type attribute - what datatype must be entered in the input box. submit is also a type.
Text area has two required attributes called rows and columns which is nothing but the length and width of the text area
The text area can be modified from the browswer itself, the rows and cols data denote the initial size of that text area
The form tag has an attribute called action which says what to do when an action like clicking the submit button is performed
The email input type of the form tag automatically checks whether a valid email address was typed
there is an action called mailto which opens up the default mail client with the input that was typed in. This also requires the method="post
For example: action="mailto:kulasekaranslrk@gmail.com" method="post"
There is another form attribute called enctype, which stands for encoding type, which like the UTF-8 in our html document, specifies in what type the form data must be encoded. By specifying this, when using the form, the data will have only the plain text that was typed onto the form (it won't have the extra symbols that will be there when not specified)
Publishing website in GitHub
Create a public repository and add the html files
The website's html file must be named "index.html". This is mandatory otherwise the website will not work.
Make sure all the data sources are pointing the right directory, otherwise they won't show up in the website
Once the files are uploaded, go the repo setting --> Pages --> source --> choose the branch --> save
github will take some time and then refresh the page. There will be a link shown. This link can be shared with anyone and they can see the website without needing any of the files
CSS - Cascading Style Sheet
33. Introduction to CSS
CSS is used to style the website to make it look more appealing which can't be done with HTML alon. Also, CSS along can't do anything without a base HTML
Inline CSS
Changing Background color using css
use "background-colo: colorname;" inside the body tag of the html document to change the background color of the whole page
The customizations above mentioned only applies to the html file that is being worked on. To make it global, that is, to make it get applied to all its sister pages, it needs to be in a external css
External CSS
Creating an external stylesheet
Create a folder named css in the root folder of the html files
Create a file named styles.css
Cut and paste the data inside the <style> </style> into the styles.css file
Now on every html document's head section, add a link tag
This link tag has two attributes: rel meaning relation and href
set the rel="stylesheet" and href="css/styles.css"
This will modify the appearance of all the html files that has this link in their head section
Debugging in CSS
Always use Chrome's web developer tools to check for bugs in the website
Inline css overrides Internal css as well as external css
style precedence is like: Inline > Internal > External
The Anatomy of CSS Syntax
Selector{property:value;}
It is always best practice to have the properties in the styles.css file arranged in alphabetical order for each element. Helps a lot while debugging
The above site lets users use different kinds of emoji from various operating systems
When an img customization is present in a styles.css file, that customization will get applied to all the images that is on the website
To apply different customization to different types of images, For eg: Having the Background color of images that has a dog as red and having the background color of images that has a cat as green, we need to include a class attribute inside the img tag and then target customizations based on classes and not on tags
Lets have two classes as dogs and cats
In the styles.css file, add .dogs{background-color:red;} and .cats{background-color:green;}
The dot(.) in front represent that the following is a class and not a tag
Note: commenting in CSS is done within /* */. Have them on different line for multiline commenting.
Classes vs. Ids
Id selectors
Use the # symbol to target Ids
Note:The customization based on Classes and Ids will override that of the general tag customization. Meaning, Even if for example, an img tag customization is already present, a specific class customization of the img will override the general one
The difference between classes and ids is that, classes can be instanced at more than one places. But Ids cane be instanced only once
For example, if there is a h1 tag with the id="heading", then this id="heading" can't be instanced anywhere else on the code. But the classes="dogs" can be instanced any number of time
They both are used to specifically target the customization across the elements. But classes target a specifig group of elements whereas Ids target a single unique element
A tag can have more than one class name. for example, If all the dog class images needs to be circular, it can be done as: class="dogs circular" And then can be targeted as: .circular{border-radius:100%;}
But a tag can't have two Ids. If more than one id was included, it won't be considered as a valid id and its customizations will not get applied. This is another difference between classes and ids
One of the uses of class is for easier and simple navigation inside the same page. In many website, there will be a bar at the top with different sections like: Home, contacts, downloads, etc., These sections can have their separate html pages or its content can be on the same page as them.
For example, when the contents are on the same page, for easier navigation, in the href of these sections, the id of these contents can be provided and so when clicked upon, the page will automatically scroll to the position of these section. This is another advantage of using ID
psuedo classes
The psuedo classes are used to perfom a change in the element when the user, say for example, hovers the mounse pointer over an element (but not clicking it)
Note: The psudo classes begin with a colon(:) in front. The syntax is tag name:pseudo class
For example, There is a pseudo class called :hover. It can be used to make changes to an element only when it is being hovered. To do this:
Go to styles.css
img:hover{background-color:blue;}
This will change the background of the image to blue only when the mouse cursor is brought on top of any image.
Note: The hover customization doesn't work if an inline CSS syling is present as it has the most precedence
Check this: site to learn more about different pseudo classes available
Intermediate CSS
Favicons
A Favicon is a small icon that appears next to the title of the website in the tab bar of the browser
In order to change the favicon of the site, create a link in the headsection of the site.
Instead of the rel="stylesheet" change it to rel="icon" and in the href give the location of the icon file
HTML Divs
The Div element
Its called the Content division element, which divides the page into several divisions and let's customizing the layout of each of them separately
Div is an HTML element and it doesn't do much of anything without CSS
Div by default has a height of 0px Unless anyother height is specified or has contents inside it
Box Model of Website styling
The box model of css: margin, border, padding, content
When a text is displayed in a website, that text has a bounding box, which has a width and height, let's assume 100px each
Padding the the space between the content of the text and its border
The space between borders of two adjacent elements is called as the margin
CSS Display Property
The display property has 4 values: Block, Inline, Inline-block, None
Block elements
Block elements are those which take up the whole width of the viewport unlike imgaes.
So when two paragraphs are inserted, they naturally occur as in new lines, since paragraphs, headings, etc., are block elements
Say, for example, if the "pro" part in a sentence called "a programmer" needs to be underlined, it wont work if it was done as: <p> a</p> <p class="pro"> pro</p> <p>grammer</p> and in the css as: .pro{text-decoration:underline;}
Span Tag - Inline Block elements
To achieve that, a tag called span needs to be used
It is achieved as follows: <p> a <span class="pro">pro</span>grammer</p> and then the Css modification of the class pro
Span tag will be very useful in formatting one part of the text. Just like the div tag, span tag don't do very much unless they are used in conjunction with css
Some common inline elements:
spans
images
Anchors
Spans seem like they have the advantage since they can be stacked next to each other unlike the block elements, so one may think that why block elements are needed anyway
The reason is that, unlike block elements, Inline block element's width can't be adjusted
On the other hand, even if the width of the block element's are adjustable, it still doesn't let other elements to sit next to it
chaning the display value of a block element to inline doesn't do any good because the width can't be changed once it becomes inline
Inline-block elements
This is where Inline - block elements come in which give in the best of both worlds
They can be stacked next to each other and still their widths can be modified
None elements
This display type is like it deletes the element with the display property as none
Imagine a situation in which a quiz is being attended on a site. To hide/show the answer at the click of a button can be made by changing the display property to none and back
There is another property called visibility which when set to hidden will simply hide the element, but the element is still on the website. But when display is set to none, the element stops existing in the site and its place can be occupied by another element
CSS Static and Relative positioning
Position property
Static
The default positioning of all elements
Relative
This positions the element relative to how it would have been positioned had it been static. Say an img would have appeared at 0 margin on the left. if its attribute was changed to position: relative; left: 30px;. Then the image would appear with a gap of 30px on the left
Just by changing the position of an element to relative, no changes will be made unless it is accompanied with one of the four coordinates that mention the change
The coordinates order is: Top, Bottom, Left, Right
NOTE:When an element gets pushed due to relative positioning, it doesn't affect the position of any other element when it gets shifted.
NOTE:Even after the element's change in position, its old posiition is still occupied by the same element. Its like the element hid itself in its original position and moved its copy to the new position, that is relative to the old one
Absolute
Fixed
Absolute Positioning
Absolute Positioning
In abosulte positioning an element is positioned with respect to its parent
For example, if an image was contained within a div, and the img's position was absolute and had right: 30px; then the img will be shifted to position such that it has 30px right margin from the right end of the div's box
Unlike relative positioning, which leaves a ghost of the element behind so it won't affect the other element's positions, absolute positioning does affect the position of other elements when an element gets moved
Fixed Positioning
When an element's position is fixed, it will be still visible even when scrolling throught the page. Like the top bars or the side bars that has the items like contacts, profile being visible even when the page is scrolled down
The dark art of centering elements
Text align property
In the external css, inside the body tag selector, put text-align:center;
This will make all the Inline-block elements like images and the full width block elements like the texts to be aligned at the center of the webpage
To center the elements that are not Inline or not of full width, there is another method which uses margin: 0 auto 0 auto which means margin top is 0, margin right is auto, margin bottom is 0 and margin left is auto
It can also be set by margin: 0 auto, which means margin top and bottom are zero and margin left and right are auto
Font styling in CSS
Common CSS Font families
Cursive
Fantasy
inherit
monospace
This is used mostly for coding as in this font all the letters of a word will be of equal width.
sans-serif
Letter don't have tiny feet linke structures
The default sans-serif font for most browswers is the arial font
serif
For most browsers, the default serif is the Times font
Letters have tiny feet like structures
It's always recommended to use websafe fonts because, when a special font is used for a website, if the user's system or the browser doesn't have that font installed, then it can't render that font and will render the default one, which will make the website look different for them instead of how it should.
CssFontStack.com Visit this site to know which fonts are most commonly used across different operating systems
On this site, when a font is copied, a font stack actually gets copied. For eg. font-family: "helvetica neue",helvetica,arial,sans-serif
The above will work like, if the system has the helvetica neue then it will get displayed, or else the one next to it and so on.
Font embedding
But there is a way to use the font that seems good and still make it get displayed whether or not the user's system's able to render it.
Have a look at: Flaticon , to use cool icons for the site
We can also use GIFs for the site from : Giphy.com
CSS Sizing
NOTE: When a font size of a text is hardcoded in the html, even if the user change the font settings in the browser, say from medium to large, that harcoded element's font alone will remain same and the rest of the texts in the page will change size.
That's because, using px and mentioning font size will the lock the font's size
Dynamic Font Sizing
Use %
NOTE: 100% in font-size means 16px
So, if 90px is needed, then (90/16)*100%, that is 562.5%is needed
Use em
em, is the phonetic pronounciation of the letter 'M'. It is no longer used in current days. In em NOTE: 1em = 16px
90px=5.625em
NOTE: With zooming, it doesn't matter if the text is dynamically or statically sized cause zooming will scale up the whole site
NOTE: say for example, the body tag has a font-size customized as 2em and then the h1 tag has the font size customized as 5em, then in the end the h1 tag will appear as 7em as it inherits the base font-size from its parent, which is the body. And its the same with using percentages. But when the body tag says the font should be 20px and the h1 tag says it needs to 90px, then it will be 90px only
To avoid, such situation, there is a feature in the CSS3, the one that is being used, is called rem - Root em
The rem is used to ignore all the parent settings.
CSS Float and Clear
The Line height - This property is used to change the height between the lines in a paragraph. It doesn't have any units
Float
There is a div containing a pragraph and an image. The image is on top of the text.
By changing the float property of an img tag to, say left, the text which was at the bottom of the image, will now wrap around the image, meaning the image will float on the left, there will be text to the right of it and also to the bottom of it, if the paragraph's height is more than that of the image. Kind of what we see in school books
Clear
This is opposite to what float does. Suppose if only heading is to be wrapped around an image and the paragraph should be at the bottom of the image, by changing the clear property of the text to clear:left will bring it down to the image
BOOTSTRAP FRONTEND FRAMEWORK
Introduction to Bootstrap
Bootstrap is a Front-end library
Javascript, CSS, HTML are some of the front end stack
.NET, Ruby, PHP, NodeJS, Java, SQL are some of the backend stack
While the front end give the appearance, the backend provides the functionality to the webpage
Bootstrap was deveoped by twitter and is an open source tool
One main advantage of incorporating Bootstrap is that it makes the website responsive, meaning, the website will alter its appearance automatically depending on the device its being viewed upon from so that the contents will appear as it should and not as broken
It makes the website to have adaptable layout
Remember at the start of the tutorial codepen.io was used as online editor? Now instead of that, Codeply will be used, as it supports front-end frameworks like bootstrap unlike codepen
To get a styled button with a hover state, many lines of CSS code is required. But it can be achieved in just two words using bootstrap
In the HTML file, create a button using the button tag and give its class name as follows: btn-primary
This btn-primary is a pre-defined class in bootstrap for a blue colored button with a hover state
In bootstrap, primary=blue, dark=black. So, for a black colored button, give the class name as btn-dark
Another example is btn-outline-dark, which is button with white fill - black text - black outline that gets filled with black when hovered over
The size can also be alterd by having class name as btn-lg
Head over to Bootstrap website and download the bootstrap files as zip (not the software), and inside the zip there will be a folder named css and inside it a file named bootstrap.css. This file containes lot of predefined classes inside it that are ready to be used on any website
Do visite the examples section as well as the docs section in the bootstrap website in order to understand well while using bootstrap
Bootstrap installation
To install or incoporate Bootstrap into the website, in the head section of the html include a link with the relation as stylesheet. It is important to put this cdn link above the custom created styles.css stylesheet link for the previous customizations to still work
For the href head to the bootstrap site and copy the cdn link. cdn stands for Content Delivery Network
It was learnt in the one of the previous lessons that the Internet is not working via satellites but via underground fibre optic Inter-continental cables laid down all over the world
The point where these cables touch the land will be probaly a data center and there will be other interior data centers as well on the land
The cdn of the bootstrap starts with maxcdn, which means bootstrap is using MaxCDN as their website host, which has a lot of data points set across the world and that means a website made with bootstrap has a lower latency and is easier to load from anywhere in the world
And since a large number of websites already uses bootstrap framework, its very likely that the user must've loaded a bootstrap oriented website in their device at some point in time and if they haven't cleared their cache yet, then the bootstrap.css file will be probably stored in their device and will get applied easily once they load the site
Web Design 101 - Wireframign
Wireframing
Wireframes are low fidelity representation of the website design. It is the first step that should be done when designing a website from scratch
It is meant to be done with pencil and paper and roughly sketch out the layout of where things should be
SneakPeekIt is a cool site that lets users download wireframe template sheet that can be printed out and drawn upon
Another way is to use the industry standard tool called Balsamiq . It is not a free tool.
Mockup
This is kind of opposite of wireframing
Its like taking a screenshot of the website from the future
Visit: awwwards for examples of cool website designs
Then create an unordered list inside the nav and give the list a class name of navbar-nav
Then create an item by using the li and give it a class name of nav-item
Finally create an anchor element inside the item and give it a class name of nav-link
As usual give the href of the anchor tag the appropriate link
An appropriate navbar has been created
But this navbar class will make the navbar items get stacked on top of each other as more elements are added into it. But that's not how a normal navbar looks like
to make the items get arranged next to each other, give an additional class name of navbar-expand-lg next to the already existing navbar class in the nav element
When using lg (large), the navbar will be horizontal on laptop like large width devices and will appear vertical when viewed in smarphone like low width devices
Instead of lg, which means large width devices like laptop, if md (medium) was used, then for both laptop and say tablets, the navbar will be horizontal and for smarphones it will be vertical
To make the navbar appear more clearly, a background class can be added along with the two already added classes. Add bg-light for a very subtle light background navbar
By default, the navbar items will look blue in color, and this can be changed by adding one more class called navbar-light to make them appear with black text color
classes - colors
primary - blue
secondary - gray
success - green
danger - red
warning - yellow
info - light blue
light - white
dark - black
link - text will be blue with underline
.navbar-brand
An element with the class as navbar-brand will appear on the top left corner of the page
ms-auto
From all the above things, the navbar will look with the brand and the three links, all arranged one after the other. But this looks a bit clumsy. To push the links onto the right and keep the brand alone on the left, add a class to the ul tag of the navbar
Add ms-auto. This will create a margin from the start of the unordered list and auto means, it will push the contents to the right as much as possible. m - margin
toggler
Now, the three links are on the righ the navbar with the brand on the left of the navbar. But when the screen size gets so small that its not possible to see all the four of them in a single line, the navbar will get bigger in height and make the links appear vertical
But it will be better if all the three links are visible inside a drop-down list. Well that's what a toggler is for
The toggler is a simple button with three horizontal lines. when clicked on it will show the contents inside it as a drop-down list
Then create a div around the contents that are needed to be collapsed upon and give the div a class name that is given in the data-bs-target inside the toggler, in this case it is toplinks
the fixed-top class can be used inside the navbar to make it fixed to the top so that it won't disappear while scrolling
Setting up our new project
When there is content on the site the navbar will not dropdown. To make it drop down, some java script is actually needed to be embedded into the HTML file.
a script tag with a cdn link of java script from the bootstrap website is needed to be added to the head section of the html file
Bootstrap grid system
Class="row" and Class="column"
Bootstrap divides the columns into 12 parts. They can be used with class names as col-1 till col-12
Col-6 takes up 50.0% of the width
Col-4 takes up 33.3% of the width
Col-3 takes up 25.0% of the width
Col-2 takes up 20.0% of the width
But still, when changing the width of the screen, the columns stay the same and are not responsive
To make it responsive, mention the size in the class when creating the columns. For example, instead of col-6, mention it as col-md-6. This will keep two columns of size 6 next to each other when the screen is large and medium (laptop and tablet), and when screen is (small) phone sized, it will stack on top of one another
Bootstrap containers
class="Container"
Create a div element with some text content inside it
Give the div a class name of container
Now, since the div has a class of container, it makes the div responsive when the the window is resized or when the content is viewed from different width devices
Class="conatiner-fluid"
fluid container's function is similar to that of the regular container, but fluid containers can take up 100% of the width, whereas the regular ones do not.
Media queries are an important tool that lets users to control the properties of the element based on the width of the viewport
Syntax: @media <type> <feature>
For eg. Things will be shown differently when viewing the same page on a desktop vs mobile. The positioning and sizing will get affected and things can get awkward so easily
Creating mobile-friendly websites are a must. Even, google search engine ranks the site based on whether it is mobile friendly or not
Many sites create a separate page for when users are using the site through small screen devices. For eg. Facebook has a separate page set for mobile. The facebook's URL when viewed from a mobile will have a m.facebook instead of just facebook. The m stands for mobile obviously
But instead of creating separate webpages for separate devices, CSS Media queries can be used to achieve the same goal
For eg. with @media print{h1{color:"red" }} we can make the h1 texts have a color of red only when it is printed and they will appear with default color when viewed upon
To change the property depending on screen-size,
<@media screen (max-width:700px){font-size:15px}>
What the above code does is, it sets the size of the fonts to 15px, when the viewport's width is less than or equal to 700px
Code Refactoring - Be a better programmer
As a better programmer, you should be DRY - Don't Repeat Yourself, instead of being WET - We Enjoy Typing
Code Refactoring:
Readability - Easier to read for a third person
Modularity - Easier to locate error
Efficiency - More efficient to load and run and all devices
Length - don't repeat
There is a funny section in stack exchange called Code golf where people try to solve a problem using the most min number of lines possible
Combining CSS Selectors
Focus on the code below:
<div class="container title">
<h1> Hello there </h1>
</div>
<div class="container">
<h1 class="title"> Hi it's me </h1>
</div>
<div class="container">
<h1> I'm Here !!! </h1>
<p> This is fun </p>
</div>
In the above code, there are 3 divs. By combining different selectors of the div, the elements inside the div can be customized speficifically
In the css, if .container.title was used, then the customization will get applied to an element that has both the classes container and title
In the css, if .container .title was used then the customization will get applied to an element that has the class title and has a parent element with the class container
In the css, if .container h1 was used, then the customization will get applied to all h1 elements that has a parent with class container
CSS selector priorities
Inline styling has priority over all other
ids have priority over classes
classes have priority over elements
Prioritization is based on the specificity
Iniside a selector in CSS, if the same property is mentioned twice, then the last one will get applied
Creating a Website that people love
Web design principles
Color Theory
Typography
UI Design
UX Design
Visit: Daily UI site This site provides daily UI challenges for 100days. Its free to sign up
Visit: Collect UI site This site collects inspirations from the above daily UI site
Using Canva's publishing features, the created UI can be easily published as a webpage that is scrollable
Color theory
What do they represent?
RED - energy, love
YELLOW - joy, intellect, attention
GREEN - freshness, safety, growth
BLUE - stability, trust, serenity
PURPLE - royalty, wealth, femininity
Combining colors
Analogous colors
Combining colors that are next to each other on a color wheel
They look harmonious
But they don't stand out
Complimentary colors
For making colors to stand out, choose two colors that are opposite to each other on the color wheel
Triatic color
Using an equilateral triangle inside the color wheel
Head over to Adobe color to mix and get various color palettes
Typography
There are two large font families: Serif, and Sans-serif
Serif
Serif font family is old and potrays authority
Its further subdivided into: OldStyle, Transitional, Modern and Slab-serif
The difference between the thickest and thinnest part of a font says how aged it is
Sans-serif
Sans-Serif family potrays straight-forwardness and friendliness
UX design
UX is User Experience
Simplicity
Consistency
F-layout - the way user's eye skims through a site has been analysed to be the shape of the letter F
Multi-platform design
Don't bait people - Dark UX patterns
UI design
Sizing
Optimal line width
Choosing the right color
Alignment
think about Audience
JAVASCRIPT
Introduction to JavaScript
In the beginning there was a browser called mosaic which was worked upon by mark andreessen - one of the principle inventors of Netscape navigator
After completing university, mark worked on netscape and netscape was big success holding over 80% of the browser market
Then there was huge browser war between netscape and internet explorer. And netscape lost
But lot of netscape's technology was transported to firefox
around the year 1995, HTML website were all just simple layouts without any function
Whenever a website needed functionality, it had to send the input back to the server and the server responses back with the ouput after the calculations
The team at netscape wanted something more dynamic. In order to achieve this, the server has to be taken away and the logic needs to be able to run on the broswer itself
They needed a scripting language and te language needed to be simple and easy to understand
So, they contacted Brendan eich and he was able to create that required language in under 10days. That language is none other than the javascript
Nowadays, Javascript is used in mostly all websites. without javascript the webstie loses its function. In chrome, the power of javascript can be visualized by turning it off in the settings and trying to load youtube or any other site. Youtube won't load
An interesting side effect of Java script is that, without javascript Ads can't load
At first Javascript was actually named as Live script. The people at microsoft tried to reverse engineer the program and ended up with something called Jscript
Then there were many versions of Java script and it started confusions
So the Europeans did what they do best and standardized the script and named it as ECMA script. ECMA stands for European Computer Manufacturers Association
Java and Javascript has as much similarities as a Car and a Carpet
The main difference between them is that Java is a compiled language and Javascript is an interpreted programming language
Javascript alerts
Open chrome -> Dev tools -> console tab
Add the following code and press enter: alert("hello");
A pop will appear with the message inside the double quotes
In the above code, alert is the function and hello inside the double quotes is the message/argument and ; represents the end of the command
The one downside in using the chrome console is when enter is pressed the commands will get executed. So if hello and world needs to be displayed as two separate alerts press enter while holding down shift to type the next alert in the next line
But the above method is cumbersome. there is a better way of doing it.
Go to chrome -> dev tools -> sources tab -> click on >> -> snippets and create a file named index.js
press ctrl+enter to execute or click on the play button
There is a keyword called typeof() which outputs the datatype of the argument in the stdout
Variable
Inside the snippet tab create a new snippet
Add the following : prompt("What is your name?");
When the above command is executed, a popup window will display with the message as well a text box to type something
If something was typed and entered, it would not have been saved anywhere. It would have been lost
To save the informaton, a keyword called var is used
Add: var MyName="john"; in the index.js and execute it. After execution. type "MyName"; and press enter. It will output john
the var keyword is needed to use only once. It is used to create a variable. Once the variable is created, the keyword need no be used again to change its content
Naming conventions
Give meaningful variable names
keywords must not be used as variable name
Underscore is the only special char allowed in variable name
Can't begin with numbers but can contain numbers
variable name must be a single word
Keep variable names camelcased
String length
var name="john";
name.length;
The above code when executed will output the result 4
String slicing
var name="john parker"
name.slice(0,2) will ouput jo
name.slice(3,7) will ouput n pa
Changing case
name.toUpperCase();changes every lowercase letter in the variable name to uppercase
name.toLowerCase();changes every uppercase letter in the variable name to lowercase
Functions
All syntax for functions are same as to that of C programming
Instead of alert, console.log can be used for dev purposes
Adding element to array: arr1.push(6). Push() will add the items at the last
Removing element: arr1.pop(). pop() will remove the last item
DOM - Document Object Model
Adding JS to website
Inline
body onload="alert('hello');". The onload method is used to do something when the website laods up
Internal
<script>alert('Hello');</script>. Using the script tab, snips of javascipt can be added anywhere in the document
External
<script src=""></script>. Add the location of the .js file inside the src attribute
The position of adding the external css is important. If it was placed before the css, then the css won't get applied until the js code gets finished.
DOM
The DOM model converts the html code into a tree structure so that it can be used to make the website interactive for the user
HTML tree generator extensions are available for chrome that can be downloaded to visualize what DOM does to a website. Download
Consider a html document with head section and body section. The head will be the first child of the document and body will be the last child of the document
To access the first child of the document, use: document.firstElementChild()
To access the last child of the document, use: document.lastElementChild()
Consider, that the body section has a h1 element with "Hello" as its content
This "Hello" can be changed by using the following js code: document.lastElementChild().firstElementChild().innerHTML = "GoodBye"
Not only content, styles can also be manipulated using js code. For eg. at first the content was by default black in color. To change its color to red, use: document.lastElementChild().firstElementChild().style.color = "red"
Inside the DOM, objects can have properties and methods
Properties are charateristics of an object
Methods are things that an object can do
Selecting elements with JS
use document.getElementsByTagName(""); will return all the elements with the matching tag name inside an array
Consider there are three li items in the body section of the document. Now if the third item in the list has to be of color green, it can be done by the following: document.getElementsByTagName("li")[2].style.color = "green"
Elements can also be selected by their class names, use: document.getElementsByClassName("");
And similary, to get element by its ID, use: document.getElementById(""). NOTE: in this code, its mentioned as element and not element(s). Since IDs are unique
While the rest of the two methods return an array, the ID method returns only one item
There is another thing called querySelector and it works like this: document.querySelector("")Inside the quotations, either class or Id or element can be mentioned. querySelector also returns a single item. Even if there was more than one item that satisfies the querySelector string, only the first occurence of such matching item will be returned
To return all the items that match the querySelector, use: docuemnt.querySelectorAll("") and this would return a list of all such items
Chaning styles using JS instead of CSS
All methods should be in camelcased in JS. For example, if the font size was set as 10px for a h1 element using CSS, the same can be set using JS like this: document.querySelector("h1").style.fontSize="10px". Note that the values are always insde the double quotation marks.
JS vs CSS
A website is built with HTML which gives it its strucutre
CSS gives the website its beautification
JS gives the website its behaviour or funcitonality
In the last topic, querySelectors were used to change the appearance of the element in the website directly, which is bad practice. Although it is possible via JS, the apperane must be taken care only by CSS.
But there is a method called classList which returns the list of classes that an element has
Consider there is a button with a class="btn". Using JS a class can be appended to this button. document.querySelector("btn").classList.add("invisible")
The above code will the add the class "invisible" to the button along with the class "btn" which is already there. Now, a css selector with the name of "invisible" can be created inside the css file and manipulate the property of display:hidden;
Using the above technique, the JS can be indirectly used to alter the behaviour(apperance) of the webpage, while CSS is still doing the work in the background, and it will be easy when debugging
Similarly, the class can be removed by using .remove("invisble")
There is anothe method called .toggle("invisible") which applies the class if its not already there and removes the class if its there
Text manipulation using JS
InnerHTML method
Consider the code: <h1><strong>Hello</strong><h1>
In the above HTML, if document.querySelector("h1").innerHTML(); was used, then it would return "<strong>Hello</strong>"
So innerHTML can be used to add code on the fly
textContent method
Whereas the textContent(); method would only return the "Hello"
textContent can be used to add / modify content on the fly
Manipulating attributes of HTML elements
using .attributes();, will return the array with all the attributes that the element has the html code
using .getAttribute("attributeName") will return the value that the attribute of the element has.
using .setAttrubute("attributeName","value"), will set the value of that attribute of that element
The above code waits for the first button element to be left clicked and when it happens, it calls the javascript function named func
Note that normally when calling a function, the syntax would be to have () at the end of the function name. But in the above code, only func is written instead of func()
If for instead, func() was written, then what would happen is that when the event listener is being added to the page, automatically the function will get called. But the function should get called only upon the click of the button.
There is another method called the usage of Anonymous function meaning the function doesn't need to have a name
Consider the above code. Now if the function didn't have the name func and still it was required to be called only at the click of the button, then it can be done as: document.querySelector("button").addEvenetListener("click",function () {alert("Hello");});
Even though the () is used, since its an anonymous funciton, it won't be called until the click occurs
Higer order funcitons : The functions which taken in other functions as arguments
When something is selected in a webpage and inspected, it will be equivalent to a $0 sign. So this, $0 sign can be used to manipulate the currently selected element on a site
Chrome dev tools has an in-built debugging tool that can be accessed by using javascript.
In the index.js under the snippets tab of the sources tab, type debugger; and press Shift + ENTER
After that, whatever function it is to be debugged, call that function, and the debugging menu will open showing step by step of what's happening when the function is being called and this can be used to figure out what's going wrong when the function is not working properly
Playing audio in Website
To play an audio using JS, use: var audio = new Audio("path to the file") and then use: audio.play()
Constructor function
cosider the code : var student1 = {name: "timmy", age:10, rollno:23}
the above is kind of like creating structures in C. And similar to that, the properties of the variable student can be accessed usign the dot operator
But it is time consuming to create the above variable for each student and when there are many students
For eg: function StudentData (name, age, rollno){ this.name = name; this.age = age; this.rolno = rollno;}
Note that, unline the other functions and variables which are named in camelcasing, constructor funcitons are named with all their starting letters capitalized, thereby making it easy to identify that a function is constructor or not
To use the above constructor: var student1 = new StudentData ("timmy",10,23);
Switch statement in JS
Same syntax as that of C programming
switch (expression){
case "" :
//something
break;
}
objects and methods
In the constructor function lesson, it was learnt how to create objects with properties. There can also be methods for those objects
function StudentData (name,age,rollno) {
this.name=name;
this.age=age;
this.rollno=rollno
this.attendTest=function () {
alert("attending Test");
}
}
checking Key Presses
Add the following:
eventListener('keydown' function() {
if(event.key==="a"){
alert(key pressed);
}
});
JQuery
What is jQuery
jQuery is a JS library that mainly helps in reducing the code length but maintaining the same funcitonality as that of pure JS
for eg. document.querySelector('h1') = $('h1')
Incorporating jQuery into the website
Just like how bootstrap was incorporated into the website, Jquery can be incorporated using the CDN
Copy the snipped and add it at the last of the body section
$ is short form of writing jQuery()
The position where the jQuery CDN is included in the HTML file is very important. It should always be above the JS files inclusion script
consider there was a h1 tag with textContent = "Hello". By default this would be black in color. To change its color using Jquery, add the following JS: $('h1').css('color','red');
If the jQuery CDN and the JS inclusion script were included in the head section of the HTML document, then there won't even be an error and still the style would not be applied to the h1 element
This is because, since the HTML document is being read from top to bottom by the system, the JS will try to apply the styling even before there exists any element. To fix this, readiness of the document can be checked by using the following: $document.ready(function(){$('h1').css('color','red');});
Minification
If the CDN link of Bootstrap or jQuery is pasted into the chrome, then there will be a mess of continuous code in the page.
But its just the minified version of the library. What Minification does is that it removes all the whitespaces, comments and unused code from the file to try and reduce the file size
Head over to : Minifier.org to minify JS or CSS code