Floating Elements CS380.

Slides:



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

LIS650 lecture 4 Thomas Krichel today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors.
Copenhagen, 6 December 2004 Modern CSS Principles Miruna Bădescu Finsiel Romania.
Week 10 Creating Positioned Layouts
1 Cascading Style Sheets Continued Different kinds of selectors in a style sheet –Simple- Pseudo-Class –Contextual- Pseudo-Element –Class Image Styles.
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
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 6 Key Concepts 1 Copyright © Terry Felke-Morris.
Layout using CSS. Using multiple classes In the head:.important{font-style:italic;}.title{color:red;} In the body: Here's a type of paragraph that is.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 6 Key Concepts 1 Copyright © Terry Felke-Morris.
Slide 1 CMPS 211 Internet Programming Spring 2008 Dynamic Effects with Styles Chapter 12 2/6/08.
Chapter 7 Page Layout Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Very quick intro HTML and CSS. Sample html A Web Title.
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.
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red“ Example h1.
CIS 1310 – HTML & CSS 6 Layout. CIS 1310 – HTML & CSS Learning Outcomes  Describe & Apply the CSS Box Model  Configure Float with CSS  Designate Positioning.
Today’s objectives Site performance Padding, Margins, Borders
Week 9 Using the Box Properties. 9-2 The CSS Visual Formatting Model Describes how the element content boxes should be displayed by the browser –Based.
Tutorial 6 Creating Fixed-Width Layouts
CSS, cont. October 12, Unit 4. Creating a Sidebar We know how to create a sidebar –Use the float property div#sidebar{ float: left; } Item1 Item2 Item3.
MORE Cascading Style Sheets (The Positioning Model)
1 CS428 Web Engineering Lecture 10 Images, Tables, Forms, Border-Radius (CSS – V)
Slide 1 of 83 Table Borders To specify table borders in CSS, use the border property. The example below specifies a black border for table, th, and td.
Web Development & Design Foundations with XHTML Chapter 6 Key Concepts.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 6 Key Concepts 1 Copyright © Terry Felke-Morris.
The Missing Manual MARGINS, PADDING, & BORDERS—CHAPTER 7.
Copyright © Terry Felke-Morris CSS Flow & Positioning 1 Copyright © Terry Felke-Morris.
Tutorial #6 – Creating Fixed Width Layouts. Tutorial #5 Review – Box Model Every html element is surround by a box Content, Padding, Border, Margin Can.
CSE 154 LECTURE 4: FLOATING AND POSITIONING. The CSS float property propertydescription floatside to hover on; can be left, right, or none (default) a.
Floating Elements CS The CSS float property (reference) 2 img.headericon { float: right; width: 130px; } CSS  removed from normal document flow;
Week 8 – Part 2 Page Layout Basics Key Concepts 1.
THE BOX MODEL Putting layouts together with CSS. The Box Model  How would you describe a box?  Container?  Tags or elements are “containers”  puts.
1 CS428 Web Engineering Lecture 08 Border, Margin, Padding … (CSS - III)
Web Development & Design Foundations with HTML5 7th Edition
INTRODUCTORY Tutorial 5 Using CSS for Layout and Printing.
CSS Layout Cascading Style Sheets. Lesson Overview  In this lesson, you will learn:  float & clear  display & visibility.
CSS Positioning & Layout Creating layouts and controlling elements.
CONTROLLING Page layout
Tutorial 4 Creating Page Layouts with CSS
HTML and Dreamweaver November 11th. Agenda Box Model Displaying and positioning elements – Padding – Margin – Float – Display – Position HTML Demo.
Today’s objectives  Announcements  Positioning  Measurement units.
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.
Laying out Elements with CSS
Cascading Style Sheets Layout
Cascading Style Sheets Boxes
CSS Layouts CH 13.
CSS Layouts: Grouping Elements
Webpage layout using CSS
Lecture 5: Floating and Positioning
Web Development & Design Foundations with HTML5 7th Edition
Chapter 7 Page Layout Basics Key Concepts
Web Development & Design Foundations with HTML5 8th Edition
The Internet 10/25/11 XHTML Tables
Basics of Web Design Chapter 7 Page Layout Basics Key Concepts
Objectives Create a reset style sheet Explore page layout designs
Controlling Layout with Style Sheets
Positioning.
MORE Cascading Style Sheets (The Positioning Model)
Float Property Elements that seem to “float" on the right or left side of either the browser window or another element are often configured using.
Web Development & Design Foundations with H T M L 5
Web Development & Design Foundations with H T M L 5
Floating and Positioning
CSc 337 Lecture 4: Positioning.
CMPT241 Web Programming More CSS: Page Layout.
Positioning.
CSc 337 Lecture 5: Grid layout.
Positioning Boxes Using CSS
CGS 3066: Web Programming and Design Fall 2019 CSS Part 2
Presentation transcript:

Floating Elements CS380

The CSS float property (reference) img.headericon { float: right; width: 130px; } CSS Ghostbusters is a 1984 American science fiction comedy film written by co-stars Dan Aykroyd and Harold Ramis about three eccentric New York City parapsychologists-turned-ghost capturers. output property description float side to hover on; can be left, right, or none (default) removed from normal document flow; underlying text wraps around as necessary

Floating elements diagram CS380

Common float bug: missing width if no width is specified, the floating element may occupy 100% of the page width, so no content can wrap around it often floating block elements must have a width property value Let’s try “floating” CS380

