Nesting and Floating.

Slides:



Advertisements
Similar presentations
Cascading Style Sheets
Advertisements

Cascading Style Sheets
Session 4: CSS Positioning Fall 2006 LIS Web Team.
Advance CSS (Menu and Layout) Miftahul Huda. CSS Navigation MENU It's truly remarkable what can be achieved through CSS, especially with navigation menus.
Floating Elements CS380.
Tutorial 6 Creating Fixed-Width Layouts
Technologies for web publishing Ing. Václav Freylich Lecture 6.
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)
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.
Web Design Transparent Backgrounds. Why : Allow text to appear clearly above a graphic background image that still can be seen in the background. Without.
Web Development & Design Foundations with XHTML Chapter 6 Key Concepts.
ITP 104.  While you can do things like this:  Better to use styles instead:
CSS The Definitive Guide Chapter 8.  Allows one to define borders for  paragraphs  headings  divs  anchors  images  and more.
Copyright © Terry Felke-Morris CSS Flow & Positioning 1 Copyright © Terry Felke-Morris.
WRT235: Writing in Electronic Environments CSS Classes, IDs, divs.
End User Computing More on HTML and CSS Sujana Jyothi Department of Computer Science
 Remember that HTML is just text  Need to point to pictures  Use the img tag  alt: › screen reader › REQUIRED for this class and to validate.
Lecture 2 - HTML and CSS Review SFDV3011 – Advanced Web Development 1.
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.
INTRODUCTORY Tutorial 5 Using CSS for Layout and Printing.
Web Design (12) CSS Introduction. Cascading Style Sheets - Defined CSS is the W3C standard for defining the presentation of documents written in HTML.
CONTROLLING Page layout
Nesting and Floating. Nesting and Floating Elements To make our page content appear the way we want, and to make the best use of screen space, we can.
CSS Box Model. What is the Box Model? Each XHTML element appearing on our page takes up a "box" or "container" of space. Each box size is affected not.
HTML & CSS Contents: the different ways we can use to apply CSS to The HTML documents CSS Colors and Background CSS Fonts CSS Text CSS box model: padding,
NAVIGATION USING HTML TO SET UP THE BASIC STRUCTURE OF A NAV BAR.
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.
Cascading Style Sheets for layout
Laying out Elements with CSS
More CSS.
CCT260H - Christopher Evan Jones
CSS Box Model.
Web Development & Design Foundations with XHTML
CSS Box Model.
4.01 Cascading Style Sheets
Nesting and Floating.
CSS Table Styling.
Fix the CSS syntax errors below
Webpage layout using CSS
Floating & Positioning
Float.
Advanced CSS BIS1523 – Lecture 20.
Nesting and Floating Elements
Cascading Style Sheets for layout
Cascading Style Sheets (Layout)
CSS Table Styling.
Introduction to CSS.
Introduction to Web programming
Creating Layouts Using CSS
Controlling Layout with Style Sheets
Positioning.
MORE Cascading Style Sheets (The Positioning Model)
Web Programming Language
CSS Box Model.
More CSS.
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.
Floating and Positioning
Web Programming Language
New Semantic Elements (Part 1)
CSS Box Model.
Web Development & Design Foundations with XHTML
Positioning.
Nesting and Floating.
Session 4: CSS Positioning
Laying out Elements with CSS
4.01 Cascading Style Sheets
CSc 337 Lecture 5: Grid layout.
Web Programming and Design
CGS 3066: Web Programming and Design Fall 2019 CSS Part 2
Presentation transcript:

Nesting and Floating

Nesting and Floating Elements To make our page content appear the way we want, and to make the best use of screen space, we can nest and float XHTML elements. Nesting merely refers to placing elements inside other elements. As in real life, smaller boxes can be nested into larger boxes. We will use this frequently when laying out our web page. Floating in XHTML refers to causing elements, such as <div> containers, to stay to the right or left side of the page, while other elements appear to their side, rather than just above and below. Let's build some examples of nesting and floating to make each of these concepts clearer.

Example: Nesting <div> Elements <style type="text/css"> .green { width: 300px; height: 300px; background-color: green; } .blue { width: 200px; height: 200px; background-color: blue; .yellow { width: 100px; height: 100px; background-color: yellow; ... <div class="green"> <div class="blue"> <div class="yellow"></div> </div> <!-- blue --> </div> <!-- green --> Here we've placed a box (yellow) inside another box (blue), which is inside a parent box (green). Notice the comments after the final two closing </div> tags. These can help us later, especially if there's a lot of code between the opening and closing tags.

The Need for Floating Elements Up to now, the elements we created in our documents were "stacked" vertically. Once we closed an element, the following element appeared directly below it: <style type="text/css"> .green { width: 120px; height: 120px; background-color: green; } .blue { background-color: blue; ... <div class="green"></div> <div class="blue"></div> How do we use the remaining horizontal space on the page? A common method is to use the float property.

The float Property <style type="text/css"> .green { width: 120px; height: 120px; background-color: green; } .floatleft { float: left; .blue { background-color: blue; ... <div class="green floatleft"></div> <div class="blue floatleft"></div> Here we created a separate class to float an element to the left side of the page and applied the class to both div containers. Although <div> is the most commonly floated element, other XHTML elements - such as <img> - can be floated on the page too.

Text with Floated Elements <style type="text/css"> ... .floatleft { float: left; } <div class="green floatleft"></div> <div class="blue floatleft"></div> <p>Paragraph 1</p> <p>Paragraph 2</p> <p>Paragraph 3</p> <p>Paragraph 4</p> <p>Paragraph 5</p> Text placed into the document will use the available space alongside the floated elements. When it runs out of space, it will wrap to the next empty line and continue normally. What if we want text (or other elements) to start at an empty line before all the floated space has been used? We can accomplish that with the clear property.

Clearing the Float <style type="text/css"> ... .floatleft { float: left; } .clearfloat { clear: both; <div class="green floatleft"></div> <div class="blue floatleft"></div> <p>Paragraph 1</p> <p>Paragraph 2</p> <div class="clearfloat"></div> <p>Paragraph 3</p> <p>Paragraph 4</p> <p>Paragraph 5</p> By applying the class containing the clear property, we are forcing subsequent content to appear below the floated elements. We could have applied the clearing class directly to the content element instead - in this case, the <p> element for the third paragraph. But by using a separate <div> to clear the float, our markup is a little easier to read and understand.

Floating Right and Left <style type="text/css"> ... .floatleft { float: left; } .floatright { float: right; .clearfloat { clear: both; <div class="green floatleft"></div> <div class="blue floatright"></div> <p>Paragraph 1</p> <p>Paragraph 2</p> <div class="clearfloat"></div> <p>Paragraph 3</p> <p>Paragraph 4</p> <p>Paragraph 5</p> We can also float elements to both the right and left sides of the page. Subsequent content will then fill the available space between. Let's see how this method can be used to create a basic web page layout.

Basic Page Layout Using Float .header { width: 600px; height: 100px; border: 1px solid orange; } .nav { width: 125px; height: 250px; border: 1px solid green; .sidebar { border: 1px solid blue; .main { height: 350px; .footer { height: 50px; border: 1px solid red; <div class="header">Header</div> <div class="nav floatleft">Nav Menu</div> <div class="sidebar floatright">Sidebar</div> <div class="main"><h1>Main Content</h1></div> <div class="clearfloat"></div> <div class="footer">Footer</div>