HTML & CSS IT SPECIALIST

Webpage Styling Using CSS

Construct and analyze styles that position content

<!--
THINGS TO KNOW: the term short hand version of a property is when a property will take multiple values at once and only takes up a single line.
For example: border: 1px solid black;
This declaration defines the border and uses three different values for the short version of the declaration.
1. 1px defines the thickness of the border.
2. solid defines the style of the border.
3. black defines the color of the border.

Longer hand version
border-style: solid;
border-color: black;
border-weight: 1px;

Longest hand version
border-top-style: solid;
border-top-weight: 1px;
border-top-color: black;

border-bottom-style: solid;
border-bottom-weight: 1px;
border-bottom-color: black;

border-left-style: solid;
border-left-weight: 1px;
border-left-color: black;

border-right-style: solid;
border-right-weight: 1px;
border-right-color: black;

-->

What is CSS?

CSS stands for Cascading Style Sheets.

What does CSS do?

CSS is used to style elements and make them look however you would like.

What is a CSS rule?

A CSS rule for Internal or External styling is composed of three parts.

  • Selector – selects the elements or tags to be affected by the CSS rule.
  • Declaration Block – anything placed withing the opening and closing curly brace.
  • Declarations – the rule that is used to style an element or a tag.
    • Declaration blocks have the following format: name: value;
//Note: the "p" is the location of the selector.
//{} brackets is the declaration block.
// color: blue; is the declaration.
color - is the name of the declaration
:(colon) is the separator between the name and the value.
blue is the value of the declaration.
;(semicolon) is the stop in the declaration where it ends.

P {
color: blue;
}

CSS Properties

CSS POSITION PROPERTY

position – tells an element how it should move based on a fix place or its current place.

Possible values include absolute and relative.

Absolute value tells the browser to move the element starting from the top left hand corner of the document body or relative to the nearest positioned ancestor.

Relative positioning – states that the element will starting moving from wherever it currently is.

Sticky positioning – an element is positioned based on the users scroll bar.

Static – an element moves according to the natural flow of the page.

P {
position: relative;
}

NOTE: the position declaration only tells an element how to move. However, it is still necessary to provide another declaration or multiple declarations on how to move the element.

top – how much to move closer or further from the top.

bottom – move closer or further from the bottom of the page

left – move closer or further away from the left side of the page.

right – move closer or further away from the right side of the page.

P {
position: realtive;
top: 100px;
bottom: 100px;
left: 100px;
right: 100px;
}

CSS Max-width Property

The max-width property is used to provide the maximum width that any element can be sized to. In other words, if an element has a max-width of 500 pixels, it means that the element can be any size up to and including 500 pixels, but not greater.

div {
max-width: 500px;
}

CSS Overflow Property

The CSS overflow property defines to an element what should happen with the element in the event that the element has more content than it can display. These are some of the options available to the overflow property:

  • scroll – the overflowed content is not visible but a scroll bar is provided to view the content within the element.
  • visible – This is the default behavior and the overflow content is not hidden. The content will spill out of the element.
  • hidden – The overflow content is not visible and it is hidden from the user with no way to view the actual hidden content.
  • auto – It decides when scrollbars are to be added or not.
div {
overflow: scroll;
}

CSS Height & Width properties

The height property defines the specific height or vertical measurement to an element. The width property defines the horizontal measurement of an element. The value for height and width can be defined in multiple units of measurement. These are some units of measurement available.

  • px – pixels.
  • pt – points
  • % percent
  • vh – viewport height
  • em – relative to the size of the elements font.
  • Centimeters (cm): Physical units, typically used for print.
  • Millimeters (mm): Another physical unit, smaller than a centimeter.
  • Inches (in): Yet another physical unit, commonly used in print.
  • Points (pt): Commonly used in print, with 1 point being equal to 1/72 of an inch.
  • Picas (pc): A picas is equal to 12 points.
div {
height: 300px;
width: 300px;
}

CSS margin Property and the Text-align Property

The margin property defines how much space an element should have between itself and a specific margin. Each element will have a top, bottom, left, and right margin. You can define each margin by using the following properties:

  • margin-top – defines the top margin with some value.
  • margin-bottom – defines the distance between the element and the bottom margin.
  • margin-left – defines the distance between the element and the left margin.
  • margin-right – defines the distance between the element and the right margin.

