Guide to Basic CSS

CSS stands for Cascading Style Sheet; Generally used for website layout and design and can be extended with Sass/Less that allow you to use variables and conditionals. Provides additional options/rules for how images and text is displayed. It is a style language and not a programming language. They use Class followed but Subclass.

The syntax follows [p {color:blue;}] and would function like adjectives.

Flexbox is a CSS3 layout mode that allows you to allign elements really quickly.

Basic Selectors

CSS Box Model

The box that wraps around every HTML element, box model refers to design and layout. You can right click the elements and inspect them.
Padding Properties: generates space around the element. Everything is the same except you cannot use auto or negative values.

How Margin Values are applied:

You can set the margin value to auto and it will adjust and react with the website.

Example:

        p{
            margin-top:5px;
            margin-bottom:10px;
            margin-right;15px;
            margin-left:20px;        
        }        
    

which is the same as the following:

        p{
            margin: 5px 15px 10px 20px;        
        }
    

Margin Properties: can be positive, zero, or negative

Methods for Adding CSS

Styles - attributes that add styles to an element such as color, font, size and more.

You can apply CSS externally, internally, and inline.

CSS Background-color Property

Used to change or specify the background color of an element. Valid color name or Hex value: #ff0000

                <body style="background-color:powderblue;">
                    <h1 style="background-color:DodgerBlue;">Hello World</h1>
                    <p style="background-color:Tomato;">Lorem ipsum...</p>
            

Text color is used for headings and paragraphs.

Example 1:

<h3 style="color:blue;">This is a heading</h3>

Which displays the following:

This is a heading

Example 2:

<p style="color:DodgerBlue;">Lorem ipsum...</p>

Which displays the following:

Lorem ipsum...

CSS Border Style property

Allows you to define the border for an element by specifying the style, width, and color.
Border-Style specifies what kind of border to display; dotted, dashes, solid
Border - set width of border and type of border and color.

Examples:

Which displays the following

Hello World

Hello World

Hello World

CSS Positioning & Styling Page Title

padding: 0px 10px;
margin: 0px;
text-shadow: 5px 4px 8px gray;
**the order is horizontal position, vertical position, then blurr then shadow color.

text-align and font-family follow the same formatting as setting text color.

text size is based on percentage and defines the text size for the HTML element.

Which displays the following

This is a paragraph.

Color Values - In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and HSLA values.

CSS Display property

Display property specifies how an element is displayed, can be used to control layout. Every HTML element has a default display value depending on the type of element. Default display for most elements are block or inline

Block level elements will always start on a new line and occupies the full width available. <p>, <div>, <h1-h6>

Inline elements do not start on a new line and only occupies width required. <a> & <img>

CSS Font Property

font-style is mainly used to make text italic

font-weight is to set the text to bold. Values are typically 100s or bold presets

font-size is to set the size of the text

font-family - when doing font-family, you would want more than just the default font in case the default font is not available and separate it by commas, such as: Arial, Helvetica, Times;
The main difference between serif and sans-serif is that serif letter text have hooks on their letters and sans-serif outputs flat or smooth letters

Other fonts include:

**Note** fonts.google.com; has you use the google API to access the fonts. Open Sans is commonly used; developers.google.com/fonts/docs/getting_started for instructions.
You add the link to your head section before the <body> but you would have to be online to add the font.

Syntax Recap

            Example: 
            a { background-color: green; }
        

Basic CSS Example

        body{
            background-color:#e0dfda;
            color:#a1a1a1;
            
            font-family: Geneva, Tahoma, sans-serif;
            font-size:16px;
            font-weight:normal;
        }
    

or

        body{
            font: normal 16px Geneva, Tahoma, sans-serif;
        }
    

line-height:1.6em; -adjusts the line spacing between the lines. 'em' represents a unit of measurement. Used for more responsive type websites unless you want to use 'px' for pixels.

Classes & ID

To call a class you use a '.' followed by the class name in the CSS file.

To call an ID tag, you would use a '#' followed by the ID tag.

Positioning in CSS

Example Layout:

            <html>
                <head>
                    <title>Blogs for Days</title>
                    <meta name="description" content="simple sample blog">
                    <meta name="keywords" content="simple sample blog company name">
                </head>
                <body>
                    <header id="main-header">
                        <h2>My Very Own Blog Website</h2>
                    </header>
                    
                    <a href="index.html">Go to Home Page</a>
                    
                    <section>
                        <article class="post">
                            <h3>First Post: Day 1</h3>
                            <small>Posted by John Doe on May 4, 2021</small>
                            <p>Each article that goes here will be a blog post. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
                            <small><a href="post.html">Read more...</a></small>
                        </article>
                        
                        <article class="post">
                            <h3>Second Post: Week 1</h3>
                            <small>Posted by John Doe on May 11, 2021</small>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
                            <small><a href="post.html">Read more...</a></small>
                        </article>
                        
                        <article class="post">
                            <h3>Third Post: Week 3</h3>
                            <small>Posted by John Doe on May 24, 2021</small>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
                            <small><a href="post.html">Read more...</a></small>
                        </article>
                    </section>
                    
                    <aside>
                        <h2>Categories</h2> 
                        <nav>
                            <ul>
                                <li><a href="#">Category 1</a></li>
                                <li><a href="#">Category 2</a></li>
                                <li><a href="#">Category 3</a></li>
                            </ul>
                        </nav>
                    </aside>
                    
                    <footer id="main-footer">
                        <p>Copyright © 2021</p>
                    </footer>
            </body>
            </html> 
        

