Download presentation
Presentation is loading. Please wait.
1
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.
2
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
3
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.
4
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.
5
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.
6
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.
7
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
8
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”
9
Applying CSS Layouts
10
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.
11
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?
12
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.
13
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?
14
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…
15
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.
16
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.
17
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.
18
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?
19
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
20
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;}
21
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.
22
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
23
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.
24
Something a Little Different
Positioning Content
25
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.
26
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.
27
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.
28
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
29
Spacing Margins and Padding
30
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
31
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.
32
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.
33
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)
34
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.