Controlling Layout with Style Sheets

Slides:



Advertisements
Similar presentations
LIS650 lecture 4 Thomas Krichel today Advice CSS Properties –Box properties-- List properties –Table properties-- Classification properties.
Advertisements

Copenhagen, 6 December 2004 Modern CSS Principles Miruna Bădescu Finsiel Romania.
Use Tables for Layout Control Day 7. You will learn to: Understand Tables Create a Simple Table Modify Your Tables Appearance Create Page Layouts with.
Week 10 Creating Positioned Layouts
© 2011 Delmar, Cengage Learning Chapter 10 Positioning Objects with AP Divs.
CSS Layout Crash Course An Advance CSS Tutorial. Inline vs. Block Many HTML elements have a default display setting of Block. Block elements take up the.
Cascading Style Sheets
Part 5 Introduction to CSS. CSS Display - Block and Inline Elements A block element is an element that takes up the full width available, and has a line.
Web-based Application Development Lecture 9 February 7, 2006 Anita Raja.
MORE Cascading Style Sheets (The Positioning Model)
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
Using Cascading Style Sheets. Introduction to Styles and Properties  Cascading Style Sheets (CSS) are a standard set by the World Wide Web Consortium.
Advanced CSS - Page Layout. Advanced CSS  Compound Selectors:  Is a Dreamweaver term, not a CSS term.  Describes more advanced types of selectors such.
Tutorial 4: Using CSS for Page Layout. 2 Objectives Session 4.1 Explore CSS layout Compare types of floating layouts Examine code for CSS layouts View.
ITP 104.  While you can do things like this:  Better to use styles instead:
CSS Netcentric. What is CSS O CSS stands for Cascading Style Sheets O Styles define how to display HTML elements O Styles were added to HTML 4.0 to solve.
Designing a Web Page with Tables. A text table: contains only text, evenly spaced on the Web page in rows and columns uses only standard word processing.
CSCE 102 – Chapter 6 (Web Design and Layout) CSCE General Applications Programming Benito Mendoza Benito Mendoza 1 By Benito Mendoza.
THE BOX MODEL Putting layouts together with CSS. The Box Model  How would you describe a box?  Container?  Tags or elements are “containers”  puts.
Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.
CSS Positioning & Layout Creating layouts and controlling elements.
CONTROLLING Page layout
Positioning Objects with CSS and Tables
- WE’LL LOOK AT THE POSITION PROPERTY AND HOW CSS RESOLVES CONFLICTS BETWEEN STYLING INSTRUCTIONS The position property; CSS specificity hierarchy.
HTML and Dreamweaver November 11th. Agenda Box Model Displaying and positioning elements – Padding – Margin – Float – Display – Position HTML Demo.
Understanding CSS Cascading Style Sheets control the presentation of content in HTML pages Style Sheets separate formatting from the content –Styles defined.
CHAPTER 15 Floating and Positioning. FLOAT VS. POSITION  Floating an element moves it to the left or right, allowing the following text to wrap around.
Mimi Opkins.  One of the major benefits of using CSS is that you’re not forced to lay your sites out in tables.  The layout possibilities of CSS give.
Tutorial 4 Using CSS for Page Layout. Objectives Session 4.1 – Explore CSS layout – Compare types of floating layouts – Examine code for CSS layouts –
Laying out Elements with CSS
Cascading Style Sheets Layout
CSS Box Model.
CSS Box Model.
The Box Model in CSS Web Design – Sec 4-8
Cascading Style Sheets Boxes
Cascading Style Sheets™ (CSS)
CSS Layouts: Positioning and Navbars
The Box Model in CSS Web Design – Sec 4-8
CSS Layouts: Grouping Elements
Webpage layout using CSS
Floating & Positioning
Advanced CSS BIS1523 – Lecture 20.
Cascading Style Sheets for layout
Cascading Style Sheets (Layout)
Putting Things Where We Want Them
Programming the Web using XHTML and JavaScript
The Box Model in CSS Web Design – Sec 4-8
The Internet 10/25/11 XHTML Tables
Cascading Style Sheets
CSS Applications to XML 19-Sep-18.
Objectives Create a reset style sheet Explore page layout designs
Creating Layouts Using CSS
Styles and the Box Model
Second CSS Lecture Applications to XML
Positioning.
MORE Cascading Style Sheets (The Positioning Model)
CSS Box Model.
More CSS 22-Feb-19.
Training & Development
Floating and Positioning
Positioning.
CSS Box Model.
Positioning.
Laying out Elements with CSS
CSS Applications to XML 20-May-19.
CSc 337 Lecture 5: Grid layout.
CSS Applications to XML 3-Jul-19.
Cascading Style Sheets™ (CSS)
Positioning Boxes Using CSS
Presentation transcript:

