CSS – Transition

CSS – transition Property ”; Previous Next CSS transition property allows you to animate changes in an element”s style properties over a specified duration. They provide a simple and efficient way to add animations to web elements without the need for complex JavaScript code or external libraries. CSS transition property is a shorthand property for transition-property transition-duration transition-timing-function transition-delay transition-behavior (This property is on an experimental basis and may not be supported). Possible Values <length> − A specific length value such as pixels (px), centimeters (cm), inches (in), etc. Applies to All elements, ::before and ::after pseudo-elements. Syntax transition: margin-right 4s; transition: margin-right 4s 1s; transition: margin-right 4s ease-in-out; transition: margin-right 4s ease-in-out 1s; transition: display 4s allow-discrete; transition: margin-right 4s, color 1s; The value for the transition property is defined as one of the following: The none value indicates that there will be no transitions on this element. This is the default value. Commas are used to separate one or more single-property transitions. A single-property transition specifies the transition for one specific property or all properties. This includes: A zero or one value indicating the property or properties for which the transition should be applied. This can be specified as: A <custom-ident> representing a single property. The all value in transitions indicates that the transition will be applied to all attributes that change when the element changes its state If no value is specified, all value will be assumed, and the transition will apply to all changing properties. Specify zero or one <easing-function> value indicating the easing function to be used. Specify zero, one, or two <time> values for transition properties. The first parsed-time value is applied to transition-duration, and the second is assigned to transition-delay. If a property has discrete animation behaviour, a zero or one value indicates whether to initiate transitions. If the value is present, it can be either allow-discrete or normal keyword. CSS transition – With Two Values The following example demonstrates that transition is applied to the padding property with a duration of 2s. When you hover over the box, padding increases to 15px and the background color changes to greenyellow − <html> <head> <style> .box { font-size: 14px; width: 100px; padding: 5px; transition: padding 2s; background-color: lightskyblue; } .box:hover { background-color: greenyellow; padding: 15px; } </style> </head> <body> <div class=”box”>Hover over me</div> </body> </html> CSS transition – delay Value The following example demonstrates that transition is applied to the padding property. The transition takes 2s to complete, and it starts after a delay of 0.5s − <html> <head> <style> .box { font-size: 14px; width: 100px; padding: 5px; transition: padding 2s .5s; background-color: lightskyblue; } .box:hover { background-color: greenyellow; padding: 15px; } </style> </head> <body> <div class=”box”>Hover over me</div> </body> </html> CSS transition – easing Function The following example demonstrates that transition is applied to the background-color property. When you hover over the box, background color changes to green-yellow, starting a smooth color transition with an ease-in-out timing function over the 4s duration − <html> <head> <style> .box { font-size: 14px; width: 100px; padding: 15px; transition: background-color 4s ease-in-out; background-color: lightskyblue; } .box:hover { background-color: greenyellow; } </style> </head> <body> <div class=”box”>Hover over me</div> </body> </html> CSS transition – easing Function and delay The following example demonstrates that transition is applied to the padding property. When you hover over the box, background color changes to green-yellow and padding increases to 15px, starting a smooth transition over the duration of 4s with an ease-in-out timing function and a delay of 0.7s − <html> <head> <style> .box { font-size: 14px; width: 100px; padding: 5px; transition: padding 4s ease-in-out 0.7s; background-color: lightskyblue; } .box:hover { background-color: greenyellow; padding: 15px; } </style> </head> <body> <div class=”box”>Hover over me</div> </body> </html> CSS transition – behavior Value The following example demonstrates that transition is applied to the background-color property. When you hover over the box, background color changes to green-yellow, starting a smooth transition over the duration of 5s using the allow-discrete timing function − <html> <head> <style> .box { font-size: 14px; width: 100px; padding: 10px; transition: background-color 5s allow-discrete; background-color: lightskyblue; } .box:hover { background-color: greenyellow; } </style> </head> <body> <div class=”box”>Hover over me</div> </body> </html> CSS transition – Applied To Two Properties The following example demonstrates that transition will be applied on text color in 2s and on margin-left in 4s. The text color will transition in 2s, while the left margin will take 4s − <html> <head> <style> .box { font-size: 14px; width: 100px; padding: 10px; transition: color 2s, margin-left 4s; background-color: lightskyblue; } .box:hover { color: red; margin-left: 70px; } </style> </head> <body> <div class=”box”>Hover over me</div> </body> </html> CSS transition – Related Properties Following is the list of CSS properties related to transition: property value transition-delay Determines the amount of time to wait before starting a transition effect when a property”s value changes. transition-duration Determines amount of time that a transition animation should take to complete. transition-property Specifies which CSS properties should have a transition effect applied. transition-timing-function Determines which intermediate values are generated for CSS properties affected by a transition effect. Print Page Previous Next Advertisements ”;

