Top Banner
webdev@rgu Layout with css
57

Layout with CSS

Jan 07, 2017

Download

Software

Mike Crabb
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Layout with CSS

webdev@rguLayout with css

Page 2: Layout with CSS

overviewThe Box Model Positioning Elements Making A horizontal Menu Making a 3 column web page

Page 3: Layout with CSS

page layout

Page 4: Layout with CSS

• LAYOUT OF MAJOR ELEMENTS OF A PAGE IS CONTROLLED USING CSS

• HEADER, NAVIGATION BARS, SIDEBARS, CONTENT AND FOOTERS

page layout

Page 5: Layout with CSS

• LAYOUT OF MAJOR ELEMENTS OF A PAGE IS CONTROLLED USING CSS

• HEADER, NAVIGATION BARS, SIDEBARS, CONTENT AND FOOTERS

page layout

Page 6: Layout with CSS

• LAYOUT OF MAJOR ELEMENTS OF A PAGE IS CONTROLLED USING CSS

• HEADER, NAVIGATION BARS, SIDEBARS, CONTENT AND FOOTERS

• <TABLE> WAS PREVIOUSLY USED FOR LAYOUT • PAINFUL FOR COMPLEX LAYOUT • TABLES ARE MEANT FOR CONTENT, NOT

LAYOUT

page layout

Page 7: Layout with CSS

• LAYOUT OF MAJOR ELEMENTS OF A PAGE IS CONTROLLED USING CSS

• HEADER, NAVIGATION BARS, SIDEBARS, CONTENT AND FOOTERS

• <TABLE> WAS PREVIOUSLY USED FOR LAYOUT • PAINFUL FOR COMPLEX LAYOUT • TABLES ARE MEANT FOR CONTENT, NOT

LAYOUT

page layout

Page 8: Layout with CSS

• LAYOUT OF MAJOR ELEMENTS OF A PAGE IS CONTROLLED USING CSS

• HEADER, NAVIGATION BARS, SIDEBARS, CONTENT AND FOOTERS

• <TABLE> WAS PREVIOUSLY USED FOR LAYOUT • PAINFUL FOR COMPLEX LAYOUT • TABLES ARE MEANT FOR CONTENT, NOT

LAYOUT

• THE PREFERRED SOLUTION IS TO DIVIDE A PAGE INTO A COLLECTION OF <DIV> OR <SECTION> ELEMENTS

• <DIV ID=“HEADER”> … </DIV> • <HEADER> … </HEADER>

page layout

Page 9: Layout with CSS

The box model

Page 10: Layout with CSS

• CSS USES WHAT IS CALLED A BOX MODEL FOR SURROUNDING CONTENT.

• MADE UP OF 3 PARTS • (CONTENT) THIS ISN’T REALLY A PART OF THE MODEL • PADDING • BORDER • MARGIN

the box model

contentpadding

bordermargin

Page 11: Layout with CSS

CONTENT PADDING BORDER MARGIN

the box model

THE CONTENT OF THE BOX, WHERE TEXT AND IMAGES

APPEAR

Page 12: Layout with CSS

CONTENT PADDING BORDER MARGIN

the box model

CLEARS AN AREA AROUND THE CONTENT. THE PADDING

IS TRANSPARENT

Page 13: Layout with CSS

CONTENT PADDING BORDER MARGIN

the box model

A BORDER THAT GOES AROUND THE PADDING AND

CONTENT

Page 14: Layout with CSS

CONTENT PADDING BORDER MARGIN

the box model

CLEARS AN AREA OUTSIDE THE BORDER. THE MARGIN IS

TRANSPARENT

Page 15: Layout with CSS

box model properties

width

height

Page 16: Layout with CSS

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Home Page</title> <link type="text/css" rel="stylesheet" href="assets/css/style.css"/> </head> <body>

<header> <h1>My First Website</h1>

<nav> <ul> <li><a href="index.html">Home Page</a></li> <li><a href="login.html">Login</a></li> <li><a href="signup.html">Signup</a></li> </ul> </nav> </header>

<main> <h2>Home Page</h2>

<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>

</main>

<footer> <p>webDev@RGU</p> </footer>

</body> </html>

Box model in practice

we are going to style this part

Page 17: Layout with CSS

header { }

Page 18: Layout with CSS

header{ /* Colourings */background-color: cornflowerblue;}

Page 19: Layout with CSS

