SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Shaping up with CSS
               <understanding how true CSS layouts are built />




Advanced CSS                                                      Stephen Ireland
Understanding Elements

• HTML elements
• Marked up as <tags />
• Two types of HTML elements


    Block level elements       Inline elements
    <h1>, <h2>, <h3> etc       <span>

    <p>                        <strong>

    <div>                      <em>

    <blockquote>               <a>

    <ul> and <ol>
Advanced CSS                                     Stephen Ireland
Block level Elements

• Fundamental differences in use
• Identified as normally displayed on its own line
• Other elements appear above or below - not either side
• Can be used as a container for one or more other elements


    The rules

• A block level element can contain other block-level elements,
    as well as inline elements.
• An inline element cannot contain block-level elements.


Advanced CSS                                          Stephen Ireland
Block Element Rule

    The rule




                                           x
    <div>
        <a href=”#”><h1>My link</h1></a>
    </div>




                                           ✓
    <div>
        <h1><a href=”#”>My link</a></h1>
    </div>



Advanced CSS                               Stephen Ireland
Inline Element Rule

    The rule

    It’s okay to nest one inline element inside another;


    <div>




                                                           ✓
        <h1>
               <a href=”#”><span>My link</span></a>
        </h1>
    </div>



Advanced CSS                                               Stephen Ireland
Element Symmetry

    Opening & closing XHTML tags

    <div>




                                                     x
        <h1>
               <a href=”#”>
                 <span>My link</span>

                     ←
               </h1>
        </a>              h1 element should not close before a
    </div>

    Can be checked using online validators (validator.w3.org)

Advanced CSS                                                Stephen Ireland
Styling Elements

    Inline elements
• Changing colour (text and background)
• Changing font styles (size, typeface, bold, underline, etc.)


    Block-level elements
• Set fixed width or height
• Set padding or margin values
• Position a block to any location on a web page, regardless
    of where it appears in the XHTML markup

    This is why block-level elements are more powerful

Advanced CSS                                             Stephen Ireland
Sizing Defaults
    Block-level elements
• Will take 100% of available width
• Available width could be parent element
• Or could be browser window
• Takes whatever height it needs




Advanced CSS                                Stephen Ireland
Setting Heights & Widths
    Setting a width
    This CSS declaration will adjust a paragraph with the class
    value of ‘highlight’. The paragraph will become 50% the width
    of its containing element.


    CSS declaration

    p.highlight {
        width: 50%;
    }

Advanced CSS                                              Stephen Ireland
Units of Measurement

    When sizing and positioning elements we can use different
    units of measurement. Each unit type have their benefits and
    drawbacks. Although different unit types can be mixed within
    layouts, problems may occur.


    Units
• Pixels (px) for fixed sizing / positioning
• Percentages (%) for sizes relative to containing elements
• Ems (em) for sizes relative to base font size
• Points (pt) for print based styles

Advanced CSS                                            Stephen Ireland
Fixed Block-Level Sizing

    Setting a height as well as a width to a block-level element is
    just as simple, although be wary of possible consequences.


    CSS declaration

    #navigation {
        background-color: #cccccc;
        width: 200px;
        height: 400px;
    }


Advanced CSS                                               Stephen Ireland
Browser Behaviour

    If you set a height that is less than the room needed for the
    content of the element, that content will overflow.

    Firefox                         Internet Explorer




Advanced CSS                                              Stephen Ireland
Other Occurances

    If a visitor to your
    website increases the
    font-size, text may
    overflow the containing
    element of a fixed size.




Advanced CSS                   Stephen Ireland
Overflow:Hidden

    There is a way to stop elements escaping the bounds of
    their containing element - set the CSS overflow property
    to ‘hidden’. Bad practice in this situation as text becomes
    unreadable anyway...


    #navigation {
        background-color: #cccccc;
        width: 200px;
        height: 300px;
    	 overflow:	hidden;
    }
Advanced CSS                                              Stephen Ireland
Positioning Elements

    Full CSS layouts
• Without intervention from CSS, a web
    browser will display elements in the
    order they appear in the source file.
• By full CSS layouts, we mean layouts
    that use CSS entirely for positioning
    elements in the web browser window.
• There are many different ways to create CSS layouts.
• Best practice methods often harder to achieve.


Advanced CSS                                             Stephen Ireland
Full CSS Layouts

    Conventional layouts
• Comprise of
    • A header
    • Two or three columns
    • A footer
• Use <div> tags for layout hooks
• Use XHTML property ‘id’ to style div elements individually

    XHTML                        CSS
    <div id=”banner”></div>      #banner { width: 760px; }