CSS – Discussion

Discuss CSS ”; Previous Next CSS is used to control the style of a web document in a simple and easy way. CSS is the acronym for “Cascading Style Sheet”. This tutorial covers both the versions CSS1,CSS2 and CSS3, and gives a complete understanding of CSS, starting from its basics to advanced concepts. Print Page Previous Next Advertisements ”;

CSS – Box Decoration Break

CSS – box-decoration-break ”; Previous Next CSS box-decoration-break property specifies how the background, padding, border, and border-radius of an element should behave when the content is broken across multiple lines or columns. It controls whether these properties should be continuous or fragmented across the line breaks. This property will affect the appearance of the following properties: background border border-image box-shadow clip-path margin padding Possible Values slice − This is the default value. It means that the padding, border, and background of the element will be rendered as if the content were not broken, resulting in continuous rendering across line breaks. clone − Each box fragment is rendered individually with its defined border, padding, and margin wrapping it. The border-radius, , and box-shadow are applied to each fragment separately. When background-repeat is set to no-repeat, the background picture may repeat for each fragment individually. Applies to All elements. Syntax box-decoration-break = slice | clone; CSS box-decoration – slice Value The following example demonstrates the box-decoration-break: slice property slices between boxes when broken across multiple lines − <html> <head> <style> .box { background-color: lightpink; border: 5px solid green; padding: 5px; border-radius: 15px; line-height: 3; -webkit-box-decoration-break: slice; box-decoration-break: slice; } </style> </head> <body> <span class=”box”>CSS<br>box-decoration-break – <br> slice<br>Value</span> </body> </html> CSS box-decoration – clone Value The following example demonstrates the box-decoration-break: clone property controls how a box displays when it is broken across multiple lines or columns − <html> <head> <style> .box { background-color: lightpink; border: 5px solid green; padding: 5px; border-radius: 15px; line-height: 3; -webkit-box-decoration-break: clone; box-decoration-break: clone; } </style> </head> <body> <span class=”box”>CSS<br>box-decoration-break – <br> clone<br>Value</span> </body> </html> CSS box-decoration – Fragmentation With Multi-column Layouts The following example demonstrates a block element with multi-column layouts using box-decoration-break property with different values, such as slice and clone − <html> <head> <style> span { display: block; background: lightpink; border: 5px solid green; padding: 5px; border-radius: 20px; margin-left: 10px; line-height: 2; } .clone-box { -webkit-box-decoration-break: clone; -ms-box-decoration-break: clone; -o-box-decoration-break: clone; box-decoration-break: clone; } .box { -webkit-columns: 3; -moz-columns: 3; -ms-columns: 3; -o-columns: 3; columns: 3; } div { width: 63em; } </style> </head> <body> <h3>Without fragmentation</h2> <div > <span>CSS<br>box-decoration-break – <br> clone Value</span> </div> <br> <h3>box-decoration-break: slice</h2> <div class=”box”> <span>CSS<br>box-decoration-break – <br> clone Value</span> </div> <h3>box-decoration-break: clone</h3> <div class=”box”> <span class=”clone-box”>CSS<br>box-decoration-break – <br> clone Value</span> </div> </body> </html> Print Page Previous Next Advertisements ”;

CSS RWD – Images

