Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Basic css

Basic css

  1. 2. Basics By Gopinath Ambothi CSS
  2. 3. <ul><li>What is CSS? </li></ul><ul><li>Why CSS? </li></ul><ul><li>Reference CSS from HTML </li></ul><ul><li>CSS Syntax </li></ul><ul><li>ID and Class </li></ul><ul><li>Selectors </li></ul><ul><li>Basic Tags & Properties </li></ul><ul><li>CSS Box Model </li></ul><ul><li>Use Firebug/IE developer toolbar </li></ul>Index
  3. 4. What is CSS? <ul><li>Cascading : Multiple styles can overlap in order to specify a range of style from a whole web site down to a unique element. </li></ul><ul><li>Style : CSS deals specifically with the presentation domain of designing a web page (color, font, layout, etc). </li></ul><ul><li>Sheet : Normally, CSS is a file separate from the HTML file –linked to the HTML (external, exceptions apply). </li></ul>
  4. 5. <ul><li>Allows for much richer document appearances than HTML. </li></ul><ul><li>Reduce workload by centralizing commands for visual appearance instead of scattered throughout the HTML doc. </li></ul><ul><li>Use same style on multiple pages . </li></ul><ul><li>Reduce page download size . </li></ul><ul><li>Use HTML for content; CSS for Presentation. </li></ul>Why CSS?
  5. 6. <link rel=“stylesheet”type=“text/css”href=“style.css”/> HTML<html><head> <link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=“style.css&quot; /> </head>…</html> … … … … style.css … … … … … sample.html Reference CSS from HTML
  6. 7. CSS Syntax h1 { color: red; background: yellow; } Selector Style Block Element Properties Style Values • The Selector selects elements on the HTML page. • The associated Style Block applies its Style Values to the selected Element’s Properties
  7. 8. <ul><li>The id selector is used to specify a style for a single, unique element. </li></ul><ul><li>The id selector uses the id attribute of the HTML element, and is defined with a &quot;#&quot;. </li></ul><ul><li>The style rule below will be applied to the element with id=&quot;para1&quot;: </li></ul><ul><li>#para1{ text-align:center; color:red;} </li></ul>ID and Class The ‘ID’ Selector In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called &quot;id&quot; and &quot;class&quot;.
  8. 9. <ul><li>The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. </li></ul><ul><li>This allows you to set a particular style for any HTML elements with the same class. </li></ul><ul><li>The class selector uses the HTML class attribute, and is defined with a &quot;.&quot; </li></ul><ul><li>In the example below, all HTML elements with class=&quot;center&quot; will be center-aligned: </li></ul><ul><ul><li>.center {text-align:center;} </li></ul></ul>ID and Class The ‘Class’ Selector
  9. 10. Selectors Select elements to apply a declared style. • Selector types: – Element Selectors: selects all elements of a specific type (<body>, <h1>, <p>, etc.) – Class Selectors: selects all elements that belong to a given class. – ID Selectors: selects a single element that’s been given a unique id . – Pseudo Selectors: combines a selector with a user activated state (:hover, :link, :visited)
  10. 11. Selectors Element Selectors • Finds all HTML elements that have the specified element type . • Example: h1{ color: blue; } Finds all elements of type < h1 > and makes the text color blue.
  11. 12. Selectors Class Selectors • Finds all elements of a given class –based on the attribute’s class value . • Syntax: .classname (Remember the dot means class selector) • Example: .legs{ font-weight: bold; background: pink; } Finds all elements whose class = “ legs ” and makes their font bold and their backgrounds pink.
  12. 13. Selectors ID Selectors • Finds a single element that’s been given a unique id –based on the attribute’s id value . • Syntax: #idname (Remember the pound-sign means id selector) • Example: #snout{ border: solid red; } Finds a single element whose id = “ snout ” and gives it a solid red border.
  13. 14. Selectors Pseudo Selectors Apply styles to a user activated state of an element. • If used, must be declared in a specific order in the style sheet. • General Purpose Pseudo-Selector: – :hover Element with mouse over • Specific to hyperlinks (and/or buttons) – a:active A link or button that is currently being clicked on. – a:link A link that has NOT been visited yet. – a:visited A link that HAS been visited.
  14. 15. Grouping Selectors • Lets say you want to apply the same style to several different selectors. Don’t repeat the style – use a comma !! • Syntax: sel1, sel2, sel3 (Remember the comma to group several different selectors) • Example: h1, .legs, #snout{ font-size: 20pt; } Finds all elements of type < h1 >, all elements with class=“ legs ” and the single element whose id = “ snout ” then makes their font-size 20pt.
  15. 16. Conflict Resolution • It’s possible to have different styles applied to the same selector ( C ascading SS ), but what if the styles tell the browser to do conflicting things? • Rules: – Which selector is more specific ? – If the selectors are the same, then which style was applied last ?
  16. 17. Sharpen your Selector • Order of specificity: (specific) id , class , elementtype (ambiguous) • Combine selectors: Elementype.classname or Elementype#idname e.g. p.legs [ or] h2#snout
  17. 18. Sharpen your Selector • Descendant Selectors: Specify the context in the HTML tree from each ancestor down to the desired element –each separated by a space. e.g. body.pigp.pig-head #snout • HTML Tree: <body class=“pig”> <p class=“pig-head”> <h1 id=“snout”> Snout SnoutSnout </h1> </p> </body>
  18. 19. Basic CSS Tags & Properties
  19. 20. <span> Element Tag • Useful for applying style to text within another HTML element. • Use SPARINGLY –unlike <h1> or <p>, <span> has no semantic meaning. • Remember, HTML is for content and HTML tags are for describing that content to non-human or visually-impaired readers. <span> is just used to make things “pretty.”
  20. 21. <div> Element Tag • Useful for dividing parts of the page into sections. • Creates a “box” with the following attributes: – margin – padding – border – height – width – (..and lots more) • Primary element used for CSS Layouts
  21. 22. Color Properties color: specifies the text color. background-color: specifies the background color. black; or #000000; red; or #FF0000; lime; or #00FF00; blue; or #0000FF; white; or #000000; … and more
  22. 23. Background Image Properties background-image: url(../location/of/image.jpg) background-repeat: tile image in background background-position: vertical(top, center, bottom, or size) horizontal(left, center, right, or size) background-attachment : (scrollor fixed)
  23. 24. Font Properties font-family: times, arial, serif, sans-serif, monospace; font-style: italic; font-weight: ( bold , bolder , lighter, or 100 – 900;) font-size: size; … or shorthand font: style weight size family;
  24. 25. Text Properties text-indent: indents first line of a paragraph according to size text-align: right;or left;or center;or justify; text-decoration: none; orunderline; text-transform: Capitalize; Line-height: added vertical space to each line of text according to size
  25. 26. List Properties list-style-type: none, disc, circle, square,(other types available) list-style-position : inside or outside list-style-image: url(../path/to/image.jpg) … or shorthand list-style: type position image
  26. 27. Border Properties border-width: (thin, medium, thick, or size) border-style: (none, hidden, dotted, dashed, solid, double, groove, ridge, inset, or outset) border-color: color … or shorthand border(-top, -right, -left, -bottom): width style color
  27. 28. Position Properties Absolute - The box is placed in an absolute location relative to the container block. The element's position is specified with the &quot;left&quot;, &quot;top&quot;, &quot;right&quot;, and &quot;bottom&quot; properties Fixed - Generates an absolutely positioned element, positioned relative to the browser window. The element's position is specified with the &quot;left&quot;, &quot;top&quot;, &quot;right&quot;, and &quot;bottom&quot; properties Relative - Generates a relatively positioned element, positioned relative to its normal position, so &quot;left:20&quot; adds 20 pixels to the element's LEFT position Static - Default. No position, the element occurs in the normal flow (ignores any top, bottom, left, right, or z-index declarations) Inherit - The element should have the same position value as the parent element. Example: trycss_position_relative
  28. 29. Float Properties With CSS float, an element can be pushed to the Left or Right allowing other elements to wrap around it. Float is very often used for images, but it is also useful when working with layouts. How Elements Float? Elements are floated horizontally, this means that an element can only be floated left or right, not up or down. A floated element will move as far to the left or right as it can. Usually this means all the way to the left or right of the containing element. The elements after the floating element will flow around it. The elements before the floating element will not be affected.
  29. 30. CSS Box Model The CSS box model is essentially a box that wraps around HTML elements, and it consists of: margins, borders, padding, and the actual content. The box model allows us to place a border around elements and space elements in relation to other elements. The image below illustrates the box model:
  30. 31. Use Firebug / IE developer tool bar <ul><li>Firebug </li></ul><ul><li>Colorzilla </li></ul><ul><li>MeasureIt </li></ul><ul><li>YSlow </li></ul>
  31. 32. Thank You!

    Be the first to comment

    Login to see the comments

  • imara0604

    Jun. 10, 2011
  • lendave07

    Aug. 8, 2011
  • SoumenBose1

    Jan. 19, 2012
  • cuiul

    Feb. 25, 2012
  • carlosvictordasilva

    May. 31, 2012
  • sandrajay

    Nov. 14, 2012
  • blezha

    Dec. 18, 2012
  • speakgeek

    Feb. 17, 2013
  • stefrivera3

    Nov. 16, 2014
  • SalmaSiddiqua2

    Aug. 6, 2016

    Nov. 4, 2017
  • reenagg

    Jul. 30, 2018
  • ahmedsaadmohamed1

    Dec. 29, 2019


Total views


On Slideshare


From embeds


Number of embeds