This displays the following:

Blogs for Days

My Very Own Blog Website

Go to Home Page

First Post: Day 1

Posted by John Doe on May 4, 2021

Each article that goes here will be a blog post. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Read more...

Second Post: Week 1

Posted by John Doe on May 11, 2021

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Read more...

Third Post: Week 3

Posted by John Doe on May 24, 2021

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Read more...

Form Example

A common class used for forms in bootstrap would be 'form-group'

Below is an example of some basic form options

The form is generated using the following HTML5 code:

            <form action="process.css" method="POST">
                <div class="form-group">
                    <label>First Name:</label>
                    <input type="text" name="firstName" placeholder="Enter first name">
                </div>
                <div class="form-group">
                    <label>Last Name:</label>
                    <input type="text" name="lastName" placeholder="Enter last name">
                </div>
                <div class="form-group">
                    <label>Email:</label>
                    <input type="email" name="emailAddress">
                </div>
                <div class="form-group">
                    <label>Birthday:</label>
                    <input type="date" name="birthday>
                </div>
                <div class="form-group">
                    <label>Quantity</label>
                    <input type="number" name="quantity" value="1">
                </div>
                <div class="form-group">
                    <label>Topic:</label>
                    <select name ="emailTopic">
                        <option value ="newOrder">New Order</option>
                        <option value ="customerService">General Customer Service</option>
                        <option value ="productSupport">Order Support</option>
                        <option value ="suggestiions">Suggestions</option>
                        <option value ="other">Other</option>
                    </select>
                </div>
                <div>
                    <label>Message:</label>
                    <textarea name="message"></textarea>
                </div>
                <input type="submit" name="submit" value="Submit">
            </form>
        

Floating Block Example:

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Position Box Example

Following HTML code:

        
        

paired with this CSS code:

        
        

displays the following:

Hello

Goodbye

Positioned as static by default if there is no position specified.

Absolute allows you to move the element around the webpage and not within the element box model as it's not positioned as relative. Uses the following line after being called.
position: absolute;

Relative position is in relation to how element that is positioned relative to its normal position. So this means top, left, right, bottom.
position: relative;

In order to use an image as an element background, you would edit the css element and add the background-image attribute with a url to the image source. The background repeats as a default unless you set it to otherwise. You can also position the image to the center position with use of the background-position.

Psuedo Classes

Pseudo classes are set in the CSS file following the element and class selector while seperated by a colon in the CSS file.

list has a class named "generic-list" and the following CSS format to apply colors or properties to the list.

        .generic-list li:nth-child(even){
            background: grey;
        }
    

Creating a Fixed Button

Home

Using the following code:
<a class="fix-position button" href="">Home</a>

with the following CSS: 
        .fix-position{
        position: fixed;
        top: 0%;
        }
    

will create a home button that stays fixed to the upper left of the screen.

CSS Reset

Styling meant to be used for 'boiler-plates' to remove page presets.

            html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp,small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
                margin: 0;
                padding: 0;
                border: 0;
                font-size: 100%;
                font: inherit;
                vertical-align: baseline;
                box-sizing: border-box
            }

            article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
                display: block;
            }
            
            body {
                line-height: 1;
            }
            
            ol, ul {
                list-style: none;
            }
            
            blockquote, q {
                quotes: none;
            }
            
            blockquote:before, blockquote:after, q:before, q:after {
                content: '';
                content: none;
            }

            table {
                border-collapse: collapse;
                border-spacing: 0;
            }

            html {
                box-sizing:border-box
            }

            * {
                box-sizing:inherit
            }
        

Styling example

            <html>
            <head>
                <title>Sample Site</title>
                <link rel="samplestyle" type="text/css" href="css/samplestyle.css">
            </head>
            <body>
                <header id="main-header">
                    <div class="container">
                    <h1>Sample Site</h1>
                    </div>
                </header>
                
                <nav id="navbar">
                    <div class="container">
                        <ul>
                            <li><a href="#">Home</a></li>
                            <li><a href="#">About</a></li>
                            <li><a href="#">Services</a></li>
                            <li><a href="#">Contact</a></li>
                        </ul>        
                    </div>
                </nav>
                
                <!--Showcase Area-->
                <section id="showcase">
                <div class="container">
                    <h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</h1>
                </div>
                </section>
                
                <!--Main Area-->
                <div class="container">
                <section id="main-header">
                    <h1>Welcome</h1>
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                </section> 
                <!--Side Bar-->
                <aside id="sidebar">
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                </aside>
                </div>
                
                <footer id="main-footer">
                        <p>Copyright ©2021: My Website</p>
                </footer>
            </body>
            </html>