CSS RWD Images ”; Previous Next Responsive images are important for the web development, as they ensure that the images are appropriately sized based on the device size and resolution. The responsive images improve the page loading speed and also reduce the time to load it. When an image is uploaded to a website, it has its default width and height; but these dimensions can be changed using CSS. In order to make an image responsive and fluid, you need to provide a new value to its width property, to which the height of the image gets adjusted automatically. For better adaptability, you should always use relative units for the width property such as percentage, instead of absolute values, such as pixels. Absolute values restrict the image getting responsive. CSS RWD Images – width Property To make an image responsive and fluid, the width property of the image is set to a percentage value, along with height property set to auto. <html> <head> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <style> img { width: 100%; height: auto; } </style> </head> <body> <p>Resize the browser window to see how the image will resize.</p> <img src=”images/pink-flower.jpg”> </body> </html> CSS RWD Images – max-width Property To make an image responsive and fluid, the max-width property of the image is set to a 100%, which will let the image get scaled down to the extent it is set, but will never scale up more than its original size. <html> <head> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <style> img { max-width: 100%; height: auto; } </style> </head> <body> <p>Resize the browser window to see how the size of the image changes.</p> <img src=”images/pink-flower.jpg”> </body> </html> CSS RWD Images – Within a grid The following example demonstrates the use of a responsive image within a grid column. Based on the max-width value of the image, the image gets scaled down as per the screen size. <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; } ul { list-style-type: none; } li { background-color: aqua; padding: 5px; border: 1px solid black; margin: 5px; } img { max-width: 100%; height: auto; } </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”> <h1>Responsive Images</h1> <p>Responsive images are important for the web development, as they ensure that the images are appropriately sized based on the device size and resolution. The responsive images improve the page loading speed and also reduce the time to load it.</p> <img src=”images/scenery2.jpg”> <p>Resize the browser window to see how the content gets responsive to the resizing.</p> </div> </body> </html> CSS RWD Images – Using Background Images The background images can also be resized or scaled based on the property background-size: contain. This property will scale the image, and tries to fit the content area. The aspect ratio of the image will be maintained. <html> <head> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <style> div { width: 100%; height: 400px; background-image: url(images/pink-flower.jpg); background-repeat: no-repeat; background-size: contain; border: 5px solid black; background-color: antiquewhite; } </style> </head> <body> <h1>Responsive Web Design – Images</h1> <div></div> </body> </html> The background image can also be resized or scaled based on the property background-size: cover. This property will scale the image such that it covers the entire content area. The aspect ratio of the image will be maintained, but some parts of the background image may be clipped. <html> <head> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <style> div { width: 100%; height: 80%; background-image: url(images/pink-flower.jpg); background-repeat: no-repeat; background-size: cover; border: 5px solid red; background-color: antiquewhite; } </style> </head> <body> <h1>Responsive Web Design – Images</h1> <div></div> </body> </html> The background image can also be resized or scaled based on the property background-size: 100% 100%. This value will make the image get stretched to cover the entire content area. <html> <head> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <style> div { width: 100%; height: 80%; background-image: url(images/pink-flower.jpg); background-repeat: no-repeat; background-size: 100% 100%; border: 5px solid red; background-color: antiquewhite; } </style> </head> <body> <h1>Responsive Web Design – Images</h1> <div></div> </body> </html> CSS RWD Images – Using Media Query When you need an image to be displayed in different sizes on different devices, you need to use a media query. The example below shows an image whose width is 50% for one kind of screen, but in order to make it full-size for a mobile device a media query will be used. <html> <head> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <style> /* For width smaller than 400px: */ body { background-repeat: no-repeat; background-image: url(images/orange-flower.jpg); } /* For width 400px and larger: */ @media only screen and (min-width: 700px) { body { background-image: url(images/pink-flower.jpg); background-size: cover; } } </style> </head> <body> <p style=”margin-top:360px;color:white;”>Resize the browser width and the background image will change at 400px.</p> </body> </html> Print Page Previous Next Advertisements ”;

CSS – Border Images