header { /* Colourings */ background-color: cornflowerblue; /* Content */ height: 200px; width: 300px; }

Page 20: Layout with CSS

header { /* Colourings */ background-color: cornflowerblue; /* Content */ height: 200px; width: 300px; /* Padding */ padding-left: 30px; padding-top: 10px; }

Page 21: Layout with CSS

header { /* Colourings */ background-color: cornflowerblue; /* Content */ height: 200px; width: 300px; /* Padding */ padding-left: 30px; padding-top: 10px; /* Border */ border-color: darkorchid; border-style: solid; border-width: 5px;}

Page 22: Layout with CSS

header { /* Colourings */ background-color: cornflowerblue; /* Content */ height: 200px; width: 300px; /* Padding */ padding-left: 30px; padding-top: 10px; /* Border */ border-color: darkorchid; border-style: solid; border-width: 5px; /* Padding */ margin-top: 30px; margin-bottom: 10px;}

Page 23: Layout with CSS

header { /* Colourings */ background-color: cornflowerblue; /* Content */ height: 200px; width: 300px; /* Padding */ padding-left: 30px; padding-top: 10px; /* Border */ border-color: darkorchid; border-style: solid; border-width: 5px; /* Padding */ margin-top: 30px; margin-bottom: 10px; margin-left: auto; margin-right: auto;}

Page 24: Layout with CSS

box model properties

width

height

border-bottompadding-bottom

border-left

padding-left

border-right

padding-right

border-toppadding-top

Page 25: Layout with CSS

box model properties

width

height

border-bottompadding-bottom

border-left

padding-left

border-right

padding-right

border-toppadding-top

margin-bottom

margin-top

margin-rightmargin-left

Page 26: Layout with CSS

Positioning elements

Page 27: Layout with CSS

• 4 DIFFERENT WAYS THAT WE CAN POSITION AN ELEMENT • STATIC POSITIONING • RELATIVE POSITIONING • FIXED POSITIONING • ABSOLUTE POSITIONING

Positioning elements

margin

Page 28: Layout with CSS

2 paragraphs on the page

<p id=“hasMaxWidth”>Lorem….</p> <p id=“noMaxWidth”>Lorem….</p>

#noMaxWidth{ width: 1000px; background-color: burlywood;}#hasMaxWidth { max-width: 1000px; background-color: burlywood;}

Max Width

Page 29: Layout with CSS

2 paragraphs on the page

<p id=“standardText”>Lorem….</p> <p id=“positionedText”>Lorem….</p>

#standardText{ background-color: aqua; }#positionedText { background-color: yellowgreen;}

Positioning

Page 30: Layout with CSS

2 paragraphs on the page

<p id=“standardText”>Lorem….</p> <p id=“positionedText”>Lorem….</p>

#standardText{ background-color: aqua;}#positionedText { background-color: yellowgreen; position: static;}

static positioningPOSITIONED STATIC BY DEFAULT

NOT SHOWN IN ANY SPECIAL WAY

Page 31: Layout with CSS

2 paragraphs on the page

<p id=“standardText”>Lorem….</p> <p id=“positionedText”>Lorem….</p>

#standardText{ background-color: aqua;}#positionedText { background-color: yellowgreen; position: relative; left: 50px; }

relative positioningPOSITIONED RELATIVE TO ITS NORMAL POSITIONING

SETTING LEFT RIGHT TOP AND BOTTOM CHANGES ITS POSITION

Page 32: Layout with CSS

2 paragraphs on the page

<p id=“standardText”>Lorem….</p> <p id=“positionedText”>Lorem….</p>

#standardText{ background-color: aqua;}#positionedText { background-color: yellowgreen; position: fixed; top: 100px; left: 50px; }

fixed positioningFIXED POSITION IN THE WINDOW

CAN BE GOOD FOR HAVING A MENU AT THE TOP ALL THE TIME

Page 33: Layout with CSS

2 paragraphs on the page

<p id=“standardText”>Lorem….</p> <p id=“positionedText”>Lorem….</p>

#standardText{ background-color: aqua;}#positionedText { background-color: yellowgreen; position: absolute; top: 100px; left: 50px; }

absolute positioningFIXED IN THE CONTAINER THAT IT IS CURRENTLY IN

Page 34: Layout with CSS

absolute positioning

fixed Positioning

Page 35: Layout with CSS

absolute positioning

fixed Positioning