The clear property Super Mario Fan Site! p { background-color: fuchsia; } h2 { clear: right; background-color: yellow; } CSS Mario is a fictional character in his video game series. Serving as Nintendo's mascot and the main protagonist of the series, Mario has appeared in over 200 video games since his creation. output Mario is a fictional character in his video game series. Serving as Nintendo's mascot and the main protagonist of the series, Mario has appeared in over 200 video games since his creation Super Mario Fan Site! CS380

The clear property (cont.) description clear disallows floating elements from overlapping this element; can be left, right, or none (default) CS380

Clear diagram div#sidebar { float: right; } p { clear: right; } CSS

Common error: container too short <p><img src="images/mario.png" alt=“super mario" /> Mario is a fictional character in his video game series.....</p> HTML p { border: 2px dashed black; } img { float: right; } CSS Mario is a fictional character in his video game series. Serving as Nintendo's mascot and the main protagonist of the series, Mario has appeared in over 200 video games since his creation. output We want the p containing the image to extend downward so that its border encloses the entire image

The overflow property p { border: 2px dashed black; overflow: hidden; } CSS Mario is a fictional character in his video game series. Serving as Nintendo's mascot and the main protagonist of the series, Mario has appeared in over 200 video games since his creation. output We want the p containing the image to extend downward so that its border encloses the entire image CS380

The overflow property (cont.) description overflow specifies what to do if an element's content is too large; can be auto, visible, hidden, or scroll We want the p containing the image to extend downward so that its border encloses the entire image CS380

Multi-column layouts Some other text that is important third paragraph <div> <p>first paragraph</p> <p>second paragraph</p> <p>third paragraph</p> Some other text that is important </div> HTML p { float: right; width: 25%; margin: 0.5em; border: 2px solid black; } div { border: 3px dotted green; overflow: hidden; } CSS We want the p containing the image to extend downward so that its border encloses the entire image Some other text that is important output third paragraph second paragraph first paragraph

Sizing and Positioning CS380

The position property (examples) div#ad { position: fixed; right: 10%; top: 45%; } CSS property value description position static default position relative offset from its normal static position absolute a fixed position within its containing element fixed a fixed position within the browser window top, bottom, left, right positions of box's corners

Absolute positioning removed from normal flow #sidebar { position: absolute; left: 400px; top: 50px; } CSS removed from normal flow positioned relative to the block element containing them actual position determined by top, bottom, left, right should often specify a width property as well CS380

Relative positioning #area2 { position: relative; } CSS absolute-positioned elements are normally positioned at an offset from the corner of the overall web page to make the absolute element to position itself relative to some other element's corner, wrap the absolute element in an element whose position is relative How will the html code look? CS380

Fixed positioning removed from normal flow #area2 { position: relative; } CSS removed from normal flow positioned relative to the browser window even when the user scrolls the window, element will remain in the same place How will the html code look? CS380

Alignment vs. float vs. position If possible, lay out an element by aligning its content horizontal alignment: text-align set this on a block element; it aligns the content within it (not the block element itself) vertical alignment: vertical-align set this on an inline element, and it aligns it vertically within its containing element If alignment won't work, try floating the element If floating won't work, try positioning the element absolute/fixed positioning are a last resort and should not be overused Find a good example or w3c

Details about inline boxes Size properties (width, height, min-width, etc.) are ignored for inline boxes margin-top and margin-bottom are ignored, but margin-left and margin-right are not ignored CS380

Details about inline boxes the containing block box's text-align property controls horizontal position of inline boxes within it text-align does not align block boxes within the page each inline box's vertical-align property aligns it vertically within its block box Definitely an example here is needed CS380

The vertical-align property description vertical-align specifies where an inline element should be aligned vertically, with respect to other content on the same line within its block element's box can be top, middle, bottom, baseline (default), sub, super, text-top, text-bottom, or a length value or % baseline means aligned with bottom of non-hanging letters CS380

vertical-align example <p style="background-color: yellow;"> <span style="vertical-align: top; border: 1px solid red;"> Don't be sad! Turn that frown <img src="images/sad.jpg" alt="sad" /> upside down! <img style="vertical-align: bottom“ src="images/smiley.jpg" alt="smile" /> Smiling burns calories, you know. <img style="vertical-align: middle" src="images/puppy.jpg" alt="puppy" /> Anyway, look at this cute puppy; isn't he adorable! So cheer up, and have a nice day. The End. </span> </p> HTML CS380

vertical-align example (cont.) CS380

Common bug: space under image <p style="background-color: red; padding: 0px; margin: 0px"> <img src="images/smiley.png" alt="smile" /> </p> HTML red space under the image, despite padding and margin of 0 this is because the image is vertically aligned to the baseline of the paragraph (not the same as the bottom) setting vertical-align to bottom fixes the problem (so does setting line-height to 0px)

The display property property description display h2 { display: inline; background-color: yellow; } CSS output property description display sets the type of CSS box model an element is displayed with values: none, inline, block, run-in, compact, ... use sparingly, because it can radically alter the page layout CS380

The display property (cont.) p.secret { visibility: hidden; } CSS output hidden elements will still take up space onscreen, but will not be shown to make it not take up any space, set display to none instead can be used to show/hide dynamic HTML content on the page in response to events CS380

The display property <ul id="topmenu"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> HTML #topmenu li { display: inline; border: 2px solid gray; margin-right: 1em; } CSS output lists and other block elements can be displayed inline flow left-to-right on same line width is determined by content