CSS – Border Image ”; Previous Next For brevity purpose, there is a shorthand for setting up of border image, i.e., border-image. The values passed to shorthand border-image are separated using the solidus symbol (/). The values should be listed in a specific order, which is slice, then width and last is offset. Applies to All HTML elements, except internal table elements. Syntax border-image: url(”URL”), 40% 25% 20% fill / 12px 5px / 5px space; Note: You can also declare the property border-image with just one value i.e., URL and rest of the values will be default. Example Let us see an example: <html> <head> <style> .box { width: 200px; height: 200px; border: 20px solid; border-image: url(images/border.png) 30 round; } </style> </head> <body> <div class=”box”></div> </body> </html> Overview The border-image property can be applied to any element, except for the internal table elements (th,tr,td), when border-collapse is set to collapse. Only required property for border-image shorthand property is, border-image-source, rest other properties are optional. Following are the properties of border-image shorthand, in their order: border-image-source: Specifies the source of border-image. Can be a URL, CSS gradient or inline SVG. border-image-slice: Allows the slicing up of image by the browser. border-image-width: Sets the width of the border image. border-image-outset: Pushes the border image outside, beyond the border box. border-image-repeat: Repeats the image specified along the sides of the border, until the whole length and width is filled. border-image-source The border-image-source property specifies the source of an image to be passed as a border to an element. Syntax border: 10px solid; border-image-source: url(”URL”); border-image-slice The image specified using the property border-image-source can be sliced using the property border-image-slice. As the name suggests, this property is used to slice up an image. It divides the image in 9 regions, with 4 corners, 4 edges and a middle region. The following diagram demonstrates function of border-image-slice property: Note: Offset for border-image-slice can be provided in terms of percentage and length units. But, percentages are highly recommended. Refer the following syntax for example: border: 20px solid; border-image-source: url(”URL”); border-image-slice: 25%; border-image-width To specify the width of the image to be set as a border, you can use the property border-image-width. Syntax border: 20px solid; border-image-source: url(”URL”); border-image-width: 15px; border-image-slice: 33.33%; border-image-outset In order to avoid the overlapping of the image borders and the content, you can use the property border-image-outset. This property pushes the border image outside, beyond the border box. Syntax border: 20px solid; padding: 1em; border-image-source: url(”URL”); border-image-width: 1; border-image-slice: 10; border-image-outset: 8px; border-image-repeat By default the border image gets stretched along the sides, but this can be changed, using the property border-image-repeat. This property repeats the image specified along the sides of the border, until the whole length and width is not filled. Syntax border: 20px solid; padding: 1em; border-image-source: url(”URL”); border-image-repeat: repeat; It can also take the value as round, apart from stretch and repeat. CSS Gradient Border Images CSS gradients can also be used to set the border of an element. Three types of gradients are supported: linear, radial and conic. Linear Gradient A linear gradient is used to set a smooth transition between two or more colors along a straight line and the same can be used as a border around an element. Example Here is an example: <html> <head> <style> img { height: 300px; width: 300px; } img.with-linear-gradient { border-style: solid; border-width: 20px; border-image: linear-gradient(45deg, rgb(15, 64, 161), rgb(228, 6, 17)) 1; } </style> </head> <body> <div> <img class=”with-linear-gradient” src=”images/orange-flower.jpg” alt=”linear-gradient”/> </div> </body> </html> Radial Gradient A radial gradient is used to set a progressive transition between two or more colors that radiate from its origin. Example Here is an example: <html> <head> <style> img { height: 300px; width: 300px; } img.with-radial-gradient { border-style: solid; border-width: 10px; border-image: radial-gradient(rgb(58, 61, 60), rgb(47, 227, 221)) 1; } </style> </head> <body> <div> <img class=”with-radial-gradient” src=”images/orange-flower.jpg” alt=”radial-gradient”/> </div> </body> </html> Conic Gradient A conic gradient is helpful in creating an image consisting of color transitions rotated around a center point, rather than radiating from the center. Example Here is an example: <html> <head> <style> img { height: 300px; width: 300px; } img.with-conic-gradient { border-style: solid; border-width: 15px; border-image: conic-gradient(red, yellow, green, aqua, blue, pink, red) 1; } </style> </head> <body> <div> <img class=”with-conic-gradient” src=”images/orange-flower.jpg” alt=”conic-gradient”/> </div> </body> </html> All the properties related to border-image are listed in the table below: Sr.No. Property Description 1 border-image A shorthand property for setting border image. 2 border-image-outset Sets the image outset i.e how much the border image area extends beyond the border box. 3 border-image-repeat Determines whether the border image should be repeated, rounded, spaced or stretched. 4 border-image-source Sets the source/path of an image to be passed as a border to an element. 5 border-image-slice Shows how to slice up an image in a border. 6 border-image-width Sets the width of the image to be set as a border. Print Page Previous Next Advertisements ”;

CSS – Specificity

