CSS RWD Grid view ”; Previous Next A grid view is a layout system that organizes content on a webpage in a grid structure. The grid in its responsive form adapts to different screen sizes and devices. A grid view involves dividing the webpage into a series of columns and rows. Each section of the grid can contain different elements such as images, text, and any other content. A typical grid-view may have 12 columns, and has a total width of 100%. The grid will shrink and expand as the size of the browser changes. CSS RWD Grid view – Building In order to build a grid view, one must make sure that all the HTML elements have the box-sizing property set to border-box. Setting of this property makes the padding and border are included in the total width and height of the elements. Use the following code snippet to set the box-sizing propert: * { box-sizing: border-box; } Add the above syntax to your CSS. CSS RWD Grid view – Example Refer the example below that demonstrates the responsive web page, in a grid view, with 2 columns: <html> <head> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <style> * { box-sizing: border-box; } .title { border: 2px solid black; padding: 10px; background-color: blanchedalmond; } .grid-one { width: 60%; float: left; padding: 10px; border: 2px solid black; background-color: darkseagreen; } .grid-two { width: 40%; float: left; padding: 15px; border: 2px solid black; background-color: lightgreen; } </style> </head> <body> <div class=”title”> <h1>Responsive Web Design</h1> </div> <div class=”grid-two”> <ul> <li>Viewport</li> <li>Grid view</li> <li>Media queries</li> <li>Images</li> <li>Videos</li> <li>Frameworks</li> </ul> </div> <div class=”grid-one”> <h3>Grid view</h3> <p>A grid view</b> is a layout system that organizes content on a webpage in a grid structure. The grid in its responsive form adapts to different screen sizes and devices.</p> <p>Resize the browser window to see how the content gets responsive to the resizing.</p> </div> </body> </html> Print Page Previous Next Advertisements ”;
Category: css
CSS – Shapes
CSS – shape-outside ”; Previous Next CSS shape-outside property is used to define a shape around which inline content (such as text or images) should wrap. This property is particularly useful for creating non-rectangular or complex text wrapping shapes. Possible Values none − Inline content flows around the element”s margin box, while the float area remains unchanged. margin-box − It represents the shape around the outside edge of the margin, with the corner radii specified by the border-radius and margin values. content-box − It represents the shape around the outside edge of the content. The corner radius of the box is determined by taking the larger value between 0 and border-radius – border-width – padding. border-box − It represents the shape around the outside edge of the border. The shape for the outside of the border follows the standard border radius shaping rule. padding-box − It represents the shape around the outside padding edge. The shape for the inside of the border follows the standard border radius shaping rule. <basic-shape> − The shape created with functions such as circle(), ellipse(), polygon(), or path() (introduced in the level 2 specification,) determines the float area. url() − It identifies which image should be used to wrap text around. linear-gradient() − To create gradient shapes that text and other inline content can wrap around. Applies to Floats. Syntax shape-outside = none | margin-box | content-box | border-box | padding-box | circle() | ellipse() | inset() | polygon | path() | url() | linear-gradient(); CSS shape-outside – margin-box The following example demonstrates the proeprty shape-outside: margin-box property defines that content should wrap around the outer edge of the element”s margin box − <html> <head> <style> .box-shape { float: left; width: 150px; height: 150px; background-color: violet; border: 8px blue; border-style: dashed double; padding: 20px; text-align: center; background-clip: content-box; shape-outside: margin-box; margin: 20px; } </style> </head> <body> <div class=”box-shape”>content box</div> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non arcu justo. Integer et ex ut justo auctor aliquam ac nec augue. Vivamus sit amet augue vitae mi scelerisque congue ac vel lacus. </p> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non arcu justo. Integer et ex ut justo auctor aliquam ac nec augue. Vivamus sit amet augue vitae mi scelerisque congue ac vel lacus. </p> </body> </html> CSS shape-outside – content-box The following example demonstrates the propertyshape-outside: content-box property defines that content should wrap around the element”s content box − <html> <head> <style> .box-shape { float: left; width: 150px; height: 150px; background-color: violet; border: 8px blue; border-style: dashed double; padding: 20px; text-align: center; background-clip: content-box; shape-outside: content-box; margin: 10px; } </style> </head> <body> <div class=”box-shape”>content box</div> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non arcu justo. Integer et ex ut justo auctor aliquam ac nec augue. Vivamus sit amet augue vitae mi scelerisque congue ac vel lacus. </p> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non arcu justo. Integer et ex ut justo auctor aliquam ac nec augue. Vivamus sit amet augue vitae mi scelerisque congue ac vel lacus. </p> </body> </html> CSS shape-outside – padding-box The following example demonstrates the property shape-outside: padding-box property defines that content should wrap around the outer edge of the element”s padding box − <html> <head> <style> .box-shape { float: left; width: 150px; height: 150px; background-color: violet; border: 8px blue; border-style: dashed double; padding: 20px; text-align: center; background-clip: content-box; shape-outside: padding-box; margin: 10px; } </style> </head> <body> <div class=”box-shape”>content box</div> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non arcu justo. Integer et ex ut justo auctor aliquam ac nec augue. Vivamus sit amet augue vitae mi scelerisque congue ac vel lacus. </p> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non arcu justo. Integer et ex ut justo auctor aliquam ac nec augue. Vivamus sit amet augue vitae mi scelerisque congue ac vel lacus. </p> </body> </html> CSS shape-outside – border-box The following example demonstrates the property shape-outside: border-box defines the flow of the content around the shape defined by the outer border of the element − <html> <head> <style> .box-shape { float: left; width: 150px; height: 150px; background-color: violet; border: 8px blue; border-style: dashed double; padding: 20px; text-align: center; background-clip: content-box; shape-outside: border-box; margin: 10px; } </style> </head> <body> <div class=”box-shape”>content box</div> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non arcu justo. Integer et ex ut justo auctor aliquam ac nec augue. Vivamus sit amet augue vitae mi scelerisque congue ac vel lacus. </p> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non arcu justo. Integer et ex ut justo auctor aliquam ac nec augue. Vivamus sit amet augue vitae mi scelerisque congue ac vel lacus. </p> </body> </html> CSS shape-outside – circle() The following example demonstrates the property shape-outside: circle() property creates a circular shape, and the content wraps around the edge of the circle − <html> <head> <style> .circle-shape { float: left; width: 150px; height: 150px; margin: 10px; shape-outside: circle(50%); } </style> </head> <body> <div class=”circle-shape”></div> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac mauris sit amet augue consectetur vestibulum. Integer id tortor nec justo consequat laoreet. Aenean volutpat lacinia turpis at facilisis. Proin in malesuada ligula, at cursus erat. Nullam vehicula justo in erat posuere congue. Morbi bibendum purus sit amet libero sagittis, eu tincidunt augue congue. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac mauris sit amet augue consectetur vestibulum. Integer id tortor nec justo consequat laoreet. Aenean volutpat lacinia turpis at facilisis. Proin in malesuada ligula, at cursus erat. Nullam vehicula justo in erat posuere congue. Morbi bibendum purus sit amet libero
CSS – Caret Color
CSS – caret-color ”; Previous Next CSS caret-color property specifies the color of the insertion caret, which is the visible marker indicating where the next typed character will be placed. It is also known as the text input cursor. The caret is found in elements such as <input> or those with contenteditable attribute. This is a thin vertical line, flashing to enhance visibility. It is black by default, but this property allows you to change it. Possible Values auto − The user agent chooses a suitable colour for the caret. The color is commonly currentcolor, but the user agent may select for a different one for better visibility, considering currentcolor, background, shadows, and other factors. Note: Even user agents can use the normally animatable currentcolor for the auto value, it is not interpolated during transitions and animations. <color> − Color of the caret. The insertion caret is just one type; browsers may have a navigation caret for non-editable text, while the cursor over text with the auto property or certain elements is not a caret but a cursor. The mouse cursor image appears as a caret when hovering over text with the auto property or over an element with text or vertical-text property, but it is actually a cursor, not a caret. Applies to All elements. Syntax Keyword Values caret-color: auto; caret-color: transparent; caret-color: currentcolor; <color> Values caret-color: red; caret-color: #5729e9; caret-color: rgb(0 200 0); caret-color: hsl(228deg 4% 24% / 80%); CSS caret-color – auto Value The following example demonstrates use of property caret-color: auto. We see input field styled with a default cursor color − <html> <head> <style> input { caret-color: auto; margin-bottom: 10px; padding: 5px; } </style> </head> <body> <input value=”Deafult cursor color.” size=”65″ /> </body> </html> CSS caret-color – transparent Value The following example demonstrates the caret-color: transparent property. Here input field is styled with a transparent cursor − <html> <head> <style> input { caret-color: transparent; margin-bottom: 10px; padding: 5px; } </style> </head> <body> <input value=”Transparent cursor.” size=”65″ /> </body> </html> CSS caret-color – currentcolor Value The following example demonstrates the caret-color: currentcolor. This sets the color of the cursor to the text color (blue) − <html> <head> <style> input { color: blue; border: 3px solid black; padding: 5px; caret-color: currentColor; } </style> </head> <body> <input value=”Deafult cursor color.” size=”65″ /> </body> </html> CSS caret-color – <color> Values The following example demonstartes how to use caret-color property for styling of input elements with different cursor colors − <html> <head> <style> input { display: block; margin-bottom: 10px; padding: 10px; } .box1 { caret-color: orange; } .box2 { caret-color: #5729e9; } .box3 { caret-color: rgb(241, 245, 20); } .box4 { caret-color: hsla(320, 77%, 58%, 0.8); } </style> </head> <body> <input class=”box1″ value=”The cursor is orange colored.” size=”65″ /> <input class=”box2″ value=”The cursor is blue colored.” size=”65″ /> <input class=”box3″ value=”The cursor is yellow colored.” size=”65″ /> <input class=”box4″ value=”The cursor is pink colored.” size=”65″ /> </body> </html> Print Page Previous Next Advertisements ”;
CSS – Web browser References
CSS – Browser Support Reference ”; Previous Next CSS3 Browser Support Reference Below list contained properties which are supported by specific web browsers − Properties Internet Explorer Fire fox Chrome Safari Opera align-content 11 28 21 webkit−7 12.1 align-self 11 20 21 webkit−7 12.1 CSS min/max-width/height 7 2-38 4-43 3.1-8.0 9-29 CSS 2.1 selectors 7-TP! 2-38 4-43 3.1-8.0 9-29 CSS3 Text-overflow 7-TP! 2-38 4-43 3.1-8.0 9-29 CSS inline-block 8-TP! 3-38 4-43 3.1-8.0 9-29 CSS Counters 8-TP! 2-38 4-43 3.1-8.0 9-29 CSS Table display 8-TP! 2-38 4-43 3.1-8.0 9-29 CSS3 Opacity 9-TP! 2-38 4-43 3.1-8.0 9-29 CSS3 selectors 9-TP! 3.5-38 4-43 3.1-8.0 9.5-29 CSS Generated content for pseudo-elements 9-TP! 2-38 4-43 3.1-8.0 9-29 CSS3 Media Queries 9-TP! 3.5-38 4-43 4-8.0 9.5-29 CSS position:fixed 7-TP! 2-38 4-43 3.1-8.0 9-29 CSS3 Colors 9-TP! 3-38 4-43 3.1-8.0 10-29 CSS3 Multiple backgrounds 9-TP! 3-38 4-43 3.1-8.0 10-29 @font-face Web fonts 9-TP! 3.5-38 4-43 3.2-8.0 10-29 getComputedStyle 9-TP! 4-38 11-43 5-8.0 10-29 rem (root em) units 9-TP! 3.6-38 6-43 5-8.0 11.6-29 CSS3 Border-radius (rounded corners) 9-TP! 4-38 5-43 5-8.0 10.5-29 CSS3 Box-shadow 9-TP! 4-38 10-43 5.1-8.0 10.5-29 SVG in CSS backgrounds 9-TP! 24-38 5-43 5.1-8.0 9-29 CSS3 Transitions 10-TP! 16-38 26-43 6.1-8.0 12.1-29 CSS Gradients 10-TP! 16-38 26-43 6.1-8.0 12.1-29 CSS pointer-events (for HTML) 11-TP! 3.6-38 4-43 3.1-8.1 9-15 CSS Repeating Gradients 10-TP! 16-38 26-43 6.1-8.0 12.1-29 TTF/OTF – TrueType and OpenType font support 9-TP! 3.5-38 4-43 3.1-8.0 10-29 CSS3 Animation 10-TP! 16-38 4-43 4-8.0 12.1-15 CSS outline 9-TP! 2-38 4-43 3.1-8.0 12.1-15 CSS3 Text-shadow 10-TP! 3.5-38 4-43 4-8.0 9.5-29 CSS3 Border images 11-TP! 15-38 16-43 6-8.0 11-15 CSS user-select: none 10-TP! 2-38 6-43 3.1-8.0 9-15 CSS background-position edge offsets 9-TP! 13-38 25-43 7-8.0 10.5-29 CSS3 3D Transforms 10-TP! 16-38 36-43 4-8.0 9-23 Improved kerning pairs & ligatures 5.5-TP! 3-38 4-43 5-8.0 9-15 CSS3 Background-image options 9-TP! 4-38 15‒43 7-8.0 10.5-29 MPEG-4/H.264 video format 9-TP! 4-38 4‒43 3.2-8.0 9-25 ::selection CSS pseudo-element 9-TP! 2-38 4‒43 3.1-8.0 9.5-29 CSS3 Overflow-wrap 5.5-TP! 3.5-38 23‒43 6.1-8.0 12.1-29 Flexible Box Layout Module 11-TP! 28-38 29‒43 6.1-8.0 12.1-29 CSS Appearance 10-TP! 15-38 4‒43 6.1-8.0 9-15 calc() as CSS unit value 9-TP! 19-38 26‒43 6.1-8.0 9-15 Viewport units: vw, vh, vmin, vmax 9-TP! 19-38 26‒43 6.1-8.0 9-15 CSS3 Cursors (original values) 9-TP! 4-38 5‒43 5-8.0 9-15 CSS3 tab-size 10-TP! 3.6-38 21‒43 6.1-8.0 10.6-15 Font feature settings 10-TP! 34-38 21‒43 3.1-8.0 9-15 CSS box-decoration-break 5.5-TP! 32-38 22‒43 6.1-8.0 11-15 Media Queries: resolution feature 9-TP! 16-38 29‒43 4-8.0 12.1-29 CSS Feature Queries 5.5-TP! 22-38 28‒43 3.1-8.0 12.1-29 CSS3 word-break 5.5-TP! 15-38 4‒43 3.1-8.0 9-15 CSS Canvas Drawings 5.5-TP! 2-38 4‒43 4-8.0 9-15 CSS text-stroke 5.5-TP! 4-38 4‒43 3.1-8.0 9-15 CSS Reflections 5.5-TP! 2-38 4‒43 4-8.0 9-15 Intrinsic & Extrinsic Sizing 5.5-TP! 4-38 22‒43 6.1-8.0 9-15 Font unicode-range subsetting 9-TP! 2-34 4‒35 3.1-8.0 9-23 Print Page Previous Next Advertisements ”;
CSS – Quick Guide
CSS – Quick Guide ”; Previous Next What is CSS? Superior styles to HTML − CSS has a much wider array of attributes than HTML, so you can give a far better look to your HTML page in comparison to HTML attributes. Multiple Device Compatibility − Style sheets allow content to be optimized for more than one type of device. By using the same HTML document, different versions of a website can be presented for handheld devices such as PDAs and cell phones or for printing. Global web standards − Now HTML attributes are being deprecated and it is being recommended to use CSS. So its a good idea to start using CSS in all the HTML pages to make them compatible to future browsers. Who Creates and Maintains CSS? CSS is created and maintained through a group of people within the W3C called the CSS Working Group. The CSS Working Group creates documents called specifications. When a specification has been discussed and officially ratified by the W3C members, it becomes a recommendation. These ratified specifications are called recommendations because the W3C has no control over the actual implementation of the language. Independent companies and organizations create that software. NOTE − The World Wide Web Consortium, or W3C is a group that makes recommendations about how the Internet works and how it should evolve. CSS Versions Cascading Style Sheets level 1 (CSS1) came out of W3C as a recommendation in December 1996. This version describes the CSS language as well as a simple visual formatting model for all the HTML tags. CSS2 became a W3C recommendation in May 1998 and builds on CSS1. This version adds support for media-specific style sheets e.g. printers and aural devices, downloadable fonts, element positioning and tables. CSS – Syntax selector { property: value } Example − You can define a table border as follows − table{ border :1px solid #C00; } Here table is a selector and border is a property and given value 1px solid #C00 is the value of that property. You can define selectors in various simple ways based on your comfort. Let me put these selectors one by one. The Type Selectors This is the same selector we have seen above. Again, one more example to give a color to all level 1 headings − h1 { color: #36CFFF; } The Universal Selectors Rather than selecting elements of a specific type, the universal selector quite simply matches the name of any element type − * { color: #000000; } This rule renders the content of every element in our document in black. The Descendant Selectors Suppose you want to apply a style rule to a particular element only when it lies inside a particular element. As given in the following example, style rule will apply to <em> element only when it lies inside <ul> tag. ul em { color: #000000; } The Class Selectors You can define style rules based on the class attribute of the elements. All the elements having that class will be formatted according to the defined rule. .black { color: #000000; } This rule renders the content in black for every element with class attribute set to black in our document. You can make it a bit more particular. For example − h1.black { color: #000000; } This rule renders the content in black for only <h1> elements with class attribute set to black. You can apply more than one class selectors to given element. Consider the following example − <p class = “center bold”> This para will be styled by the classes center and bold. </p> The ID Selectors You can define style rules based on the id attribute of the elements. All the elements having that id will be formatted according to the defined rule. #black { color: #000000; } This rule renders the content in black for every element with id attribute set to black in our document. You can make it a bit more particular. For example − h1#black { color: #000000; } This rule renders the content in black for only <h1> elements with id attribute set to black. The true power of id selectors is when they are used as the foundation for descendant selectors, For example − #black h2 { color: #000000; } In this example all level 2 headings will be displayed in black color when those headings will lie with in tags having id attribute set to black. The Child Selectors You have seen the descendant selectors. There is one more type of selector, which is very similar to descendants but have different functionality. Consider the following example − body > p { color: #000000; } This rule will render all the paragraphs in black if they are direct child of <body> element. Other paragraphs put inside other elements like <div> or <td> would not have any effect of this rule. The Attribute Selectors You can also apply styles to HTML elements with particular attributes. The style rule below will match all the input elements having a type attribute with a value of text − input[type = “text”] { color: #000000; } The advantage to this method is that the <input type = “submit” /> element is unaffected, and the color applied only to the desired text fields. There are following rules applied to attribute selector. p[lang] − Selects all paragraph elements with a lang attribute. p[lang=”fr”] − Selects all paragraph elements whose lang attribute has a value of exactly “fr”. p[lang~=”fr”] − Selects all paragraph elements whose lang attribute contains the word “fr”. p[lang|=”en”] − Selects all paragraph elements whose lang attribute contains values that are exactly “en”, or begin with “en-“. Multiple Style Rules You may need to define multiple style rules for a single element. You can define these rules to combine multiple properties and corresponding values into a single block as defined in the following example − h1 { color: #36C; font-weight: normal; letter-spacing: .4em; margin-bottom: 1em; text-transform: lowercase;
CSS – Questions and Answers
CSS Questions and Answers ”; Previous Next CSS Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews. This section provides a useful collection of sample Interview Questions and Multiple Choice Questions (MCQs) and their answers with appropriate explanations. Sr.No. Question/Answers Type 1 CSS Interview Questions This section provides a huge collection of CSS Interview Questions with their answers hidden in a box to challenge you to have a go at them before discovering the correct answer. 2 CSS Online Quiz This section provides a great collection of CSS Multiple Choice Questions (MCQs) on a single page along with their correct answers and explanation. If you select the right option, it turns green; else red. 3 CSS Online Test If you are preparing to appear for a Java and CSS related certification exam, then this section is a must for you. This section simulates a real online test along with a given timer which challenges you to complete the test within a given time-frame. Finally you can check your overall test score and how you fared among millions of other candidates who attended this online test. 4 CSS Mock Test This section provides various mock tests that you can download at your local machine and solve offline. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself. Print Page Previous Next Advertisements ”;
CSS RWD – Introduction
CSS RWD Introduction ”; Previous Next Responsive Web Design (RWD) is a web-designing and development approach that makes the web pages render well and correctly on various devices with different screen sizes and resolutions. The motive of responsive web design is to ensure that the user experience is consistent and optimized regardless of whether the website is viewed on a mobile device, a desktop computer, laptop, or a tablet. RWD Structure The following figure describes the structure of responsive web designing, where the same page can be viewed optimally on different kinds of devices of varied sizes and resolutions. Cascading Style Sheets (CSS) plays a crucial role in responsive web designing. Following are few of the concepts and techniques that are used in CSS for responsive web designing: Media Queries: Media queries allow you to apply CSS rules based on characteristics of the device, such as its screen width, height, or even its orientation (landscape or portrait). By using media queries, you can define different styles for different devices. Flexible Grid Layouts: Instead of using fixed-width layouts, responsive designs often use flexible grid layouts. CSS frameworks like Bootstrap provide grid systems that automatically adjust the layout based on the screen size. Flexible Images and Media: Images and other media elements, such as videos, can be made responsive by using the max-width: 100% property. This ensures that images scale down proportionally within their parent containers. Viewport Meta Tag: The viewport meta tag is used in the HTML <head> to control the viewport behavior and scale on mobile devices. It is crucial for ensuring proper rendering on various screen sizes. Print Page Previous Next Advertisements ”;
CSS – Pseudo Classes
CSS – Pseudo Classes ”; Previous Next Pseudo-classes in CSS are used to select and style elements based on their state or position within the document tree, without the need for adding extra classes or JavaScript. For Example, pseudo-class can be used to change color of element when mouse is hovered over it or Click a button to change color. Example iframe for Pseudo-Class property Hover over me! Click me! Table of Contents What is Pseudo-class? Pseudo-Class Hover Pseudo-Class Active Pseudo-Class Focus Pseudo-Class nth Child Pseudo-Class First-Child Pseudo-Class Last-Child Pseudo-Class Lang Pseudo-Class not List of CSS Pseudo Classes What is Pseudo-class? Pseudo-classes often used along with CSS Selectors by inserting a colon (:) after selector. For example a : hover{}, Here selector `a` will selects all the anchor tags in document. A functional pseudo-class contains a pair of parentheses to define the arguments. For example: :lang(en). The element to which a pseudo-class is attached, is termed as an anchor element. For example: button:hover, a:focus, etc. Here button and a elements are called the anchor elements. Pseudo-classes apply style to an element as per the content of the document tree. Pseudo-classes also apply a style to an element in relation to the external factors, such as history of the navigation of the element (:visited), status of the content (:checked), or position of mouse (:hover) Syntax selector:pseudo-class { property: value; } Pseudo-Class Hover In CSS, pseudo-class :hover is used to specify mouse hovering state of an element. This used to style element while users mouse passes through an element in document. Syntax tag:hover { property: value; } Example Following example shows how this can be applied. <!DOCTYPE html> <html lang=”en”> <head> <style> a{ background-color: lightgrey; padding: 10px; } a:hover { color: red; } div{ padding: 10px; border: solid 3px; background-color: aqua; } div:hover{ background-color: lightgreen; } </style> </head> <body> <h3>Anchor Tag Hovering</h3> <a href=”#”>Hover over me!</a> <h3>Div Hovering</h3> <div>Hover me</div> </body> </html> Pseudo-Class Active The pseudo-class :active will apply style to an element when user activates the element by clicking or tapping on it. This is most commonly used with interactive elements like button and anchor tag, but all the HTML elements can use this pseudo-class. Syntax tag:active { property: value; } Example Here is an example that shows different usage of pseudo-class active. <!DOCTYPE html> <html lang=”en”> <head> <style> a, p, li { color: black; background-color: lightgrey; padding: 7px; border: 3px solid; } a:active { color: red; } p:active { background-color: gold; } li:active { background-color: darkred; } </style> </head> <body> <h2>Active Pseudo-Class Example</h2> <h3>For Button:</h3> <a href=”#”>Click Me</a> <h3>For paragraph:</h3> <p>Click me to see the effect.</p> <h3>For list:</h3> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> </body> </html> Pseudo-Class Focus The pseudo-class :focus will apply style to an element when user focused an element like input tag by clicking on it. Before typing text in input element users has to click in input area to enable cursor, this is called focusing. Syntax tag:focus { property: value; } Example This example will show how to use pseudo-class focus in HTML. <!DOCTYPE html> <html lang=”en”> <head> <style> input{ padding:3px; } input:focus { border-color: green; background-color: lightgrey; } </style> </head> <body> <h2>Pseudo-Class focus Example</h2> <h3>Focus on input text</h3> <input type=”text” placeholder=”Type Something!”> </body> </html> Pseudo-Class nth Child The pseudo-class :nth-child(n) will apply style to any specified direct child of an element. Syntax tag:nth-child(number/ expression / odd / even) { property: value; } The pseudo-class nth-child can take number, mathematical expression or values like odd, even as parameter. To know about values associated with nth child visit our tutorial on Pseudo Class nth-child(). <!DOCTYPE html> <html lang=”en”> <head> <style> div{ border: 2px solid; margin: 7px; padding: 2px; } /* Apply Style to 2nd child of div */ div:nth-child(2){ background-color:red; } /* Apply Style to all odd children of li */ li:nth-child(odd) { background-color: lightgray; } /* Apply Style to all even children of li */ li:nth-child(even) { background-color: lightblue; } </style> </head> <body> <h2>Pseudo-Class nth-child</h2> <h3>2nd child of Div</h3> <div> <div>1st div</div> <div>2nd div</div> <div>3rd div</div> <div>4th div</div> </div> <h3>Selecting odd and even children</h3> <ul> <li>First item</li> <li>Second item</li> <li>Third item</li> <li>forth item</li> <li>Third item</li> <li>fifth item</li> </ul> </body> </html> Pseudo-Class First-Child The pseudo-class first-child used to select first direct child element. Syntax tag:first-child { property: value; } Example Following example show how to use first-child pseudo-class in HTML. <!DOCTYPE html> <html lang=”en”> <head> <style> div{ border: solid; } /* Selects all first child paragraphs */ p:first-child { color: blue; } </style> </head> <body> <p> This paragraph is first child of body element, will be blue. </p> <p>This paragraph will not be affected.</p> <p>Another paragraph that won”t be affected.</p> <div> <p> This paragraph is first child of div element will be blue. </p> <p>This paragraph will not be affected.</p> <p>Another paragraph that won”t be affected.</p> </div> </body> </html> Pseudo-Class Last-Child The pseudo-class last-child used to select last direct child element. Syntax tag:last-child { property: value; } Example Following example show how to use last-child pseudo-class in HTML. <!DOCTYPE html> <html lang=”en”> <head> <style> div{ border: solid; } /*
CSS – Custom Properties
CSS – Custom Properties ”; Previous Next Custom properties use names that start with —, such as –color-name. These properties can store values, which can then be used in other elements using the var() function. Custom properties are specific to elements, and their values follow the cascading rules, the value of a custom property is determined by the cascading algorithm. Possible Values <declaration-value> − This value can be any combination of tokens, but it must not include certain disallowed tokens. It specifies what a valid declaration can have as its value. Applies To All the HTML elements. Syntax –keywordValue: right; –colorValue: #e74c3c; –complexValue: 5px 10px rgb(238, 50, 17); When defining custom properties with “–“, remember they are case sensitive. “–my-color” and “–My-color” will not have the same value, they are separate variables. CSS Custom Properties – Commas in Values The following syntax shows how to use multiple values using commas. The transform: scale(var(–scale, 1.1, 1.5)) property defines the first comma, which separates the fallback, and the second comma, which is a value − button { transform: scale(var(–scale, 1.1, 1.5)); } CSS Custom Properties The following example demonstrates the use of custom properties − <html> <head> <style> :root { –red-color: red; –green-color: rgb(125, 226, 31); } div { width: 200px; height: 100px; margin: 10px; } .box1 { background-color: var(–green-color); color: var(–red-color); } .box2 { background-color: var(–red-color); color: var(–green-color); } .box3 { –pink-color: rgb(247, 30, 193); } .box3 p { color: var(–pink-color); } </style> </head> <body> <div class=”box1″> Green Background, Red Text </div> <div class=”box2″> Red Background, Green Text </div> <div class=”box3″> <p>Pink Text</p> </div> </body> </html> CSS Custom Properties – Setting Value The following example demonstrates that custom property”s value can be set using another custom property − <html> <head> <style> html { –red-color: #e92424; –green-color: #2c1fdd; –yellow-color: #f6f867; –back: var(–yellow-color); –para: var(–green-color); –border: var(–red-color); } div { width: 200px; height: 150px; padding: 10px; background-color: var(–back); border: 3px solid var(–border); } h3 { color: var(–green-color); text-align: center; } p { color: var(–para); } </style> </head> <body> <div> <h3>Tutorialspoint</h3> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text.</p> </div> </body> </html> CSS Custom Properties – Splitting Colors The following example demonstrates that when you hover over the box, the background color is changed by modifying the values of –h, –s, –l, and –a − <html> <head> <style> .box { width: 150px; width: 150px; padding: 10px; –h: 0; /* hue */ –s: 70%; /* saturation */ –l: 50%; /* lightness */ –a: 1; /* alpha */ background-color: hsl(var(–h) var(–s) var(–l) / var(–a)); color: white; } .box:hover { –l: 75%; } .box:focus { –s: 75%; } .box[disabled] { –s: 0%; –a: 0.5; } </style> </head> <body> <div class=”box”> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text. </div> </body> </html> CSS Custom Properties – Shadow The following example demonstrates box shadow effect with –shadow value. The box shadow is initially 2px, but when you hover over it, the shadow increases to 10px − <html> <head> <style> .box { width: 150px; width: 150px; padding: 10px; margin: 30px; –shadow: 2px; background-color: aqua; box-shadow: 0 0 20px var(–shadow) red; } .box:hover { –shadow: 10px; } </style> </head> <body> <div class=”box”> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text. </div> </body> </html> CSS Custom Properties – Gradients The following example demonstrates that the box with gradient background transitioning from green to yellow to red. The gradient angle is initially 90deg, but when you hover over it, gradient angle changes to 180deg − <html> <head> <style> .box { width: 150px; width: 150px; padding: 10px; margin: 30px; –gradient-angle: 90deg; background: linear-gradient(var(–gradient-angle), green, yellow, red); } .box:hover { –gradient-angle: 180deg; } </style> </head> <body> <div class=”box”> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text. </div> </body> </html> CSS Custom Properties – Grid The following example demonstrates the grid layout where the width of column changes based on the the screen width. The value of the –boundary is initially 30px, but when you resize the browser window, the –boundary value changes to the 40% of the container width − <html> <head> <style> .box { background-color: lightcoral; display: grid; –boundary: 30px; grid-template-columns: var(–boundary) 1fr var(–boundary); } @media (max-width: 800px) { .box { –boundary: 40%; } } </style> </head> <body> <div class=”box”> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text. </div> </body> </html> CSS Custom Properties – Transforms The following example demonstrates the transform effect using custom properties. When you hover over a button, it scales down to 80% of its original size, and when you click it, it moves down 3px − <html> <head> <style> button { transform: var(–scale-button, scale(1)) var(–translate-button, translate(0)); padding: 10px; background-color: yellow; } button:active { –translate-button: translate(0, 3px); } button:hover { –scale-button: scale(0.8); } </style> </head> <body> <button> Tutorialspoint </button> </body> </html> CSS Custom Properties – Concatenation of Unit Types The following example demonstrates how to use CSS custom properties to dynamically set the font size. The calc() function calculates the size by multiplying the custom properties –size-val and –pixel-values − <html> <head> <style> html { –size-val: 24; –unit-val: px; font-size: var(–size-val) + var(–unit-val); font-size: calc(var(–size-val) * 1px); –pixel-values: 1px; font-size: calc(var(–size-val) * var(–pixel-values)); } .box { width: 200px; height: 150px; background-color: yellowgreen; } </style>
CSS – Useful Resources
CSS – Useful Resources ”; Previous Next The following resources contain additional information on CSS. Please use them to get more in-depth knowledge on this topic. Useful Video Courses Full Stack Web Development – HTML, CSS, JavaScript, PHP, ELIXIR 55 Lectures 6 hours Pranjal Srivastava, Harshit Srivastava More Detail Complete HTML and CSS Masterclass For Beginners (Complete Bootcamp Course) 51 Lectures 7 hours Emenwa Global, Ejike IfeanyiChukwu More Detail CSS Bootcamp – Master CSS (Including CSS Grid/Flexbox) Most Popular 88 Lectures 11 hours Code And Create More Detail Learn Web Development with HTML, CSS , Javascript, Typescript, and Vue 32 Lectures 1 hours James Coonce More Detail Learn Web Development with HTML, CSS , Javascript , Typescript, and React 37 Lectures 1.5 hours James Coonce More Detail Learn Web Development with HTML, CSS , Javascript ,Typescript, and Angular 30 Lectures 58 mins James Coonce More Detail Print Page Previous Next Advertisements ”;