Controlling Layout with Style Sheets An introduction Due to the fact that the students do not have anything to reference in terms of text, this ppt is provided as a study guide, thus the untraditional style of the ppt. Students are expected to complete all of the “Try it!” portions and are graded via their participation in class. The class does not move onto the next content and “Try it!” until the students are able to complete the task. If one particular student is having difficulty, then we may “pause,” to move the class forward, and while the students are engaged in the next “Try it!” I will work with the student until he/she is caught up and/or another student will assist in peer guidance.

Introduction With style sheets, you can precisely position text, images, and other elements on your pages. Style sheets let you place content at set coordinates within your layout. You can control spacing around your page elements, wrap text around images and tables, and overlap content

Box Model Where each element on a page exists in its own rectangular box. Control the dimensions of the box using height and width attributes. Control where the box is placed on the web page Control how the box aligns or overlaps with other boxes on the page.

HTML Block Tags Block-level tags place new lines before and after the content they enclose. What are these HTML tags? <p>, <h1>, <table> What about <div>? The div tag is a type of generic block-level tag commonly placed around other tags to organize content when using style sheets to determine layout.

Offsetting Content Can offset content on your web page from its normal position using top, left, right, and bottom style sheet properties. You can place content in a precise position within the browser window. You can overlap content in the browser window by placing an element at the same window coordinates as another element.

Positioning Content What property would be used for positioning? What is relative positioning? It places content on the page relative to the normal flow of the other content on the page. Example: top 25px; left: 25px What is absolute positioning? It places content at absolute points on the page. Example: top: 500px; left: 300px What is fixed positioning? It places content relative to the browser window and keeps it fixed as a user scrolls (it stays in the browser window). Example: position: fixed; left: 20px Every student did not like the “fixed position” feature, therefore we will not be working with it unless the need arises.

Padding and Margins What would padding do? What would margins do? Control the space that surrounds content inside each box on your page. What would margins do? Control the space outside the edge of the area you are controlling

Floating Content The float property takes a box out of the normal flow of your page and moves it to the right or left side of the enclosing box. Content that follows then wraps around the floated content. What can you align using the float property? Images (most common use) Paragraphs (depends on the browser) Tables Other content within a “box”

Applying CSS Layouts

To Start: Open your personal website in your browser. On a piece of paper, visually determine how you want your page to “look” and draw out how you want your information to lay out. When determining what you need, target items according to the blocks of information (p tags, h tags, etc). Consider the Block/Box Model for layout options. Be sure you have space for your heading Potentially a side bar The body and how that lays out (pictures vs. content) If you like, you can create a footer as well in your layout, but this is something that we will get into later.

Set Width and Height for an element (quick review) What properties would you use? Width: Height: What is the problem with height? How would you state an absolute value? Div.first {width: 500px; height: 300px;} Using the above rule structure, how would you assign this to your element? Use the class attribute Example: <div class=“first”> How would you state a relative value? Div.first {width: 80%; height: 20%} What is the problem with relative values?

Try it! Choose one element that you would like to place in a “container.” Choose one that has 2 consecutive paragraphs or other larger elements. Create an internal style that targets that element and assign an absolute value to it (remember your layout strategy and keep in mind the visual area of your workspace in your browser). Apply the style to the element Check in your browser: alter if needed Show me.  Now choose a different element and apply relative values. Check in your browser. Which do you prefer? You may change the one you do not prefer or leave them as is.

Positioning: Relative What does relative positioning mean? Position elements relative to other content on the page (directly near or within the same container) What would the declaration consist of in positioning an element relative to other content? P {position: relative;} This alone will not position an element: why?

Positioning: Relative Add additional instructions to the declaration. What would the properties be? Top, bottom, left, right Example: P {position: relative; top: 5px; left: 75px;} What will these instructions do to our paragraph? Create space between the previous element and the element you are altering. Also it will add space left of the element you are altering What is the problem with setting bottom and right values? If creating right values, it can push the content off the left of the page If creating bottom values, it can obscure content above the positioned element. What elements can we alter? Any and (almost)all! p, div, table, h1, h2…

Try it! Choose an element to alter its positioning (preferably the second element after the one you set width to). If there is not a style created for that particular element, you will want to do that now. If there is, you simply add the positioning and instructions to your declaration. You will want to add a width to the element when creating your style for this exercise. Offset your element using relative positioning with enough px to notice the difference. Be sure to check it in your browser. Show me. 

Positioning: Absolute What does absolute positioning mean? It places elements in exact coordinates on your page independent of elements that come before it. (Not relative to other elements.) What are the “coordinates?” Top, bottom, right, left This allows you to precisely fit together boxes of text, images, and other content on the page, like a jigsaw puzzle. Absolute positioning removes an object from the normal flow of page content. Its size and position has no effect on the position of the content that follows it.