CSS – Specificity ”; Previous Next Specificity in CSS is a calculation or algorithm that is understood and used by the browser to determine the CSS declaration that needs to be applied on an element. It chooses the selector with the highest specificity value and applies the styling accordingly on any HTML element. For instance, if two or more CSS rules are specified on an HTML element, the selector with highest specificity value, will be eventually applied on that element. CSS Specificity – Selector Weight Categories Specificity of any selector is calculated based on the weightage given it. There are four different categories which broadly defines the specificity level of any selector. The categories are: Inline style Inline style declaration is given the highest priority. Refer the syntax given below: <h1 style=”color: blue;”>Example</h1> Id Id selector is given higher priority than any other selector, but lower than the inline style. Example – #sample-demo. Refer the syntax given below: <style> #sample-demo {color: blue;} </style> <h1 id=”sample-demo”>Example</h1> Class, pseudo-class, attribute selector Class, pseudo-class and attribute selector is given lower priority than id, but higher than the element and pseudo-element selector(s). Example – .sample-demo, :hover, [href]. Refer the syntax given below: <style> .sample-demo {color: blue;} </style> <h1 class=”sample-demo”>Example</h1> Element, pseudo-element The lowest priority is given to the elements and pseudo-elements. Example: h1, ::after, etc. <style> h1 {color: blue;} </style> <h1>Example</h1> CSS Specificity – Score Of Each Selector Type Following list shows the score earned by each selector and based on these scores, you can calculate a selector”s overall specificity. No value: Universal selector (*), :where() pseudo-class, combinators (+, >, ~, _, ||), nesting combinator (&) has no specificity and scores 0 point. Element / Pseudo-element selector: It gets 1 point of specificity. Class, pseudo-class, or attribute selector: It gets 10 points of specificity. Id selector: It gets 100 points of specificity. Inline style attribute: It gets 1000 points of specificity. !important rule: The rule gets 10000 points of specificity. If an !important rule is applied to any CSS property,it takes the precedence over all other properties. CSS Specificity – Exception Cases The pseudo-classes such as, the matches-any :is(), the relational :has(), and the negation :not(), are not considered in the specificity calcultaion, but the parameters passed to them are part of the specificity algorithm. Refer the code block given below: h1 { /* point of element */ } :is(h1) { /* point of element */ } h2:nth-last-of-type(n + 2) { /* point of pseudo-class and element */ } h2:has(~ h2) { /* point of element */ } div.outer p { /* point of class and element */ } div:not(.inner) p { /* point of class and element */ } In the above CSS code block, the specificity weight provided by the :is(), :has() and :not() pseudo-classes is the value of the selector parameter, not of the pseudo-class. CSS Specificity – Handling Issues Following are some tips and tricks to handle the specificity issues in your code: Use of cascade layers and low weight specificity, instead of !important, so that the styles can be easily overwritten. Selectors can be made more specific with or without adding specificity. By reducing the ID specificity, where the id of an element can be used as an attribute selector rather than an id selector, makes an element more specific without adding extra specificity. By duplicating id, class, pseudo-class or attribute selectors inside a compound selector, increases specificity along with easy control over the particular section. Enabling one set of styles to take precedence over other set is by using cascade layers. For example, when two selectors from different layers match the same element, the origin and importance take precedence. The specificity of that selector in the losing stylesheet becomes irrelevant. CSS Specificity – Points To Remember Following are some important points to remember in regard to specificity: Specificity is applicable only when the same element is targeted by multiple declarations in the same origin or cascade layer. In case matching selectors are in different origins, the cascade decides which declaration takes precedence. Scoping proximity is calculated, when two selectors are in the same cascade layer and origin have the same specificity. In such a case the ruleset with the lowest scoping proximity takes precedence. Source order comes into picture, when the scope proximity is also same for both selectors. When everything is equal, the last selector wins. Regardless of the specificity of the inherited rule, the styles of a directly targeted element will always take precedence over the inherited styles. In the document tree, proximity of elements, has no effect on the specificity. CSS Specificity – Equal Specificity (Latest Wins) Following example demonstrates that when two selectors have the same specificity, the latest CSS style or rule gets applied. Here the selector is h1 element, which has same specificity, and is given two styling declarations, but the output shows that the last rule is applied and the heading text has background color as red and text color as white. <html> <head> <style> h1 {background-color: yellow; color: black; } h1 {background-color: red; color: white; } </style> </head> <body> <h1>Same Specificity</h1> </body> </html> CSS Specificity – Specificity Hierarchy (Inline Style) Following example demonstrates the order of specificity based on the type of selector. Inline style takes over all other declarations. <html> <head> <style> h1 {background-color: yellow; color: black; } #id-heading-color { background-color: red; color: white; } .cl-heading-color { background-color: aquamarine; color: black; } </style> </head> <body> <p>Note the styling applied on h1 element</p> <h1 id=”id-heading-color” class=”cl-heading-color” style=”background-color: pink; color:

CSS – Units