Advanced CSS                                           Stephen Ireland
Layout Options

    Debate
• Fixed-width
• Fluid-width
• Semi-fluid (one fixed width column, one fluid width)
• Zoom (entire layout relative to font size)
• Resolution-dependent (Made possible with Javascript)


    All types of layouts are dependent on methods of sizing and
    positioning of the block-level elements.



Advanced CSS                                             Stephen Ireland
Positioning Block-Level Elements

    CSS	‘position’	property	
• Static
• Relative
                       #banner { position: absolute; }
• Absolute
• Fixed

    CSS	‘float’	property	
• Left
• Right                #left-col { float: left; }
• None

Advanced CSS                                         Stephen Ireland
Easiest positioning Method

    CSS	‘position’	property	
• Static
• Relative

               ←
                            #banner { position: absolute; }
• Absolute
• Fixed            Its absolute positioning

    CSS	‘float’	property	
• Left
• Right                     #left-col { float: left; }
• None

Advanced CSS                                              Stephen Ireland
Position:Absolute

    Absolute positioning gives you total control where a
    block-level element appears in the browser window. This
    declaration positions a div with id of ‘banner’ 10 pixels
    from the top and left of the browser window.


                                  ←
    #banner {
        position: absolute;
        top: 50px;
        left: 50px;
    }


Advanced CSS                                               Stephen Ireland
Top, right, Bottom, Left

• Absolute positioning relies on a
    position being set.
• If you don’t provide positions, your
    elements will overlap one another.
• Make sure to set one or two values
• In most cases you will work from the
    top-left corner of the browser window.
    Therefore, most commonly used
    properties are ‘top’ and ‘left’.



Advanced CSS                                 Stephen Ireland
Handy Tips

• Before moving on to more complex positioning schema,
    experiment with the control absolute positioning gives you.
• Set background-color on the different main elements, or
    give each element a border temporarily until you have
    your layout how you intended. You’ll be able to see where
    each element starts and ends, without holding a ruler in
    front of the screen!
• Nothing is ever nothing unless specified - most browsers
    have default margins and paddings which could upset
    your design. If in doubt - specify them with zero value.


Advanced CSS                                             Stephen Ireland

Weitere ähnliche Inhalte

Was ist angesagt?

WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
New Tricks
 

Was ist angesagt? (20)

Intro to Sass for WordPress Developers
Intro to Sass for WordPress DevelopersIntro to Sass for WordPress Developers
Intro to Sass for WordPress Developers
 
How to use CSS3 in WordPress - Sacramento
How to use CSS3 in WordPress - SacramentoHow to use CSS3 in WordPress - Sacramento
How to use CSS3 in WordPress - Sacramento
 
Maintainable CSS
Maintainable CSSMaintainable CSS
Maintainable CSS
 
CSS Best practice
CSS Best practiceCSS Best practice
CSS Best practice
 
Sass
SassSass
Sass
 
CSS Reset
CSS ResetCSS Reset
CSS Reset
 
How to use CSS3 in WordPress
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPress
 
Srijan presentation on CSS
Srijan presentation on CSSSrijan presentation on CSS
Srijan presentation on CSS
 
Artdm171 Week5 Css
Artdm171 Week5 CssArtdm171 Week5 Css
Artdm171 Week5 Css
 
CSS Introduction
CSS IntroductionCSS Introduction
CSS Introduction
 
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
 
css-tutorial
css-tutorialcss-tutorial
css-tutorial
 
Less css
Less cssLess css
Less css
 
The ABCs of HTML
The ABCs of HTMLThe ABCs of HTML
The ABCs of HTML
 
CSS For Backend Developers
CSS For Backend DevelopersCSS For Backend Developers
CSS For Backend Developers
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
6 Steps to Make Your CSS Code More Maintainable
6 Steps to Make Your CSS Code More Maintainable6 Steps to Make Your CSS Code More Maintainable
6 Steps to Make Your CSS Code More Maintainable
 
Intro to SASS CSS
Intro to SASS CSSIntro to SASS CSS
Intro to SASS CSS
 
The Future Of CSS
The Future Of CSSThe Future Of CSS
The Future Of CSS
 
Sass presentation
Sass presentationSass presentation
Sass presentation
 

Andere mochten auch (7)

Css Positioning Elements
Css Positioning ElementsCss Positioning Elements
Css Positioning Elements
 
Css positioning
Css positioningCss positioning
Css positioning
 
Lesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayLesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ay
 
5 domain name worksheet
5   domain name worksheet5   domain name worksheet
5 domain name worksheet
 
