Understanding CSS Basics and Best Practices

Slide Note
Embed
Share

Exploring the fundamentals of CSS including the Box Model, Border, Margin, Padding, Inline styling, Classes, IDs, and more. Dive into the world of Cascading Style Sheets and learn about their relationship with HTML, supported media types, and limitations on various browsers. The slides cover a range of topics from styling elements to advanced techniques, offering insights into creating well-designed web pages.


Uploaded on Sep 16, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. 2 CSS 2014

  2. CSS , , , , CSS Box Model Border, margin, padding

  3. CSS Cascading Style Sheets , ( ) HTML , , , .... screen, print, tv... braille - ,

  4. CSS , HTML CSS 3 <head> HTML <head> <style> h1 { text-align: center; color: red; } </style> </head>

  5. CSS HTML CSS 3 Inline HTML <h1 style="font-size:18px">Page title</h1> link <link href= mycss.css" rel="stylesheet" type="text/css"/> Import - <style type="text/css"> @import "styles.css"; </style> - import Internet Explorer

  6. CSS IE 6-9 A sheet may contain up to 4095 rules A sheet may @import up to 31 sheets @import nesting supports up to 4 levels deep IE 10 A sheet may contain up to 65534 rules A document may use up to 4095 stylesheets @import nesting is limited to 4095 levels (due to the 4095 stylesheet limit)

  7. , , HTML HTML p, div, nav, span, input { : ; : ; : ; }

  8. , , CSS HTML id, classes, , , .. Element HTML / strong { color: blue; } Class / HTML class .myclass { color: blue; } <h1 class="myclass"> </h1>

  9. , , ID HTML / ID #myid { color: blue; } <h1 id="myid"> </h1>

  10. h1 { text-align: center; color: red; } h2 { text-align: center; color: red; } p { text-align: center; color: red; }

  11. . h1, h2, p { text-align: center; color: red; }

  12. #navigation p strong { color: red; } <div id="navigation"> <h1 style="font-size:18px">Page title</h1> <p> Lorem Ipsum is <strong>simply dummy text</strong> of the prin </p> </div>

  13. nav p strong { color: red; } <nav> <h1 style="font-size:18px">Page title</h1> <p> Lorem Ipsum is <strong>simply dummy text</strong> of the prin </p> </nav>

  14. / a[title] { color: red; text-decoration: none; } <p>Lorem Ipsum is <a href="#" title="page title">simply dummy text</a> of the print</p> <p>Lorem Ipsum is <a href="#">simply dummy text</a> of the print</p>

  15. / input[type=text] { color: red; text-decoration: none; } <p>Lorem Ipsum is <a href="#" title="page title">simply dummy text</a> of the print</p> <p>Lorem Ipsum is <a href="#">simply dummy text</a> of the print</p>

  16. / , a[title*=someword] { color: gray; } <p>Lorem Ipsum is <a href="#" title="someword in title">simply dummy text</a> of the print</p> <p>Lorem Ipsum is <a href="#" title="other title">simply dummy text</a> of the print</p>

  17. / body * { font-size: 10px; } <p>Lorem Ipsum is <a href="#" title="someword in title">simply dummy text</a> of the print</p> <p>Lorem Ipsum is <a href="#" title="other title">simply dummy text</a> of the print</p>

  18. p > .otherclass { color: green; }

  19. % percentage in inch cm centimeter mm millimeter em 1em is equal to the current font size. 2em means 2 times the size of the current font. E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses ex one ex is the x-height of a font (x-height is usually about half the font-size) pt point (1 pt is the same as 1/72 inch) pc pica (1 pc is the same as 12 points) px pixels (a dot on the computer screen)

  20. Hex # . Color Color HEX #000000 Color RGB rgb(0,0,0) #FF0000 rgb(255,0,0) #00FF00 rgb(0,255,0) #0000FF rgb(0,0,255) #FFFF00 rgb(255,255,0) #00FFFF rgb(0,255,255) #FF00FF rgb(255,0,255) #C0C0C0 rgb(192,192,192) #FFFFFF rgb(255,255,255)

  21. Property background Description Sets all the background properties in one declaration background-attachment Sets whether a background image is fixed or scrolls with the rest of the page background-color Sets the background color of an element background-image Sets the background image for an element background-position Sets the starting position of a background image background-repeat Sets how a background image will be repeated

  22. body { background-image: url('css/red001.jpg'); background-color: #f4f4f4; background-repeat: no-repeat; background-position: center bottom; background-attachment: scroll; background-size: cover; }

  23. : font-family: Verdana, Geneva, sans-serif; font-size: 10px; font-style: italic; color: #930; opacity: 0.6; text-decoration: line-through; text-transform: uppercase; letter-spacing: 20px; text-align: center; http://www.w3schools.com/cssref/default.asp

  24. <ul class="a"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges <ul class="b"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges <ul class="c"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li> </ul> </li> </ul> </li> </ul>

  25. ul.a { list-style-type: circle; list-style-image: url(css/sqpurple.gif); } ul.b { list-style-type: square; } ul.c { list-style-type: square; list-style-image: none; } ul .b li { background-image: url(css/sqpurple.gif); background-repeat: no-repeat; background-position: 10px 5px; padding-left: 14px; text-indent:20px; }

  26. table { width: 500px; border-collapse: collapse; } border-collapse table, td, th { border: 1px solid green; } th { background-color: green; color: white; }

  27. CSS Box Model CSS box model

  28. CSS Box Model : Margin - border. Margin Border - , padding . Padding - . Padding . - ,

  29. CSS Box Model , box .math { width: 250px; padding: 10px; border: 5px solid gray; margin: 10px; } CSS Box Model = + padding + padding + border + border + margin + margin = + padding + padding + border + border + margin + margin 250px (width) + 20px (left + right padding) + 10px (left + right border) + 20px (left + right margin) = 300px

  30. Border, margin, padding Border - Property border border-bottom border-bottom-color border-bottom-style border-bottom-width border-color border-left border-left-color border-left-style border-left-width border-right border-right-color border-right-style border-right-width border-style border-top border-top-color border-top-style border-top-width border-width Description Sets all the border properties in one declaration Sets all the bottom border properties in one declaration Sets the color of the bottom border Sets the style of the bottom border Sets the width of the bottom border Sets the color of the four borders Sets all the left border properties in one declaration Sets the color of the left border Sets the style of the left border Sets the width of the left border Sets all the right border properties in one declaration Sets the color of the right border Sets the style of the right border Sets the width of the right border Sets the style of the four borders Sets all the top border properties in one declaration Sets the color of the top border Sets the style of the top border Sets the width of the top border Sets the width of the four borders

  31. Border, margin, padding Margin Property margin Description A shorthand property for setting the margin properties in one declaration margin-bottom Sets the bottom margin of an element margin-left Sets the left margin of an element margin-right Sets the right margin of an element margin-top Sets the top margin of an element

  32. Border, margin, padding Padding Property padding Description A shorthand property for setting all the padding properties in one declaration padding-bottom Sets the bottom padding of an element padding-left Sets the left padding of an element padding-right Sets the right padding of an element padding-top Sets the top padding of an element

  33. Position Value static Description Default value. Elements render in order, as they appear in the document flow The element is positioned relative to its first positioned (not static) ancestor element absolute fixed The element is positioned relative to the browser window relative The element is positioned relative to its normal position, so "left:20" adds 20 pixels to the element's LEFT position initial Sets this property to its default value. Read about initial inherit Inherits this property from its parent element. Read about inherit

  34. float , .left { float: left; color: blue; width: 300px; } .right { float: right; color: red; width: 300px; } clear clear: both, left right

  35. display visibility display visibility ! .hidden { visibility: hidden; } .displayhidden { display: none; }

  36. display block padding, border, margin inline height width inline-block height width overflow : http://css-tricks.com/examples/OverflowExample/ z-index Z

  37. a:hover { color: #ff00ff; } CSS a.blue:hover { color: blue; }

  38. p:first-child i { color: blue; } a::before { content: "-"; color: green; } a::after{ content: "-"; }

  39. Selector Example Example description :link a:link Selects all unvisited links :visited a:visited Selects all visited links :active a:active Selects the active link :hover a:hover Selects links on mouse over :focus input:focus Selects the input element which has focus ::first-letter p::first-letter Selects the first letter of every <p> element ::first-line p::first-line Selects the first line of every <p> element :first-child p:first-child Selects every <p> elements that is the first child of its parent ::before p::before Insert content before every <p> element ::after p::after Insert content after every <p> element :lang(language) p:lang(it) Selects every <p> element with a lang attribute value starting with "it"

  40. ?

  41. ! todos@david.bg Skype: todor_pashov https://facebook.com/tpashov acad@david.bg http://acad.david.bg/ @david_academy https://facebook.com/DavidAcademy

Related


More Related Content