CSS – Measurement Units ”; Previous Next Values and units, in CSS, are significant as they determine the size, proportions, and positioning of elements on a web page. Units, define the measurement system used to specify the values. CSS offers a number of different units for expressing length and measurement. CSS unit is used to specify the property size for a page element or its content. There are a number of ways to specify and measure length in CSS. It is used to specify margins, padding, font size, width, height, border, etc. For example- font-size: 50px, here number 50 has a suffix px i.e., pixel, it is a CSS measurement unit. There should be no whitespace between the number and the unit. The unit can be left out when the value is 0. Following table shows the different types of values and units that we mostly use in CSS styling: Data type Description Example <integer> Represents a whole number 55, -55, etc. <number> Represents a decimal number. It may or may not have a decimal point. 1.5, 234, -1.5, etc. <dimension> Represents a <number> with a unit attached to it. Also includes value types such as <length>, <angle>, <time> and <resolution> 5px, 30deg, 2s, 2.5dpi <percentage> Represents a fraction of other value, that is, it is always relative to other value. 80%, 25%, etc. Length Units Length units can be categorized into two types: Absolute units Relative units Absolute Length Units These units are categorized as fixed-length units, which means that lengths specified with absolute units maintain an exact, unchanged size on the screen. These units prove to be very effective when the browser has comprehensive information about the properties of the screen, the printer being used, or other appropriate user agents. The following table contains all the types of absolute units: Unit Description Equivalent value Example mm Refers to millimetre, it is used to specify the measurements in millimetres. 1mm = 1/10th of 1cm font-size: 10mm; cm Refers to centimetre, it is used to specify the measurements in centimetres. 1cm = 37.8px = 25.2/64in font-size: 5cm; Q Refers to Quarter-millimeters, it is used to specify the measurements in centimetres. 1Q = 1/40th of 1cm font-size: 5Q; in Refers to inches, it is used to specify the measurement in inches. 1in = 2.54cm = 96px font-size: 1in; pt Refers to point, it is used to specify the measurements in points. 1pt = 1/72 of 1in font-size: 20pt; pc Refers to picas, it is used to specify the measurement in picas. 1pc = 1/6th of 1in width: 6pc; px Refers to pixels, it is used to specify the measurement in pixels. 1px = 1/96th of 1in font-size: 15px; Absolute units prove valuable for projects where responsiveness is not a priority. However, they are less beneficial for responsive websites because they do not adjust when screen dimensions change. CSS Measurement Units – Using mm, cm, in, Q Here is an example of absolute units (mm, cm, in, Q): <html> <head> <style> .unit-mm { font-size: 5mm; } .unit-cm { font-size: 1cm; } .unit-inch { font-size: 0.5in; } .unit-quarter { font-size: 40Q; } </style> </head> <body> <h1 class=”unit-mm”>Font size 5mm</h1> <h1 class=”unit-cm”>Font size 1cm</h1> <h1 class=”unit-inch”>Font size 0.5inch</h1> <h1 class=”unit-quarter”>Font size 40Q</h1> </body> </html> CSS Measurement Units – Using px, pt, pc Here is an example of absolute units (px, pt, pc): <html> <head> <style> .unit-px { font-size: 20px; } .unit-pt { font-size: 25pt; } .unit-pc { font-size: 3pc; } </style> </head> <body> <h1 class=”unit-px”>Font size 20px</h1> <h1 class=”unit-pt”>Font size 25pt</h1> <h1 class=”unit-pc”>Font size 3pc</h1> </body> </html> Relative Length Units Relative length units are called such because they are measured in relation to other elements. Relative units are great for styling responsive websites because they can be adjusted proportionally based on window size or parent elements. These units define lengths relative to other length properties. The following table contains all the types of relative units: Unit Description Example em Relative to the font-size of the element. font-size: 4em; ex Relative to the x-height of the current font. font-size: 4ex; ch Relative to width of the “0”. font-size: 4ch; rem Relative to font-size of the root element. font-size: 2rem; lh It is relative to the line height of the element. font-size: 4lh; rlh It is relative to the line height of the root element. font-size: 4rlh; vh It is relative to the height of the viewport. 1vh = 1% or 1/100 of the height of the viewport. font-size: 4vh; vw It is relative to the width of the viewport. 1vw = 1% or 1/100 of the width of viewport. width: 4vw; vmin It is relative to the smaller dimension of the viewport. 1vmin = 1% or 1/100 of the viewport”s smaller dimension. width: 4vmin; vmax It is relative to the larger dimension of the viewport. 1vmax = 1% or 1/100 of the viewport”s larger dimension. width: 4vmax; vb It is relative to the size of the

CSS – Comments

CSS – Comments ”; Previous Next In CSS, comments are useful in adding explanatory notes or annotations within your stylesheet that are not interpreted as styling instructions by the web browser. Syntax /* This is a comment */ p { color: red; /* Set text color to red */ } CSS comments are intended for the benefit of developers and are ignored by the browser when rendering a web page. They are useful in documentation, debugging, etc. Types of CSS Comments In CSS, there are two main ways to create comments: Single-line Comments: Single-line comments are created using /* to start the comment and */ to end it. Multi-line Comments: Multi-line comments allow you to add comments that span multiple lines. They are also enclosed within /* and */. /* Single line Comment */ /* Comment which stretches over multiple lines */ HTML And CSS comments In HTML tutorial we learned that, a command in HTML is defined between <!– and –> symbols. Syntax <html> <head> <style> /* This is a CSS Comment */ </style> </head> <body> <!– This is an html comment format –> </body> </html> Example Here is an example showing html comment and CSS comment format: <html> <head> <style> /* Target all div elements */ div { background-color: red; /* Set background color */ height: 50px; /* Set the height */ width: 200px; /* Set the width */ padding: 5px; /* Set the padding */ border: 5px solid black; /* Set the border */ } </style> </head> <body> <!– This is an html comment format –> <div> Styles Applied </div> </body> </html> Print Page Previous Next Advertisements ”;