CSS font-stacks
CSS font-stacksCSS font-stacks
CSS font-stacks
 
Anatomy Of A Domain Name and URL
Anatomy Of A Domain Name and URLAnatomy Of A Domain Name and URL
Anatomy Of A Domain Name and URL
 
Purchase Your Domain Name
Purchase Your Domain NamePurchase Your Domain Name
Purchase Your Domain Name
 

Ähnlich wie Shaping Up With CSS

Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
 
High Performance Front-End Development
High Performance Front-End DevelopmentHigh Performance Front-End Development
High Performance Front-End Development
drywallbmb
 
CSS Layout Tutorial
CSS Layout TutorialCSS Layout Tutorial
CSS Layout Tutorial
hstryk
 
Even faster web sites presentation 3
Even faster web sites presentation 3Even faster web sites presentation 3
Even faster web sites presentation 3
Felipe Lavín
 

Ähnlich wie Shaping Up With CSS (20)

Css tips & tricks
Css tips & tricksCss tips & tricks
Css tips & tricks
 
Designing for the web - 101
Designing for the web - 101Designing for the web - 101
Designing for the web - 101
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
 
Intro to CSS
Intro to CSSIntro to CSS
Intro to CSS
 
Css
CssCss
Css
 
High Performance Front-End Development
High Performance Front-End DevelopmentHigh Performance Front-End Development
High Performance Front-End Development
 
Web Programming Basic topic.pptx
Web Programming Basic topic.pptxWeb Programming Basic topic.pptx
Web Programming Basic topic.pptx
 
Basics of Rich Internet Applications
Basics of Rich Internet ApplicationsBasics of Rich Internet Applications
Basics of Rich Internet Applications
 
David Weliver
David WeliverDavid Weliver
David Weliver
 
Css3
Css3Css3
Css3
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4
 
CSS Layout Tutorial
CSS Layout TutorialCSS Layout Tutorial
CSS Layout Tutorial
 
Web Layout
Web LayoutWeb Layout
Web Layout
 
Web-03-CSS.ppt
Web-03-CSS.pptWeb-03-CSS.ppt
Web-03-CSS.ppt
 
Style Your Site Part 1
Style Your Site Part 1Style Your Site Part 1
Style Your Site Part 1
 
Web
WebWeb
Web
 
Even faster web sites presentation 3
Even faster web sites presentation 3Even faster web sites presentation 3
Even faster web sites presentation 3
 
Html5 elements-Kip Academy
Html5 elements-Kip AcademyHtml5 elements-Kip Academy
Html5 elements-Kip Academy
 
Managing responsive websites with css preprocessors.
Managing responsive websites with css preprocessors. Managing responsive websites with css preprocessors.
Managing responsive websites with css preprocessors.
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 

Kürzlich hochgeladen

unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
Abortion pills in Kuwait Cytotec pills in Kuwait
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
lizamodels9
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
amitlee9823
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
lizamodels9
 
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂EscortCall Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
dlhescort
 

Kürzlich hochgeladen (20)

unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
 
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
 
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
 
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂EscortCall Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business Potential
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLWhitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 