Positioning: Absolute What would the declaration look like for absolute positioning? P {position: absolute;} What else do we need? Add additional instructions for placement. What additional properties and values would be added to the declaration? P {position: absolute: left: 600px; top: 300px;} What will these instructions do to our paragraph? Position the paragraph to 300 px from the top of the page and 600px left of the left side of the webpage.

Try it! Alter the element following the one you positioned as relative. If there is not a style created for that particular element, you will want to do that now. If there is, you simply add the positioning and instructions to your declaration. You will want to add a width to the element when creating your style for this exercise. Offset your element using absolute positioning with enough px to notice the difference. Be sure to check it in your browser. Show me.  Which do you prefer? Did you see a difference in the two different positions? Now remove the relative positioning from the first element. Check it in your browser. What happened?

Text Wrapping and Floating Elements We have worked with text wrapping before using HTML; however, this is a little different. What does text wrapping mean? Text that wraps around another element (eg. Images) What is the property that we will use? Float: What do you think will be the values used? Right, left, or none

Text Wrapping and Floating Elements If I set an image to float right, where will the image be in relation to the text? It will set to the right of the text What will the style rule look like to float an image to the right? Img {float: right;} The image on the webpage floats. What is the style rule for this? Img {float: left;}

Float Elements Continued This is one of the easiest methods of creating multicolumn layouts. You must set a width (if you have not already done so) to the element you want to float Generally, you will want to set widths to the elements you want to float next to as well (if not looking to text wrap but make a column without tables). It is especially helpful if you set content areas in which you are working in div’s.

Try it! Locate an image within your html document to place with text. If you do not have one, save one to your file (be sure to “save it for web”). Create a div around the image and text (you might want the image before your text tag). Create a style that targets your image to float to one side of the text. Be sure to check it in your browser. Show me 

Vertical Alignment (Review) You can align your elements within your div. What will be the property assigned? Vertical-align: What will be the value? Top, bottom, middle, or baseline There is more; however, there are others that we will not be using these at this time (sub, super) This property controls how the elements appear relative to the text or other content that comes before and after it. Due to the size of the elements on the page, there is no need to align the elements vertically at this time. This may come up as a requirement in the lab. Again, this is review from previous lessons.

Something a Little Different Positioning Content

Control the Overlap of Elements You can overlap the elements on your pages by positioning them at similar coordinates. With overlapping, you need to use a “z-index” to specify the overlapping order of elements. An element with greater stacking order will set in front of an element with a lower stacking order.

Control the Overlap of Elements Z-index only works on positioned elements Positioned relative, absolute, or fixed. What would the property be? Z-index: You can assign values to either element as long as you state the z-index for the other.

Control the Overlap of Elements If you want to assign the z-index to the overlapping element only, then you need to add a positive number Overlapping: img.top {position: absolute; left 200px, top 400px; z-index: 1} If you want to assign the z-index to the underlying element only, then you need to assign a negative number Underlying: img.bottom {position: absolute; left: 100px; top: 300px; z-index: -1} You can also assign a z-index to both elements using positive numbers; however, you need to assign the overlapping element a larger number.

Try it! Look for an image that will compliment an image already on your website. Be sure to “save for web.” Place this image in line with your other image within your document. Create a style that will overlap these images to your liking. Be sure to check your page in your browser. Show me 

Spacing Margins and Padding

Set Margins You can control the margins of your web page elements using margin properties. Where would these margins be noticeable? From the outside of a page elements border (whether a border is visible or not). What would these properties be? Margin: (used for all sides) Margin-left: (right, top, bottom) What would the values be? Your value measurement: pt, px, mm, cm, in, pc, ex, em

Try it! Target your paragraphs with an internal style. If you already have a style for your paragraphs, then simply include your instructions for creating margins. Create a margin for all sides that is large enough to be noticeable. Check in your browser and adjust accordingly Show me  What happened when you created a top and bottom margin? Top and bottom margins are only applied to the paragraphs, not the page.

Create Padding Use the padding property to add space around web page content. Adding padding makes elements easier to read and separates content when needed. Where would we notice this spacing? (Hint: think in terms of tables) Inside an elements border (visible or not) Remember, to set space on the outside of an element, use margins.

Create Padding What would the property be to create padding around an element? Padding: What would the values be to create that space? Pt, px, mm, cm, in, pc, ex, em HOWEVER…you can add padding to only one side. What would you do to the declaration? Padding-left: (right, top, bottom)

Try it! Place a border around at least one paragraph Target your paragraphs and create an internal style that creates padding on at least 2 sides that is noticeable Be sure to check in your browser and adjust accordingly. Show me