CSS – Functions

CSS – Value Functions ”; Previous Next CSS value functions allow you to generate values for CSS properties dynamically. These functions take parameters and return a value that can be used in place of a static value. Syntax selector { property: function([argument]? [, argument]!); } The function name appears first in the value syntax, followed by a opening parenthesis (. The argument(s) come next, and a closing parenthesis ) completes the function. Multiple parameters are accepted by functions, and their formatting is the same as that of CSS property values. Though optional, whitespace is permitted inside parenthesis. Multiple arguments are separated by commas in certain functional notations and by spaces in others. Transform Functions The CSS data type called <transform-function> represents visual transformations and is employed as a value within the transform property. Translate Functions Following table lists translate functions: Functions Description translateX() Translates an element horizontally. translateY() Translates an element veritcally. translateZ() Translates an element along the z-axis. translate() Translates an element on the 2D plane. translate3d() Translates an element in 3D space. Rotation Functions Following table lists rotation functions: Functions Description rotateX() Rotates an element around the horizontal axis. rotateY() Rotates an element around the vertical axis. rotateZ() Rotates an element around the z-axis. rotate() Rotates an element around a fixed point on the 2D plane. rotate3d() Rotates an element around a fixed axis in 3D space. Scaling Functions Following table lists scaling functions: Functions Description scaleX() Scales an element up or down horizontally. scaleY() Scales an element up or down vertically. scaleZ() Scales an element up or down along the z-axis. scale() Scales an element up or down on the 2D plane. scale3d() Scales an element up or down in 3D space. Skew Functions Following table lists skew functions: Functions Description skewX() Skews an element in the horizontal direction. skewY() Skews an element in the vertical direction. skew() Skews an element on the 2D plane. Matrix Functions Following table lists matrix functions: Functions Description matrix() Describes a homogeneous 2D transformation matrix. matrix3d() Describes a 3D transformation as a 4×4 homogeneous matrix. Perspective Functions Following table lists perspective functions: Functions Description perspective() Sets the distance between the user and the z=0 plane. Math Functions Mathematical expressions can be used in CSS to represent numeric values using math functions. Basic Arithmetic Functions Following table lists basic arithmetic functions: Function Description calc() Performs basic arithmetic calculations on numerical values. Comparision Functions Following table lists comparision functions: Function Description min() Determines the minimum value from a given set of values. max() Determines the maximum value from a given list of values. clamp() Calculates the central of a minimum, central, and maximum values. Stepped Value Functions Following table lists stepped value functions: Function Description round() Calculates a rounded number based on a rounding strategy. Trignometric Functions Following table lists trignometric functions: Function Description sin() Calculates the trigonometric sine of a number. cos() Calculates the trigonometric cosine of a number tan() Calculates the trigonometric tangent of a number. asin() Calculates the trigonometric inverse sine of a number. acos() Calculates the trigonometric inverse cosine of a number. atan() Calculates the trigonometric inverse tangent of a number. atan2() Calculates the trigonometric inverse tangent of two-numbers in a plane. Filter Functions The CSS data type <filter-function> denotes a graphical effect capable of changing the look of an input image. It”s used within the filter and backdrop-filter properties. Function Description blur() Increases the image gaussian blur. brightness() Brightens or darkens an image.. contrast() Increases or decreases the image contrast. drop-shadow() Applies a drop shadow behind an image. grayscale() Converts an image to grayscale. hue-rotate() Changes the overall hue of an image. invert() Inverts the colors of an image. opacity() Adds transparency to an image. saturate() Changes the overall saturation of an image. sepia() Increases the sepia of an image. Color Functions The CSS data type <color> defines various ways to represent colors. Function Description rgb() Specifies a given color according to its red, green, blue and alpha (transparency) components. hsl() Specifies a given color according to its hue, saturation, lightness and alpha (transparency) components. hwb() Specifies a given

CSS – Multi Background

