CSS – float Property ”; Previous Next The CSS float property controls the positioning and formatting of content on the page. It positions an element on the right or left side of the container, letting text and other inline elements to wrap around it. The float property uses the block layout, hence it adjusts the computed value of the display property in certain cases: Specified value Computed value inline block inline-block block inline-table table table-row block table-row-group block table-column block table-column-group block table-cell block table-caption block table-header-group block table-footer-group block inline-flex flex inline-grid grid This chapter discusses how to use float property. Possible Values Following are all possible values that can be used for property float: none: The element does not float. This is the default value. left: The element floats to the left of its container.. right: The element floats to the right of its container. inline-start: The element floats to the start side of its containing block. (For ltr scripts its left side, and the right side for rtl scripts). inline-end: The element floats to the end side of its containing block. (For ltr scripts its right side, and the left side for rtl scripts). Values inline-start and inline-end are supported only by Firefox and Safari browsers. Applies to All elements, but has no effect if the value of display is none. Syntax float = left | right | inline-start | inline-end | none We can”t float elements to the center, top, or bottom of a container — only left or right float can be done. Following example demonstrates usage of float property with its values: <html> <head> <style> div { margin: 5px; width: 50px; height: 150px; } .left { float: left; background: yellow; } .right { float: right; background: cyan; } .inherit{ float: inherit; background: pink; } </style> </head> <body> <div class=”left”>1</div> <div class=”right”>2 <div class=”inherit”>3</div> </div> <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration insome form, by injected humour, or randomised words which don”t look even slightly believable. </p> </body> </html> CSS Float – Equal Width Columns We can create a two-columns layout with equal widths where two grid boxes are floated on the right side of a container using the float: right property. Here is an example − <html> <head> <style> .grid-box { float: right; width: 50%; padding: 30px; box-sizing: border-box; text-align: center; } .grid-container::after { content: “”; clear: both; display: table; } </style> </head> <body> <h4>The first red color grid box is placed on the right side.</h3> <div class=”grid-container”> <div class=”grid-box” style=”background-color:#f0610e;”> <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration insome form, by injected humour, or randomised words which don”t look even slightly believable.</p> </div> <div class=”grid-box” style=”background-color:#86f00e;”> <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration insome form, by injected humour, or randomised words which don”t look even slightly believable.</p> </div> </div> </body> </html> CSS Float – Equal Height Columns Create a simple two-columns layout with equal height where two grid boxes are floated on the left side of a container using the float: left property. Here is an example − <html> <head> <style> .grid-box { float: left; width: 50%; height: 200px; padding: 30px; box-sizing: border-box; text-align: center; } .grid-container::after { content: “”; clear: both; display: table; } </style> </head> <body> <h4>The first red color grid box is placed on the left side.</h3> <div class=”grid-container”> <div class=”grid-box” style=”background-color:#f0610e;”> <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration insome form, by injected humour, or randomised words which don”t look even slightly believable.</p> </div> <div class=”grid-box” style=”background-color:#86f00e;”> <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don”t look even slightly believable.</p> </div> </div> </body> </html> CSS Float – Images Next To Each Other A simple four-column images layout can be created using floating elements. The float: right property positions an image to the right within the container. Here is an example − <html> <head> <style> .grid-box { float: right; width: 25%; padding: 3px; box-sizing: border-box; text-align: center; } .grid-container::after { content: “”; clear: both; display: table; } </style> </head> <body> <h4>The first image is placed on the right side, while the rest of the images are also right aligned within the container.</h4> <div class=”grid-container”> <div class=”grid-box”> <img class=”tutimg” src=”images/orange-flower.jpg” width=”100%” height=”50%” /> <p>Orange color flower</p> </div> <div class=”grid-box”> <img class=”tutimg” src=”images/see.jpg” width=”100%” height=”50%” /> <p>see</p> </div> <div class=”grid-box”> <img class=”tutimg” src=”images/tree.jpg” width=”100%” height=”50%” /> <p>Tree</p> </div> <div class=”grid-box”> <img class=”tutimg” src=”images/red-flower.jpg” width=”100%” height=”50%” /> <p>Red color flower</p> </div> </div> </body> </html> CSS Float – Flexible Boxes To create a two-column layout within a flexible container, you can use the display: flex property to make the container a flex container, and the flex-nowrap property ensures that the flex items remain in a single row even if the viewport width is reduced. Here is an example − <html> <head> <style> .grid-container { display: flex; flex-wrap: nowrap; background-color: #f0610e; } .grid-box { width: 50%; padding: 30px; box-sizing: border-box; text-align: center; background-color: #86f00e; margin: 15px; } .grid-container::after { content: “”; clear: both; display: table; } </style> </head> <body> <h4>Resize the browser window to see the
Category: css
CSS – Resize
CSS – Resize ”; Previous Next CSS resize is a property that allows users to adjust the size of an element, either vertically, horizontally, both, or none, based on the specified value. Resize property adds a handle at the bottom-right corner of an element on a webpage. This handle allows users to click and drag to change the size of an elements, making it larger or smaller according to their preference. This chapter will cover the use of resize property. Possible Values none − No user-controllable method for resizing an element is possible. This is default value. vertical − User can resize an element in the vertical direction. horizontal − User can resize an element in the horizontal direction. both − User can resize an element both horizontally and vertically. block − User can resize an element in the block direction (either horizontally or vertically, depending on the writing-mode and direction value). inline − User can resize an element in the inline direction (either horizontally or vertically, depending on the writing-mode and direction value). The properties block and inline are supported only on Firefox and Safari browsers. Applies to Elements with overflow other than visible, and optionally replaced elements representing images or videos, and iframes Syntax resize: none | vertical | horizontal| both; CSS resize – none Value Following example demonstrates use of CSS resize property set to none value. Here we see user is prevented from resizing the element in any direction. The resize: none is a default value. <html> <head> <style> textarea { background-color: #e7ef0e; color: #ee2610; resize: none; overflow: auto; height: 150px; width: 250px; } </style> </head> <body> <textarea>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don”t look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn”t anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet.</textarea> </body> </html> CSS resize – vertical Value Following example demonstrates use of CSS resize property set to vertical. Here we see user is allowed to resize the height of the <div> element vertically by dragging the bottom-right corner. <html> <head> <style> div { background-color: #e7ef0e; color: #ee2610; resize: vertical; overflow: auto; height: 150px; width: 250px; } </style> </head> <body> <h3>Click and drag the bottom-right corner to change the size of an element vertically.</h3> <div> <h2 style=”color: #0f5e02; text-align: center;”>Tutorialspoint</h2> There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don”t look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn”t anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. </div> </body> </html> CSS resize – horizontal Value Following example demonstrates use of CSS resize property set to horizontal. Here we see user is allowed to modify the width of a <div> element horizontally by dragging the bottom-right corner. <html> <head> <style> div { background-color: #e7ef0e; color: #ee2610; resize: horizontal; overflow: auto; height: 150px; width: 250px; } </style> </head> <body> <h3>Click and drag the bottom-right corner to change the size of an element horizontally.</h3> <div> <h2 style=”color: #0f5e02; text-align: center;”>Tutorialspoint</h2> There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don”t look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn”t anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the internet. </div> </body> </html> CSS resize – both Value Following example demonstrates use of CSS resize property set to both. Here we see user is allowed to resize the element both horizontally and vertically. <html> <head> <style> div { background-color: #e7ef0e; color: #ee2610; resize: both; overflow: auto; height: 150px; width: 250px; } </style> </head> <body> <h3>Click and drag the bottom-right corner to change the size of an element vertically and horizontally.</h3> <div> <h2 style=”color: #0f5e02; text-align: center;”>Tutorialspoint</h2> There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don”t look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn”t anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. </div> </body> <html> CSS resize – inherit Value Following example demonstrates use of CSS resize property set to inherit on a child element. Here we see it will have the same resizing behavior as its parent element. <html> <head> <style> .my-box1 { background-color: #e7ef0e; color: #ee2610; resize: vertical; overflow: auto; height: 150px; width: 250px; } .my-box2 { resize: inherit; } </style> </head> <body> <h3>Click and drag the bottom-right corner to change the size of an element.</h3> <div class=”my-box1″> <div class=”my-box2″> <h2 style=”color: #0f5e02; text-align: center;”>Tutorialspoint</h2> There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don”t look even slightly believable. If you
CSS – Dropdowns
CSS – Dropdowns ”; Previous Next Dropdown is a user interface element that includes a list of options. It allows the user to choose one value from a list by hovering or clicking on a trigger element. It is typically used in navigation menus, forms, and other interactive components of a website. Dropdown menu is created using HTML”s unordered list (<ul>) and list item (<li>) elements. This chapter will cover the utilization of CSS for styling and arranging dropdown menu elements, controlling their appearance and behavior. CSS Dropdown – Basic Example Let us see a simple example of dropdowns with list of options. When you hover over the “Select an Option” text, a dropdown menu appears with options. <html> <head> <style> .dropdown { position: relative; display: inline-block; } .dropdown-button { background-color: #e81a1a; padding: 10px 20px; border: none; cursor: pointer; color: #ffffff; margin: 0; } .dropdown-menu { display: none; position: absolute; background-color: #fff; border: 1px solid #ccc; margin: 0; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); padding: 12px 16px; z-index: 1; } .dropdown:hover .dropdown-menu { display: block; } </style> </head> <body> <div class=”dropdown”> <span class=”dropdown-button”>Select an Option</span> <div class=”dropdown-menu”> <p>Option 1</p> <p>Option 2</p> <p>Option 3</p> </div> </div> </body> </html> In the above example: Use any HTML element such as <span>, or a <button> to open the dropdown content. To create the dropdown content or menu, use a container element (like >div< Use CSS to wrap and position dropdown content correctly. The .dropdown class uses position:relative. This property places dropdown menu right below the dropdown button (using position:absolute). .dropdown-menu class holds the actual dropdown content. It is hidden by default, and will be displayed on hover. CSS box-shadow property to make the dropdown menu look like a card. The :hover selector shows the dropdown menu when the user moves the mouse over the dropdown button. CSS Dropdown – Hoverable Effect A hoverable dropdown is a user interface element where a dropdown menu appears when a user hovers their cursor over the trigger element. The dropdown menu usually disappears when the user moves their cursor away from the trigger element. Let us see an example. This example uses anchor tags inside the dropdown box and style them to fit a styled dropdown button: <html> <head> <style> .dropdown { position: relative; display: inline-block; } .dropdown-button { background-color: #e81a1a; padding: 15px; border: none; cursor: pointer; color: #ffffff; margin: 0; } .dropdown-menu { display: none; position: absolute; background-color: #fff; border: 1px solid #ccc; padding: 0; margin: 0; } .dropdown-menu li { padding: 10px; background-color: #15AD39; } .dropdown-menu li a { display: block; text-decoration: none; color: #ffffff; } .dropdown:hover .dropdown-menu { display: block; } .dropdown-menu li:hover { background-color: #82ea32; } </style> </head> <body> <div class=”dropdown”> <button class=”dropdown-button”>Select an Option</button> <ul class=”dropdown-menu”> <li><a href=”#”>Option 1</a></li> <li><a href=”#”>Option 2</a></li> <li><a href=”#”>Option 3</a></li> </ul> </div> </body> </html> CSS Dropdown – Clicked Dropdowns When you click on a dropdown, it expands to show the available options, and you can select one of these options by clicking on it. Let us see an example: <html> <head> <style> .dropdown-button { background-color: #e81a1a; padding: 15px; border: none; cursor: pointer; color: #ffffff; margin: 0; } .dropdown-menu { display: none; position: absolute; background-color: #fff; border: 1px solid #ccc; padding: 0; margin: 0; } .dropdown-menu li { padding: 10px; background-color: #15AD39; } .dropdown-menu li a { display: block; text-decoration: none; color: #ffffff; } .dropdown-menu li:hover { background-color: #82ea32; } .show { display: block; } </style> </head> <body> <div class=”dropdown”> <button class=”dropdown-button”>Select an Option</button> <ul class=”dropdown-menu”> <li><a href=”#”>Option 1</a></li> <li><a href=”#”>Option 2</a></li> <li><a href=”#”>Option 3</a></li> </ul> </div> <script> document.addEventListener(”DOMContentLoaded”, function () { const button = document.querySelector(”.dropdown-button”); const dropdownContent = document.querySelector(”.dropdown-menu”); button.addEventListener(”click”, function () { dropdownContent.classList.toggle(”show”); }); window.addEventListener(”click”, function (event) { if (!event.target.matches(”.dropdown-button”) && dropdownContent.classList.contains(”show”)) { dropdownContent.classList.remove(”show”); } }); }); </script> </body> </html> CSS Dropdown – Right-aligned Menu You can place a dropdown menu on the right side of the screen by applying a float: right style to the <div> that contains the dropdown menu. This arrangement shifts the menu to the right-hand side of the screen. Let us see an example: <html> <head> <style> .dropdown { position: relative; display: inline-block; } .dropdown-button { background-color: #e81a1a; padding: 15px; border: none; cursor: pointer; color: #ffffff; margin: 0; } .dropdown-menu { display: none; position: absolute; background-color: #fff; border: 1px solid #ccc; padding: 0; margin: 0; list-style: none; } .dropdown-menu li { padding: 10px; background-color: #15AD39; } .dropdown-menu li a { display: block; text-decoration: none; color: #ffffff; } .dropdown:hover .dropdown-menu { display: block; } .dropdown-menu li:hover { background-color: #82ea32; } </style> </head> <body> <div class=”dropdown” style=”float: right;”> <button class=”dropdown-button”>Select an Option</button> <ul class=”dropdown-menu”> <li><a href=”#”>Option 1</a></li> <li><a href=”#”>Option 2</a></li> <li><a href=”#”>Option 3</a></li> </ul> </div> </body> </html> CSS Dropdown – Left-aligned Menu You can achieve a left-aligned dropdown menu by adding the float: left style to the <div> containing the dropdown menu. This arrangement shifts the menu to the leftmost part of the screen. Let us see an example: <html> <head> <style> .dropdown { position: relative; display: inline-block; } .dropdown-button { background-color: #e81a1a; padding: 15px; border: none; cursor: pointer; color: #ffffff; margin: 0; } .dropdown-menu { display: none; position: absolute; background-color: #fff; border: 1px solid #ccc; padding: 0; margin: 0; list-style: none; } .dropdown-menu li { padding: 10px; background-color: #15AD39; } .dropdown-menu li a { display: block; text-decoration: none; color: #ffffff; } .dropdown:hover .dropdown-menu { display: block; } .dropdown-menu li:hover { background-color: #82ea32; } </style> </head> <body> <div class=”dropdown” style=”float: left;”> <button class=”dropdown-button”>Select an Option</button> <ul class=”dropdown-menu”> <li><a href=”#”>Option 1</a></li> <li><a href=”#”>Option 2</a></li> <li><a href=”#”>Option 3</a></li> </ul> </div> </body> </html> CSS Dropdown – With Image You can enhance the dropdown by including images alongside the textual options. When you hover over an
CSS – Lists
CSS – Lists ”; Previous Next Lists are useful as they present the information in a structured and organized manner. Lists improve the readability and comprehension of content on a web page. So, if the content is listed, it is easy to follow. Lists are commonly used to display items, steps, options, or any other type of related information that should be presented sequentially or in a group. This chapter will discuss how to control list type, position, style, etc., using CSS. Before that let us understand how are HTML lists different in the following sections. HTML Lists HTML provides mainly two kinds of lists – <ol> (ordered list) and <ul> (unordered list). Name Description Syntax Ordered List (<ol>) Ordered lists are used when the items need to be presented in a specific order. Commonly used for procedures, steps, instructions, or any sequence of information where the order matters. <ol class=”list”> <li></li> </ol> Unordered List (<ul>) Unordered lists are used when the order of items doesn”t matter, and you want to present items as a group. Commonly used for lists of features, benefits, options, or any non-sequential information. <ul class=”list”> <li></li> </ul> Example Let us see an example of the two kinds of lists (without CSS): <!DOCTYPE html> <html> <head> <title>CSS – Lists</title> <meta charset=”UTF-8″> <meta http-equiv=”X-UA-Compatible” content=”IE=edge”> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <style> h2 {margin-bottom: 5px;} </style> </head> <body> <div> <h2>Ordered list</h2> <ol class=”list”> <li>The list is ordered.</li> <li>It is used in cases where we need to follow a sequence.</li> <li>The points are numbered.</li> </ol> <h2>Unordered list</h2> <ul class=”list”> <li>The list is unordered.</li> <li>It is used in cases where we need not follow a sequence.</li> <li>The points are bulleted.</li> </ul> </div> </body> </html> Lists – CSS Properties CSS provides a set of properties that can be applied to any list, which are as follows: The list-style-type allows you to control the shape or appearance of the marker. The list-style-position specifies whether a long point that wraps to a second line should align with the first line or start underneath the start of the marker. The list-style-image specifies an image for the marker rather than a bullet point or number. The list-style serves as shorthand for the preceding properties. Item markers for lists or Bullet Styles To change the type of marker used for a list’s items, property list-style-type can be used. The same property can be used for both ordered and unordered lists. Let us see an example: <!DOCTYPE html> <html> <head> <title>CSS – Lists</title> <meta charset=”UTF-8″> <meta http-equiv=”X-UA-Compatible” content=”IE=edge”> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <style> h2 { margin-bottom: 5px; } ol.o1 { list-style-type: lower-roman; } ol.o2 { list-style-type: upper-alpha; } ul.u1 { list-style-type:square; } ul.u2 { list-style-type: circle; } </style> </head> <body> <div> <h2>Ordered list – Item markers</h2> <ol class=”o1″> <li>The item marker is lower-roman.</li> <li>It is used in cases where we need to follow a sequence.</li> </ol> <ol class=”o2″> <li>The item marker is upper-alpha.</li> <li>It is used in cases where we need to follow a sequence.</li> </ol> <h2>Unordered list – Item markers</h2> <ul class=”u1″> <li>The item marker is square.</li> <li>It is used in cases where we need not follow a sequence.</li> </ul> <ul class=”u2″> <li>The item marker is circle.</li> <li>It is used in cases where we need not follow a sequence.</li> </ul> </div> </body> </html> Following table lists possible values that can be used for property list-style-type: Value Description Example none NA NA disc (default) A filled-in circle circle An empty circle square A filled-in square decimal Number 1, 2, 3, 4, 5, … decimal-leading-zero 0 before the number 01, 02, 03, 04, 05, … lower-alpha Lowercase alphanumeric characters a, b, c, d, e, … upper-alpha Uppercase alphanumeric characters A, B, C, D, E, … lower-roman Lowercase Roman numerals i, ii, iii, iv, v, … upper-roman Uppercase Roman numerals I, II, III, IV, V, … lower-greek The marker is lower-greek alpha, beta, gamma, … lower-latin The marker is lower-latin a, b, c, d, e, … upper-latin The marker is upper-latin A, B, C, D, E, … hebrew The marker is traditional Hebrew numbering armenian The marker is traditional Armenian numbering georgian The marker is traditional Georgian numbering cjk-ideographic The marker is plain ideographic numbers hiragana The marker is Japanese numbering – hiragana a, i, u, e, o, ka, ki katakana The marker is Japanese numbering – katakana A, I, U, E, O, KA, KI hiragana-iroha The marker is Japanese numbering (hiragana-iroha) i, ro, ha, ni, ho, he, to katakana-iroha The marker is Japanese numbering (katakana-iroha) I, RO, HA, NI, HO, HE, TO The list-style-type property, as well as all other list-related properties, can be applied only to an element that has a display of list-item, but CSS doesn’t distinguish between ordered and unordered list items. User agent may prohibit ordered markers from being applied to unordered lists, and vice versa. You can’t count on this, so be careful. Item list marker – an image (Using a custom bullet image) You might prefer
CSS – Dimension
CSS – Dimension ”; Previous Next In the earlier chapters we learnt how to add padding, margin, border, etc using CSS to an element. Now we will see how to set dimensions to an element. Here we will study how to set conditions to limit how high or wide a positioned element gets, not to mention cases where you want the browser to go ahead and automatically calculate the width, height, or both. Following properties allow you to control the dimensions of an element: height: Sets the height of an element. width: Sets the width an element. line-height: Sets the height of a line of text. max-height: Sets a maximum height that an element can have. min-height: Sets the minimum height that an element can have. max-width: Sets the maximum width that an element can have. min-width: Sets the minimum width that an element can have. Height And Width The height and width properties allow you to set specific height and width for your positioned element. These properties can hold following values: length: Any unit of length (px, pt, em, in, etc.) percentage (%): A percentage value, which is in percent of the containing block. auto: Browser calculates the height and width of the element. Default value. initial: Sets the value of height and width to its default value. inherit: Inherits the value of height and width from its parent value. Following example demonstrates using height and width for a div element: <html> <head> <style> div { height: 100px; width: 80%; background-color: rgb(206, 211, 225); } </style> </head> <body> <h2>Height and Width Property without layout properties</h2> <div>This div element has a height of 100px and a width of 80%.</div> </body> </html> The height and width properties in this example add nothing to the layout of the element i.e it doesn”t include padding, margin or border. Following example demonstrates the difference when using height and width for a div along with padding, a border, or a margin: <html> <head> <style> div { height: 100px; width: 80%; padding: 2em; border:1px solid; margin:2px; background-color: rgb(206, 211, 225); } </style> </head> <body> <h2>Height and Width Property with padding, margin, border</h2> <div>This div element has a height of 100px and a width of 80%.</div> </body> </html> CSS Dimension – Line Height The line-height property allows you to set the space between lines of text. The value of the line-height property can be: length: Any unit length, used in the calculation of line box height (px, pt, em, in, etc.) percentage (%): Value relative to the font size of the element. number: A unitless number, that is multiplied by the element”s own font-size. normal: A keyword. The default value is 1.2, but it depends on the element”s font-family. Example Here is an example: <html> <head> <style> div.a { line-height: 2in; font-size: 10pt; background-color: rgb(206, 211, 225); margin-bottom: 2px; } div.b { line-height: 100px; font-size: 10pt; background-color: rgb(206, 211, 225); margin-bottom: 2px; } div.c { line-height: 5; font-size: 10pt; background-color: rgb(206, 211, 225); margin-bottom: 5px; } div.d { line-height: normal; font-size: 10pt; background-color: rgb(206, 211, 225); margin-bottom: 2px; } </style> </head> <body> <h2>line-height Property</h2> <div class=”a”>This div element has a line-height of 2 inches.</div> <div class=”b”>This div element has a line-height of 100px.</div> <div class=”c”>This div element has a line-height of 5 (unitless number)</div> <div class=”d”>This div element has a line-height of normal.</div> </body> </html> CSS Dimension – Maximum Height An element’s height can be limited using max-height property. This allows you to specify maximum height of an element. The value of the max-height property can be: none: No maximum height value is set. Default value. length: Sets the maximum height in terms of length units (px, pt, em, in, etc.) percentage (%): Value relative to the percent of containing block. initial: Sets the value of max-height to its default value. inherit: Inherits the value of max-height from its parent. Example Here is an example: <html> <head> <style> div { width: 60%; overflow: auto; border: 2px solid black; padding-bottom: 2px; } div.a { max-height: 100px; } div.b { max-height: 70%; } div.c { max-height: inherit; } div.d { max-height: none; } </style> </head> <body> <div class=”a”> <h2>max-height: 100px and width:80%</h2> <p class=”a”><p>The <i>max-height</i> property allows you to specify maximum height of a box. The value of the max-height property can be various, but this one is 100px.</p> </div> <div class=”b”> <h2>max-height: 70% and width:80%</h2> <p class=”a”><p>The <i>max-height</i> property allows you to specify maximum height of a box. The value of the max-height property can be various, but this one is 70%.</p> </div> <div class=”c”> <h2>max-height: inherit and width:80%</h2> <p class=”a”><p>The <i>max-height</i> property allows you to specify maximum height of a box. The value of the max-height property can be various, but this one is inherit.</p> </div> <div class=”d”> <h2>max-height: none and width:80%</h2> <p class=”a”><p>The <i>max-height</i> property allows you to specify maximum height of a box. The value of the max-height property can be various, but this one is none.</p> </div> </body> </html> CSS Dimension – Minimum Height The min-height property in CSS is used to set the minimum height of an element. It specifies the smallest height that an element can have, ensuring that it will never shrink below that value. The value of the min-height property can be: length: Sets the minimum height in terms of length units (px, pt, em, in, etc.). Default value. percentage (%): Value is relative to the percent of containing block. initial: Sets the value of min-height to its default value. inherit: Inherits the value of min-height from its parent. The minimum height will
CSS – Inline Block
CSS – inline-block ”; Previous Next CSS inline-block property is used to display an element as an inline-level block container. Inline-block elements do not start on a new line, but they can be set to a specific width and height. Here are some of the characteristics of the inline-block property: The element will be displayed on the same line as other inline elements. The element will have a width and height, but it will not have a margin or padding by default. The element can be floated or positioned. The element can be cleared of floats. The display: inline-block property is a combination of the display: inline and display: block properties. It allows an element not only to behave like an inline element, but also have the ability to take up space on a line like a block element. Difference between display: inline, display: block and display: inline-block: inline block inline-block The element is displayed on the same line. The element is displayed on a new line. The element is displayed on the same line . It does not take up the full width of the container. It takes up the full width of the container. It does not take up the full width of the container. It does not have a margin or padding by default. It has a margin and padding by default. It has a margin and padding by default. Following diagram shows the different layout behavior of inline, block, and inline-block elements: CSS Inline Block – With Different Behavior Here”s an example that demonstrates the different behaviors of the display: inline, display: block and display: inline-block properties − <html> <head> <style> .display-inline { display: inline; background-color: #1f9c3f; border: 2px solid #000000; color: #ffffff; padding: 5px; text-align: center; } .display-block { display: block; background-color: #1f9c3f; border: 2px solid #000000; color: #ffffff; padding: 5px; height: 30px; text-align: center; } .display-inline-block { display: inline-block; background-color: #1f9c3f; border: 2px solid #000000; color: #ffffff; padding: 5px; height: 30px; text-align: center; } </style> </head> <body> <h2>Display Inline</h2> <div>There are many variations of passages of Lorem Ipsum available, <span class=”display-inline”>Tutorialspoint</span> , by injected humour, or randomised words which don”t look even slightly believable.</div> <h2>Display Block</h2> <div>There are many variations of passages of Lorem Ipsum available, <span class=”display-block”>Tutorialspoint</span> , by injected humour, or randomised words which don”t look even slightly believable.</div> <h2>Display Inline Block</h2> <div>There are many variations of passages of Lorem Ipsum available, <span class=”display-inline-block”>Tutorialspoint</span> , by injected humour, or randomised words which don”t look even slightly believable.</div> </body> </html> CSS Inline Block – Navigation Links The inline-block property is used to create horizontal navigation menus or lists, where each navigation item is displayed as a block-level element, but remains inline with other items. <html> <head> <style> ul { list-style-type: none; margin: 0; padding: 15px; background-color: #1f9c3f; } li { display: inline-block; } a { padding: 10px; color: rgb(247, 247, 247); } </style> </head> <body> <ul> <li><a href=”#”>Tutorialspoint</a></li> <li><a href=”#”>Home</a></li> <li><a href=”#”>Articles</a></li> <li><a href=”#”>Courses</a></li> <li><a href=”#”>About us</a></li> </ul> </body> </html> CSS Inline Block – Button Groups You can create button groups that are displayed horizontally using the inline-block property. The buttons will be displayed together on the same line, and they will have a specific width and height. <html> <head> <style> .button-group { display: inline-block; background-color: #ef4343; } button { padding: 10px; margin: 10px; background-color: #1f9c3f; border: none; color: #ffffff; width: 80px; height: 40px; } </style> </head> <body> <div class=”button-group”> <button>Submit</button> <button>Cancel</button> <button>Reset</button> </div> </body> </html> CSS Inline Block – Images And Text The inline-block property causes the image and span to be displayed on the same line, allowing them to be aligned horizontally within the block. <html> <head> <style> div { display: inline-block; } img { width: 100px; height: 100px; } span { padding: 10px; } </style> </head> <body> <div> <img src=”images/tutimg.png” alt=”Image”> <span>Tutorialspoint</span> </div> </body> </html> CSS Inline Block – Progress Bars We can create progress bars using the inline-block property. This property is displayed on the same line as other inline elements. <html> <head> <style> .progress-bar { display: inline-block; width: 100%; height: 25px; background-color: blue; border-radius: 15px; overflow: hidden; } .progress-bar-fill { width: 70%; background-color: #1f9c3f; height: 100%; } </style> </head> <body> <div class=”progress-bar”> <div class=”progress-bar-fill”></div> </div> </body> </html> Print Page Previous Next Advertisements ”;
CSS – Zoom
CSS – Zoom ”; Previous Next The zoom property of CSS is useful in controlling the magnification level of elements. zoom is a non-standard property of CSS and it is advisable to use the transform: scale() function for the same output. Possible Values normal: Specifies that the element should be rendered at its normal size. reset: Specifies that the element should not de(magnify), unless the user applies non-pinch-based zooming. Not recommended, instead use unset value. <percentage>: Any percentage value called zoom factor. Value equal to 100% is normal. Value more than 100% means element should zoom-in. Value less than 100% means element should zoom-out. <number>: Any number value that corresponds to a percentage value. For example: 1.0 = 100% = normal. Value equal to 1.0 is normal. Value more than 1.0 means element should zoom-in. Value less than 1.0 means element should zoom-out. Applies to All the HTML elements. DOM Syntax object.style.zoom = “normal | reset | <number> | <percentage>”; CSS zoom – normal Value Here is an example: <html> <style> p.normal { zoom: normal; } p.percent { zoom: 170%; } p.number { zoom: 4; } p.unset { zoom: unset; } </style> <head> </head> <body> <p class=”normal”>Normal size</p> <p class=”percent”>Zoom in percentage</p> <p class=”number”>Zoom in number</p> <p class=”unset”>Zoom settings reverted.</p> </body> </html> CSS zoom – <percentage> Value Here is another example: <html> <head> <style> div.box { height: 50px; width: 50px; display: inline-block; padding: 5px; border: 1px solid black; } div#m { background-color: orange; zoom: 200%; } div#n { background-color: lavender; zoom: 1.5; } div#o { background-color: palevioletred; zoom: normal; } </style> </head> <body> <div id=”m” class=”box”></div> <div id=”n” class=”box”></div> <div id=”o” class=”box”></div> </body> </html> CSS zoom – With number Value Here is an example, where the h1 element gets zoomed on hover: <html> <head> <style> p { border: 1px solid red; } p.percent { zoom: 170%; } p.number { zoom: 4; } h1:hover { zoom: 250%; text-decoration-line: underline; } </style> </head> <body> <h1>Hover to Zoom</h1> <p class=”percent”>Zoom in percentage</p> <p class=”number”>Zoom in number</p> </body> </html> CSS zoom – With Animation Here is an example, where the animation is added on hover along with zoom: <html> <head> <style> div.box { width: 25px; height: 25px; vertical-align: middle; display: inline-block; transition: transform .5s; padding: 10px; } div#a { background-color: rgb(58, 220, 22); zoom: normal; } div#b { background-color: rgb(239, 86, 137); zoom: 200%; } div#c { background-color: rgb(223, 217, 44); zoom: 2.9; } div.box:hover { transform: scale(1.5); } </style> </head> <body> <h1>Animation added on hover</h1> <div id=”a” class=”box”></div> <div id=”b” class=”box”></div> <div id=”c” class=”box”></div> </body> </html> Print Page Previous Next Advertisements ”;
CSS – Bottom
CSS – bottom Property ”; Previous Next The bottom property in CSS is used to set the bottom position of a positioned element. It specifies the distance between the bottom edge of the element and the bottom edge of its containing element. Based on the value of the position property, the effect of bottom property, is determined. Position value Bottom property absolute or fixed Specifies the distance between element”s bottom edge”s outer margin amd the inner border of the container”s bottom edge. relative Specifies the distance the element”s bottom edge is moved above its normal position. sticky Used to compute the sticky-constraint rectangle. static No effect on the elements. Both top and bottom distances are respected, when both top and bottom values are specified, position is set to absolute or fixed , and height is either 100% or auto. The top value takes precedence and the bottom value is ignored, when height is constrained or position is set to relative. Possible Values <length> − Can specify a negative, null or positive value. <percentage> − Percentage of the container”s height. auto − Default value. Browser calculates the bottom position. Applies to All the HTML positioned element. DOM Syntax object.style.bottom = “2px”; CSS bottom – With Absolute Position Here is an example with position:absolute and bottom having different values (auto, percent, length) − <html> <head> <style> div.blockbottompostion { bottom: 10%; background-color: yellow; position: absolute; height: 100px; border: 3px solid rgb(12, 5, 62); } </style> </head> <body> <h1>The bottom Property</h1> <p>This<br />is<br />tutorialspoint<br />site,<br />and,<br />has,<br />many,<br />many<br />courses. </p> <p>This<br />site<br />has<br />abundant,<br />material,<br />on,<br />all,<br />skills. </p> <div class=”blockbottompostion”>Position:absolute bottom:10%</div> </body> </html> CSS bottom – With Relative Position Here is an example with position:relative and bottom having different values (auto, percent, length)− <html> <head> <style> div.blockbottompostion { bottom: 10%; background-color: yellow; position: relative; height: 100px; border: 3px solid rgb(12, 5, 62); } </style> </head> <body> <h1>The bottom Property</h1> <p>This<br />is<br />tutorialspoint<br />site,<br />and,<br />has,<br />many,<br />many<br />courses. </p> <p>This<br />site<br />has<br />abundant,<br />material,<br />on,<br />all,<br />skills. </p> <div class=”blockbottompostion”>Position:relative bottom:10%</div> </body> </html> CSS bottom – With Fixed Position Here is an example with position:fixed and bottom having different values (auto, percent, length)− <html> <head> <style> div.blockbottompostion { bottom: 10%; background-color: yellow; position: fixed; height: 100px; border: 3px solid rgb(12, 5, 62); } </style> </head> <body> <h1>The bottom Property</h1> <p>This<br />is<br />tutorialspoint<br />site,<br />and,<br />has,<br />many,<br />many<br />courses. </p> <p>This<br />site<br />has<br />abundant,<br />material,<br />on,<br />all,<br />skills. </p> <div class=”blockbottompostion”>Position:fixed bottom:10%</div> </body> </html> CSS bottom – With Sticky Position Here is an example with position:sticky and bottom having different values (auto, percent, length)− <html> <head> <style> div.blockbottompostion { bottom: 10%; background-color: yellow; position: sticky; height: 100px; border: 3px solid rgb(12, 5, 62); } </style> </head> <body> <h1>The bottom Property</h1> <p>This<br />is<br />tutorialspoint<br />site,<br />and,<br />has,<br />many,<br />many<br />courses. </p> <p>This<br />site<br />has<br />abundant,<br />material,<br />on,<br />all,<br />skills. </p> <div class=”blockbottompostion”>Position:sticky bottom:10%</div> </body> </html> CSS bottom – With Static Position Here is an example with position:static and bottom having different values (auto, percent, length)− <html> <head> <style> div.blockbottompostion { bottom: 10%; background-color: yellow; position: static; height: 100px; border: 3px solid rgb(12, 5, 62); } </style> </head> <body> <h1>The bottom Property</h1> <p>This<br />is<br />tutorialspoint<br />site,<br />and,<br />has,<br />many,<br />many<br />courses. </p> <p>This<br />site<br />has<br />abundant,<br />material,<br />on,<br />all,<br />skills. </p> <div class=”blockbottompostion”>Position:static bottom:10%</div> </body> </html> Print Page Previous Next Advertisements ”;
CSS – Padding
CSS – Paddings ”; Previous Next CSS padding is used to creates extra space between border of element and it”s contents. In this article we will learn different types of padding and properties associated with it. What is CSS Padding? In CSS, padding is a property that is used to create additional spacing inside the boundary of an element. The default value for padding is zero. A padding value zero indicate that content (mostly text contents) will start from the border of element itself. CSS Padding Example You can try different ways to use to create padding in the below section and you can change the values as well. padding: 1em padding: 10px 0 padding: 10px 50px 20px padding: 10px 50px 20px 40px padding: 30px Try Different Padding Options Table of Contents Define Padding Padding Individual Sides Different Ways to Apply Padding Padding Percentage Values Padding Mix up Units Padding Properties Reference Define Padding To define any padding on any HTML element you can use CSS padding property, this property is shorthand property of ”padding-top”, ”padding-right”, ”padding-bottom” and ”padding-left” properties. A single value will generate padding all around the element. Syntax padding: “value”; Example As you can see in this below example we have generated 5px padding surrounding the paragraph element and highlight the padding area with light-green background. <!DOCTYPE html> <html> <head> <title>CSS Padding</title> <style> div{ background-color: lightgray; border: 1px solid black; } p { background-color: white; } </style> </head> <body> <h1>Tutorialspoint</h1> <h3>CSS Padding</h3> <div> <p style=”padding: 5px;”> CSS Padding Applied on Paragraph Element </p> </div> </body> </html> Padding Individual Sides As we have mentioned earlier the padding is shorthand property for all Individual sides padding. You can set different padding values for top, right, bottom and left sides. padding-top: This property is used to set the padding top on any element. padding-right: This property is used to set the padding right on any element. padding-bottom: This property is used to set the padding bottom on any element. padding-left: This property is used to set the padding left on any element. You can check the attached image for more clarity on individual side paddings. Syntax padding-top: “value”; padding-right: “value”; padding-bottom: “value”; padding-left: “value”; Example In this example we have create 4 different element and generated padding on each element”s individual sides with the above mentioned properties. <!DOCTYPE html> <html> <head> <title>CSS Padding</title> <style> div{ background-color: lightgray; border: 1px solid black; } p { background-color: lightgreen; border: 1px solid black; } span { background-color: white; } </style> </head> <body> <h1>Tutoriaslpoint</h1> <h3>CSS Padding</h3> <div> <p style=”padding-top: 15px;”> <span>CSS Padding Top Applied on Paragraph Element</span> </p> <p style=”padding-right: 15px;”> <span>CSS Padding Right Applied on Paragraph Element</span> </p> <p style=”padding-bottom: 15px;”> <span>CSS Padding Bottom Applied on Paragraph Element</span> </p> <p style=”padding-left: 15px;”> <span>CSS Padding Left Applied on Paragraph Element</span> </p> </div> </body> </html> All the left over space on the right side of the element can be confusing to identify the padding, if you try on your own by changing values it will clear the padding concept. And always remember negative values are not allowed for padding in CSS. Different Ways to Apply Padding on HTML Elements There are four ways to provide value to the CSS padding property all of them are mentioned and described bellow with the complete example code. Single Values: Here you can provide a single value to the padding property that same value will be applicable on four sides of the the element. Two Values: Here you have to provide two values that will be used as top, bottom and right, left padding value. Three Values: In this way you can provide three values that will define top, left, right and bottom value. Like if you set padding: 20px 40px 10px. In this case top padding will be 20px, right and left paddings will be 40px and bottom padding will be 10px. Four Values: If you provide four values to the padding property it will generate top padding from first value, right padding from 2nd value and so on. Syntax padding: “value” // Single Value padding: “value value” // Two Values padding: “value value value” // Three Values padding: “value value value value” // Four Values Example In this following example we have crated a four different element and used inline css to generate padding around the element in different ways. <!DOCTYPE html> <html> <head> <title>CSS Padding</title> <style> div{ background-color: lightgray; border: 1px solid black; } p { background-color: lightgreen; border: 1px solid black; } </style> </head> <body> <h1>Tutoriaslpoint</h1> <h3>CSS Padding</h3> <div> <p style=”padding: 20px”> <span>Padding property with Single Value</span> </p> <p style=”padding: 10px 20px”> <span>Padding property with two Values</span> </p> <p style=”padding: 10px 15px 20px”> <span>Padding property with three Values</span> </p> <p style=”padding: 5px 10px 15px 20px”> <span>Padding property with four Values</span> </p> </div> </body> </html> Padding Mix up Units CSS does not restrict usage of multiple units for specifying the values of padding, while specifying in shorthand property. That means one can pass values of length as pixel along with ems or inches, etc. Syntax h2 { padding: 20px 4ex .5in 3em; } Example In this following example we will provide 4 values on padding property but each value will be mentioned in different units.. <!DOCTYPE html> <html> <head> <style>
CSS – Border Inline
CSS – border-inline ”; Previous Next The CSS property border-inline is a shorthand property that sets the values for different logical inline border attributes, combining them into a single statement. The writing mode, directionality, and text orientation of the element determine how the border-inline attribute is mapped to actual boundaries. Depending on values of writing-mode, direction, and text-orientation, border-inline behaves as either border-top and border-bottom or border-right and border-left properties. Use the border-block property, which sets both border-block-start and border-block-end, to establish borders in other dimension. Possible values The border-inline is specified with one or more of the following, in any order: <”border-width”> – The width of the border. <”border-style”> – The line style of the border. <color> – The color of the border. Constituent properties This property is a shorthand for the following CSS properties: border-inline-color border-inline-style border-inline-width Syntax border-inline = <”border-block-start”> Applies to All the HTML elements. CSS border-inline – Basic Example The following example demonstrates the usage of border-inline CSS property. <html> <head> <style> .container { background-color: #ffeeba; width: 450px; height: 450px; display: flex; align-items: center; justify-content: center; font-size: 20px; border-radius: 10px; box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.6); } .custom-border { border-inline: 6px dashed #3498db; padding: 10px; font-weight: bold; color: #333; } </style> </head> <body> <div class=”container”> <p class=”custom-border”>A Example with border-inline property</p> </div> </body> </html> CSS border-inline – Writing Mode The following example demonstrates the usage of border-inline CSS property with vertical writing mode. <html> <head> <style> .container { background-color: #fed8b1; width: 400px; height: 400px; display: flex; align-items: center; justify-content: center; font-size: 18px; border-radius: 15px; box-shadow: 4px 4px 12px rgba(0, 0, 0, 0.6); writing-mode: vertical-rl; } .demo-border { border:4px solid black; border-inline: 0.9rem groove #e74c3c; padding: 10px; font-weight: bold; color: #333; } </style> </head> <body> <div class=”container”> <p class=”demo-border”>A border-inline example with vertical text.</p> </div> </body> </html> Related Properties The table given below lists some related properties: Property Description border-inline-width Defines the width of the logical inline borders of an element. border-inline-start-width Defines the width of the logical inline-start border of an element. border-inline-end-width Defines the width of the logical inline-end border of an element. border-inline-end A shorthand property for setting the individual logical inline-end border property border-inline-color Defines the color of the logical inline borders of an element. border-inline-start-color Defines the color of the logical inline start border of an element. border-inline-end-color Defines the color of the logical inline-end border of an element. border-inline-start A shorthand property for setting the individual logical inline-start border property. border-inline-style Defines the style of the inline border of an element. border-inline-start-style Defines the style of the logical inline start border of an element. border-inline-end-style Defines the style of the logical inline end border of an element. Print Page Previous Next Advertisements ”;