Embed presentation
Download to read offline

























![• #next{left:129px;width:43px;}- Positioned 129px to the right (start of #prev is 63px + #prevwidth 43px + extra space), and the width is 43px.• #next{background:url('img_navsprites.gif') no-repeat -91px 0;} - Defines the background image91px to the right (#home width 46px + 1px line divider + #prev width 43px + 1px line divider )Image Sprites - Hover EffectNow we want to add a hover effect to our navigation list.Our new image ("img_navsprites_hover.gif") contains three navigation images and three images to use forhover effects:Because this is one single image, and not six separate files, there will be no loading delay when a userhovers over the image.We only add three lines of code to add the hover effect:Example#home a:hover{background: url('img_navsprites_hover.gif') 0 -45px;}#prev a:hover{background: url('img_navsprites_hover.gif') -47px -45px;}#next a:hover{background: url('img_navsprites_hover.gif') -91px -45px;}Example explained:• Since the list item contains a link, we can use the :hover pseudo-class• #home a:hover{background: transparent url(img_navsprites_hover.gif) 0 -45px;} - For all threehover images we specify the same background position, only 45px further downCSS Attribute SelectorsStyle HTML Elements With Specific AttributesIt is possible to style HTML elements that have specific attributes, not just class and id.Note: Internet Explorer 7 (and higher) supports attribute selectors only if a !DOCTYPE is specified.Attribute selection is NOT supported in IE6 and lower.Attribute SelectorThe example below styles all elements with a title attribute:Example[title]{color:blue;}Attribute and Value SelectorThe example below styles all elements with title="W3Schools":Example[title=W3Schools]{border:5px solid green;}Attribute and Value Selector - Multiple ValuesThe example below styles all elements with a title attribute that contains a specified value. This workseven if the attribute has space separated values:Example[title~=hello] { color:blue; }Styling FormsThe attribute selectors are particularly useful for styling forms without class or ID:Exampleinput[type="text"]{width:150px;display:block;margin-bottom:10px;background-color:yellow;}input[type="button"]{width:120px;margin-left:35px;display:block;}CSS ReferenceBackground PropertiesProperty Description CSSbackground Sets all the background properties in one declaration 126](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fcssintroduction-170801141911%2f85%2fCss-introduction-26-320.jpg&f=jpg&w=240)




CSS (Cascading Style Sheets) allows separation of document content from document presentation by defining styles. CSS can be defined internally, inline, or externally in CSS files. CSS rules have selectors and declarations, where properties and values are used to style elements. Common CSS properties control color, text formatting, background images and colors. Styles can be applied to HTML elements, classes, or IDs. When multiple conflicting styles are defined, styles are cascaded according to precedence rules with inline styles having the highest priority.

























![• #next{left:129px;width:43px;}- Positioned 129px to the right (start of #prev is 63px + #prevwidth 43px + extra space), and the width is 43px.• #next{background:url('img_navsprites.gif') no-repeat -91px 0;} - Defines the background image91px to the right (#home width 46px + 1px line divider + #prev width 43px + 1px line divider )Image Sprites - Hover EffectNow we want to add a hover effect to our navigation list.Our new image ("img_navsprites_hover.gif") contains three navigation images and three images to use forhover effects:Because this is one single image, and not six separate files, there will be no loading delay when a userhovers over the image.We only add three lines of code to add the hover effect:Example#home a:hover{background: url('img_navsprites_hover.gif') 0 -45px;}#prev a:hover{background: url('img_navsprites_hover.gif') -47px -45px;}#next a:hover{background: url('img_navsprites_hover.gif') -91px -45px;}Example explained:• Since the list item contains a link, we can use the :hover pseudo-class• #home a:hover{background: transparent url(img_navsprites_hover.gif) 0 -45px;} - For all threehover images we specify the same background position, only 45px further downCSS Attribute SelectorsStyle HTML Elements With Specific AttributesIt is possible to style HTML elements that have specific attributes, not just class and id.Note: Internet Explorer 7 (and higher) supports attribute selectors only if a !DOCTYPE is specified.Attribute selection is NOT supported in IE6 and lower.Attribute SelectorThe example below styles all elements with a title attribute:Example[title]{color:blue;}Attribute and Value SelectorThe example below styles all elements with title="W3Schools":Example[title=W3Schools]{border:5px solid green;}Attribute and Value Selector - Multiple ValuesThe example below styles all elements with a title attribute that contains a specified value. This workseven if the attribute has space separated values:Example[title~=hello] { color:blue; }Styling FormsThe attribute selectors are particularly useful for styling forms without class or ID:Exampleinput[type="text"]{width:150px;display:block;margin-bottom:10px;background-color:yellow;}input[type="button"]{width:120px;margin-left:35px;display:block;}CSS ReferenceBackground PropertiesProperty Description CSSbackground Sets all the background properties in one declaration 126](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fcssintroduction-170801141911%2f85%2fCss-introduction-26-320.jpg&f=jpg&w=240)