CSS – Multiple Backgrounds ”; Previous Next In CSS, you can use multiple background images for an element. First background should be layered on top, and the last background should be layered behind. Only the last background can have a background color. Syntax .multibackgrounds { background: background1, background2, /* …, */ backgroundN; } You can use shorthand and individual background properties, excluding background-color. The following background properties can be provided as a list, one for each background: background, background-attachment, background-clip, background-image, background-origin, background-position, background-repeat, background-size. CSS Multiple Backgrounds – Using background-image property The following example demonstrates adding two background images using background-image property, where the first image is stacked on top and the second is behind it − <html> <head> <style> .multibackgrounds { background-image: url(images/logo.png), url(images/see.jpg); background-position: left top, right top; background-repeat: no-repeat, repeat; padding: 70px; } </style> </head> <body> <div class=”multibackgrounds”> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p> </div> </body> </html> CSS Multiple Backgrounds – Using background-size Property The following example demonstrates the use of multiple background images of different sizes using background-size property. The first image”s size is 150px, and the second image”s size is 300px − <html> <head> <style> .multibackgrounds{ background-image: url(images/logo.png), url(images/see.jpg); background-position: left top, right top; background-repeat: no-repeat, repeat; padding: 70px; } .multibackgrounds-size { background-image: url(images/logo.png), url(images/see.jpg); background-position: left top, right top; background-repeat: no-repeat, repeat; background-size: 150px, 300px; padding: 70px; } </style> </head> <body> <h3>Without Sizing</h3> <div class=”multibackgrounds”> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p> </div><br> <h3>With Sizing</h3> <div class=”multibackgrounds-size”> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p> </div> </body> </html> CSS Multiple Backgrounds – Using background Property The following example demonstrates addition of three background images using the shorthand property background − <html> <head> <style> .multibackgrounds-size { background: url(images/logo.png), url(images/pink-flower.jpg), url(images/see.jpg); background-position: left top, center, right top; background-repeat: no-repeat, no-repeat, no-repeat; background-size: 150px, 100px, 550px; padding: 70px; color: yellow; } </style> </head> <body> <div class=”multibackgrounds-size”> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p> </div> </body> </html> CSS Multiple Backgrounds – Full Size Image The following example demonstrates full sized background image, set using background-size: cover property − <html> <head> <style> html { background: url(images/red-flower.jpg) no-repeat center fixed; background-size: cover; color: yellow; } </style> </head> <body> <h1>Red Flower Image</h1> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p> </body> </html> CSS Multiple Backgrounds – Hero Image The following example demonstrates the setting of a hero image, refers to a large image with text using different background properties on <div> − <html> <head> <style> .background-img { background: url(images/see.jpg) no-repeat center; background-size: cover; height: 300px; position: relative; } .background-text { text-align: center; position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); color: red; } button { background-color: yellow; padding: 10px; } </style> </head> <body> <div class=”background-img”> <div class=”background-text”> <h1>See Image</h1> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry”s standard dummy text ever since the 1500s.</p> <button>Click Me</button> </div> </div> </body> </html> CSS Multiple Backgrounds – Using background-origin Property The following example demonstrates how the background image is positioned within a box using background-origin property − <html> <head> <style> div { width: 200px; height: 150px; border: 7px solid blue; padding: 30px; background: url(images/pink-flower.jpg); background-repeat: no-repeat; margin: 10px; } P { color: yellow; } h3 { color: red; } .box1 { background-origin: padding-box; } .box2 { background-origin: border-box; } .box3 { background-origin: content-box; } </style> </head> <body> <div class=”box1″> <h3>background-origin: padding-box</h3> <p>Background image is positioned relative to the padding box.</p> </div> <div class=”box2″> <h3>background-origin: border-box</h3> <p>Background image is positioned relative to the border box.</p> </div> <div class=”box3″> <h3>background-origin: content-box</h3> <p>Background image is positioned relative to the content box.</p> </div> </body> </html> CSS Multiple Backgrounds – Using background-clip Property The following example demonstrates how the background image should be displayed within box using background-clip property − <html> <head> <style> p { width: 200px; height: 150px; border: 8px solid blue; margin: 10px; padding: 30px; color: yellow; background: url(images/pink-flower.jpg); } .box1 { background-clip: border-box; } .box2 { background-clip: padding-box; } .box3 { background-clip: content-box; } </style> </head> <body> <p class=”box1″>Background image is applied to the entire element.</p> <p class=”box2″>Background image is applied to the padding area.</p> <p class=”box3″>Background image is applied only to the content area.</p> </body> </html> CSS Multiple Backgrounds – Related Properties All the properties related to background are listed in the table below: Properties Description background Shorthand for background related properties. background-attachment Specifies the position of the background relative to the viewport, either fixed or scrollable. background-clip Controls how far a background image extends beyond the element”s padding or content