Page 36: Layout with CSS

2 paragraphs on the page

<p id=“hasMaxWidth”>Lorem….</p> <p id=“noMaxWidth”>Lorem….</p>

#noMaxWidth{ width: 1000px; background-color: burlywood;}#hasMaxWidth { max-width: 1000px; background-color: burlywood;}

Max Width

Page 37: Layout with CSS

horizontal menu

Page 38: Layout with CSS

• SOMETIMES YOU WILL WANT YOUR CONTENT TO FLOAT AROUND THE PAGE • GETTING TEXT TO APPEAR BESIDE AN IMAGE PROPERLY. • HORIZONTAL MENUS!!!

HERE IS WHERE FLOAT COMES INT

floating elements

margin

Page 39: Layout with CSS

2 paragraphs on the page 1 image contained div in-between them <div id=imageContainer></div>

#imageContainer { width: 100px; height: 100px; background-color: gold;}

Page 40: Layout with CSS

2 paragraphs on the page 1 image contained div in-between them <div id=imageContainer></div>

#imageContainer { width: 200px; height: 200px; background-color: gold; float: right;}

Page 41: Layout with CSS

What about the navigation bar!? <nav> <ul> <li><a href="index.html">Home Page</a></li> <li><a href="login.html">Login</a></li> <li><a href="signup.html">Signup</a></li> </ul></nav>

Page 42: Layout with CSS

What about the navigation bar!? ul { list-style-type: none; margin: 0; padding: 0; }

Page 43: Layout with CSS

What about the navigation bar!? ul { list-style-type: none; margin: 0; padding: 0;}li { float: left;}

Page 44: Layout with CSS

What about the navigation bar!? ul { list-style-type: none; margin: 0; padding: 0;}li { float: left;}li a { display: inline-block; text-align: center; padding: 0 10px 10px 10px; text-decoration: none;}

Page 45: Layout with CSS

3 column web page

Page 46: Layout with CSS

• THIS TAKES A LOT OF THE THINGS THAT WE HAVE ALREADY LOOKED AT AND PUTS THEM INTO PRACTICE

3 column webpage

margin

Page 47: Layout with CSS

<main> <h2>Home Page</h2> <section id="col1"> <p>Lorem .…</p> </section> <section id="col2"> <p>Lorem.…</p> </section> <section id="col3"> <p>Lorem…</p> </section> </main>

html

Page 48: Layout with CSS

#col1{ background-color: green; }#col2{ background-color: red;}#col3{ background-color: blue;}

css

Page 49: Layout with CSS

#col1{ background-color: green; width:33%}#col2{ background-color: red; width:33%}#col3{ background-color: blue; width:33%}

css - set the width

Page 50: Layout with CSS

#col1{ background-color: green; width:33%; float: left;}#col2{ background-color: red; width:33%;}#col3{ background-color: blue; width:33%;}

float col1 to the left

Page 51: Layout with CSS

#col1{ background-color: green; width:33%; float: left;}#col2{ background-color: red; width:33%;}#col3{ background-color: blue; width:33%; float: right;}

float col3 to the right

Page 52: Layout with CSS

#col1{ background-color: green; width:33%; float: left;}#col2{ background-color: red; width:33%; display: inline-block;}#col3{ background-color: blue; width:33%; float: right;}

display col2 as inline-block

Page 53: Layout with CSS

#col1{ background-color: green; width:31%; float: left; margin: 1%; }#col2{ background-color: red; width:31%; display: inline-block; margin: 1%; }#col3{ background-color: blue; width:31%; float: right; margin: 1%; }

adding a margin for pretty-ness

Page 54: Layout with CSS

#col1{ background-color: green; width:29%; float: left; margin: 1%; padding: 1%; }#col2{ background-color: red; width:30%; display: inline-block; margin: 1%; padding: 1%; }#col3{ background-color: blue; width:29%; float: right; margin: 1%; padding: 1%; }footer{ clear: both; } and some padding

Page 55: Layout with CSS

STOPthis is getting complicated…there

must be an easier way to do layouts!?

Page 56: Layout with CSS

next time we are going to look at using some tools that can help us a

lot in making layouts

(and also making our life a lot easier!)

Page 57: Layout with CSS

recappurpose of css syntax of css benefits of css APPLYING CSS

USING CSS WITH HTML ID AND CLASS SELECTORS PAGE LAYOUT BOX MODEL