Note: Margins can be defined using multiple units of measurement. I typically define it using pixels. You can use one of these properties or all of them at once.

Also, the short hand version of margin can be provided one value to represent all margins.

//Short version
div {
margin: 10px; //All ten pixels will be provided to all margins.
}
//Not as short version
div {
margin: 10px 15px 5px 3px; //top, right, bottom, left
}
//Very long version of the property
div {
margin-top: 100px;
margin-bottom: 100px;
margin-left: 100px;
margin-right: 100px;
}

CSS display Property

The display property is used to define to an element how it should be displayed. Those options can be:

  • inline – display the elements next to each other only using the space needed by the element.
  • block – display the element as a greedy element and one that uses more space than it needs (the entire line) and has a line break.
  • inline-block – an element that is displayed as an inline element but width and height can be applied.
P {
display: inline;
}

Inline Elements Vs. Block Level Elements

Inline level elements are not greedy. Inline level elements only use up the space they need. Multiple inline level elements can fit in one line. However, block level elements are greedy and require the entire line whether they need it or not. A block level element also always starts on the next line.

<element> <element> <element> <element> inline level elements

<p>the </p>
block level element.

CSS Visibility Property

The visibility property is used to define when an element should be visible or hidden.

  • hidden – the element will be hidden.
  • visible – the element will be visible.
p {
visibility: hidden;
}

Box Model Defined

The box model defines that every element is a box and each element is capable of having content, padding, margin, and a border. Many define this model as a box that contains content, followed by padding, followed a border, followed by padding.

Even though those properties are not visible on the element, it is understood that you can make those properties visible.

p {
padding: 10px;
margin: 10px;
border: 1px solid black;
}

CSS Padding Property

The padding property provides space between the content and the border of the element. Padding can be defined in short hand and long hand version.

IT Specialists Multimedia Presentation Using HTML (Displaying Images)

HTML 5 Logo

Construct and Analyze Markup That Displays Images

<img> Image Tag

The <img> tag is used to add a image to a web page. However, technically speaking that image is not really embedded into a webpage, but rather it is linked to the page by the <img> tag.

This tag doesn’t have a closing tag and is a void tag.

<img> Required Attributes

The <img> tag by itself doesn’t actually do anything, well it kind of holds a space in the HTML page to show that an image will be there at some point. In order to have an actual image show up, you are required to provide two attributes to the <img> tag. Those attributes are as follows:

  • src – attribute tells the <img> tag where the image is located; almost like a pointer to where the image is. It can accept a relative URL or an absolute URL.
  • alt – the alt attribute provides an alternative title to the image in case the image breaks. This attribute is good for screen readers or if for some reason the browser is unable to display the actual image.

Example Code

<img src="dog.png" alt="An image of a dog">

Additional Attributes for the <img> tag

  • height – (pixels) – specifies the height of the image.
  • width – (width) – specifies the width of the image.
  • usemap – (id) – will specify an image as a client-side image map.
  • loading – () – used to specify if the image should be loaded at some other time or later in the page load.
  • ismap – () – specifies an image as a server-side image.
  • crossorigin – () – allows crossorigin access to images.

<picture></picture> Element

The picture element provides more flexibility by allowing the browser to display multiple images to best fit the device the image is being displayed on. The <picture></picture> element has the ability to have multiple sources tags to multiple images on the web. <source> tags are void tags and as such, they don’t have a closing tag.

<source> tag is used inside (sub element) the <picture></picture>element. The source attribute is used to provide instruction to the browser of when it is most appropriate to display the image and when it is located.

  • media attribute – defines when the image should be used by the browser.
  • srcset – is the location of the image.
<picture>
         <source media="(min-width: 600px)", srcset="image.png">
         <source media="(min-height: 300px)" srcset="image3.png">
         <img src="image.png">  // Just in case the browser doesn't support the   
                                //picture element.
</picture>
//Note: the <img> tag inside of the picture element is used in case a browser doesn't handle the picture element, it can default to the <img> tag.  This is what is considered backwards compatibility.