Shaping Up With CSS

  • 1. Shaping up with CSS <understanding how true CSS layouts are built /> Advanced CSS Stephen Ireland
  • 2. Understanding Elements • HTML elements • Marked up as <tags /> • Two types of HTML elements Block level elements Inline elements <h1>, <h2>, <h3> etc <span> <p> <strong> <div> <em> <blockquote> <a> <ul> and <ol> Advanced CSS Stephen Ireland
  • 3. Block level Elements • Fundamental differences in use • Identified as normally displayed on its own line • Other elements appear above or below - not either side • Can be used as a container for one or more other elements The rules • A block level element can contain other block-level elements, as well as inline elements. • An inline element cannot contain block-level elements. Advanced CSS Stephen Ireland
  • 4. Block Element Rule The rule x <div> <a href=”#”><h1>My link</h1></a> </div> ✓ <div> <h1><a href=”#”>My link</a></h1> </div> Advanced CSS Stephen Ireland
  • 5. Inline Element Rule The rule It’s okay to nest one inline element inside another; <div> ✓ <h1> <a href=”#”><span>My link</span></a> </h1> </div> Advanced CSS Stephen Ireland
  • 6. Element Symmetry Opening & closing XHTML tags <div> x <h1> <a href=”#”> <span>My link</span> ← </h1> </a> h1 element should not close before a </div> Can be checked using online validators (validator.w3.org) Advanced CSS Stephen Ireland
  • 7. Styling Elements Inline elements • Changing colour (text and background) • Changing font styles (size, typeface, bold, underline, etc.) Block-level elements • Set fixed width or height • Set padding or margin values • Position a block to any location on a web page, regardless of where it appears in the XHTML markup This is why block-level elements are more powerful Advanced CSS Stephen Ireland
  • 8. Sizing Defaults Block-level elements • Will take 100% of available width • Available width could be parent element • Or could be browser window • Takes whatever height it needs Advanced CSS Stephen Ireland
  • 9. Setting Heights & Widths Setting a width This CSS declaration will adjust a paragraph with the class value of ‘highlight’. The paragraph will become 50% the width of its containing element. CSS declaration p.highlight { width: 50%; } Advanced CSS Stephen Ireland
  • 10. Units of Measurement When sizing and positioning elements we can use different units of measurement. Each unit type have their benefits and drawbacks. Although different unit types can be mixed within layouts, problems may occur. Units • Pixels (px) for fixed sizing / positioning • Percentages (%) for sizes relative to containing elements • Ems (em) for sizes relative to base font size • Points (pt) for print based styles Advanced CSS Stephen Ireland
  • 11. Fixed Block-Level Sizing Setting a height as well as a width to a block-level element is just as simple, although be wary of possible consequences. CSS declaration #navigation { background-color: #cccccc; width: 200px; height: 400px; } Advanced CSS Stephen Ireland
  • 12. Browser Behaviour If you set a height that is less than the room needed for the content of the element, that content will overflow. Firefox Internet Explorer Advanced CSS Stephen Ireland
  • 13. Other Occurances If a visitor to your website increases the font-size, text may overflow the containing element of a fixed size. Advanced CSS Stephen Ireland
  • 14. Overflow:Hidden There is a way to stop elements escaping the bounds of their containing element - set the CSS overflow property to ‘hidden’. Bad practice in this situation as text becomes unreadable anyway... #navigation { background-color: #cccccc; width: 200px; height: 300px; overflow: hidden; } Advanced CSS Stephen Ireland
  • 15. Positioning Elements Full CSS layouts • Without intervention from CSS, a web browser will display elements in the order they appear in the source file. • By full CSS layouts, we mean layouts that use CSS entirely for positioning elements in the web browser window. • There are many different ways to create CSS layouts. • Best practice methods often harder to achieve. Advanced CSS Stephen Ireland
  • 16. Full CSS Layouts Conventional layouts • Comprise of • A header • Two or three columns • A footer • Use <div> tags for layout hooks • Use XHTML property ‘id’ to style div elements individually XHTML CSS <div id=”banner”></div> #banner { width: 760px; } Advanced CSS Stephen Ireland
  • 17. Layout Options Debate • Fixed-width • Fluid-width • Semi-fluid (one fixed width column, one fluid width) • Zoom (entire layout relative to font size) • Resolution-dependent (Made possible with Javascript) All types of layouts are dependent on methods of sizing and positioning of the block-level elements. Advanced CSS Stephen Ireland
  • 18. Positioning Block-Level Elements CSS ‘position’ property • Static • Relative #banner { position: absolute; } • Absolute • Fixed CSS ‘float’ property • Left • Right #left-col { float: left; } • None Advanced CSS Stephen Ireland
  • 19. Easiest positioning Method CSS ‘position’ property • Static • Relative ← #banner { position: absolute; } • Absolute • Fixed Its absolute positioning CSS ‘float’ property • Left • Right #left-col { float: left; } • None Advanced CSS Stephen Ireland
  • 20. Position:Absolute Absolute positioning gives you total control where a block-level element appears in the browser window. This declaration positions a div with id of ‘banner’ 10 pixels from the top and left of the browser window. ← #banner { position: absolute; top: 50px; left: 50px; } Advanced CSS Stephen Ireland
  • 21. Top, right, Bottom, Left • Absolute positioning relies on a position being set. • If you don’t provide positions, your elements will overlap one another. • Make sure to set one or two values • In most cases you will work from the top-left corner of the browser window. Therefore, most commonly used properties are ‘top’ and ‘left’. Advanced CSS Stephen Ireland
  • 22. Handy Tips • Before moving on to more complex positioning schema, experiment with the control absolute positioning gives you. • Set background-color on the different main elements, or give each element a border temporarily until you have your layout how you intended. You’ll be able to see where each element starts and ends, without holding a ruler in front of the screen! • Nothing is ever nothing unless specified - most browsers have default margins and paddings which could upset your design. If in doubt - specify them with zero value. Advanced CSS Stephen Ireland