bottom
The bottom CSS property participates in setting the vertical position of a positioned element. It has no effect on non-positioned elements.
The effect of bottom depends on how the element is positioned (i.e., the value of the position property):
- When position is set to absolute or fixed , the bottom property specifies the distance between the element’s bottom edge and the bottom edge of its containing block.
- When position is set to relative , the bottom property specifies the distance the element’s bottom edge is moved above its normal position.
- When position is set to sticky , the bottom property is used to compute the sticky-constraint rectangle.
- When position is set to static , the bottom property has no effect.
When both top and bottom are specified, position is set to absolute or fixed , and height is unspecified (either auto or 100% ) both the top and bottom distances are respected. In all other situations, if height is constrained in any way or position is set to relative , the top property takes precedence and the bottom property is ignored.
Syntax
Values
A negative, null, or positive <length> that represents:
- for absolutely positioned elements, the distance to the bottom edge of the containing block.
- for relatively positioned elements, the distance that the element is moved above its normal position.
A <percentage> of the containing block’s height.
- for absolutely positioned elements, the position of the element is based on the top property, while height: auto is treated as a height based on the content; or if top is also auto , the element is positioned where it should vertically be positioned if it were a static element.
- for relatively positioned elements, the distance of the element from its normal position is based on the top property; or if top is also auto , the element is not moved vertically at all.
Specifies that the value is the same as the computed value from its parent element (which might not be its containing block). This computed value is then handled as if it were a <length> , <percentage> , or the auto keyword.
Formal definition
Initial value | auto |
---|---|
Applies to | positioned elements |
Inherited | no |
Percentages | refer to the height of the containing block |
Computed value | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, auto |
Animation type | a length, percentage or calc(); |
Formal syntax
Examples
Absolute and fixed positioning
This example demonstrates the difference in behavior of the bottom property, when position is absolute versus fixed .
bottom
The bottom CSS property participates in specifying the vertical position of a positioned element. It has no effect on non-positioned elements.
The effect of bottom depends on how the element is positioned (i.e., the value of the position property):
- When position is set to absolute or fixed , the bottom property specifies the distance between the element’s bottom edge and the bottom edge of its containing block.
- When position is set to relative , the bottom property specifies the distance the element’s bottom edge is moved above its normal position.
- When position is set to sticky , the bottom property behaves like its position is relative when the element is inside the viewport, and like its position is fixed when it is outside.
- When position is set to static , the bottom property has no effect.
When both top and bottom are specified, and height is unspecified or either auto or 100% , both the top and bottom distances are respected. In all other situations, if height is constrained in any way, the top property takes precedence and the bottom property is ignored.
Initial value | auto |
---|---|
Applies to | positioned elements |
Inherited | no |
Percentages | refer to the height of the containing block |
Media | visual |
Computed value | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, auto |
Animation type | a length, percentage or calc(); |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
Syntax
Values
- for absolutely positioned elements, the distance to the bottom edge of the containing block.
- for relatively positioned elements, the distance that the element is moved above its normal position.
- for absolutely positioned elements, the position of the element is based on the top property, while height: auto is treated as a height based on the content.
- for relatively positioned elements, the distance of the element from its normal position is based on the top property, or if top is also auto , the element is not moved vertically at all.
Formal syntax
Example
This example demonstrates the difference in behavior of the bottom property, when position is absolute versus fixed .
CSS: bottom property
This CSS tutorial explains how to use the CSS property called bottom with syntax and examples.
Description
The CSS bottom property defines the bottom position of an element in combination with the position property.
Syntax
The syntax for the bottom CSS property is:
Parameters or Arguments
The bottom value when positioning an element using the position property. It can be one of the following:
Value | Description |
---|---|
fixed | Fixed value expressed in pixels, em’s, etc. div < position: relative; bottom: 8px; > div |
percentage | Percentage value div |
auto | This is the default behavior div |
inherit | Indicates that the element will inherit the bottom from its parent element div |
- When the value is provided as a percentage, it is relative to the height of the containing block.
- If the position property is set to relative, absolute, or fixed, you can set the bottom, right, bottom, and left properties.
- If the position property is set to static, he bottom, right, bottom, and left properties do not apply.
- See also the position, top, right, and left properties.
Browser Compatibility
The CSS bottom property has basic support with the following browsers:
- Chrome
- Firefox (Gecko)
- Internet Explorer (IE)
- static, relative, absolute: IE 4
- fixed: IE 7
Example
We will discuss the bottom property below, exploring examples of how to use this property in CSS.
Relative Position
Let’s look at an example where we set the position property to relative and set a value for the bottom property.
The CSS would look like this:
The HTML would look like this:
The result would look like this:
In this CSS position example, we have set the totn2 class to have a position of relative and the bottom property is set to 5px. What this means is that the div element (identified by the totn2 class) will be moved up from the bottom by 5px relative to where it would have been positioned in a normal layout.
Absolute Position
Let’s take a look at what would happen if we tried setting the position property to absolute for the second div and set a value for the bottom property.
The CSS would look like this:
The HTML would look like this:
The result would look like this:
In this CSS position example, we have set the totn2 class to have a position of absolute and the bottom property is set to 5px. What this means is that the div element (identified by the totn2 class) will be moved within its parent container to an absolute position of 5px from the bottom of the container.
So in this example, the second div in effect is positioned on top of the first div (identified by the totn1 class).
https://amdy.su/wp-admin/options-general.php?page=ad-inserter.php#tab-8Fixed Position
Let’s take a look at what would happen if we tried setting the position property to fixed for the second div and set a value for the bottom property.
The CSS would look like this:
The HTML would look like this:
The result would look like this:
In this CSS position example, we have set the totn2 class to have a position of fixed and the bottom property is set to 5px. What this means is that the div element (identified by the totn2 class) will be moved within the screen’s viewport to a fixed position of 5px from the bottom of the viewport.
It looks very similar to the result from the absolute position example. The only exception is that when we scroll with the fixed position example, the second div (identified by the totn2 class) will remain fixed within the screen’s viewport and will not scroll off of the screen.
CSS @bottom
By
Priya Pedamkar
Introduction to CSS @bottom
CSS Bottom is defined as the bottom property specifies the vertical position of an element added with the position property. It gives the offset at the bottom edge of the reference elements box in any browser window, an element that is altered from the bottom of the viewport. The bottom property does not affect the static position. In this topic, we are going to learn about CSS @bottom.
Syntax and Parameters
Here is the general Syntax as follows:
Web development, programming languages, Software testing & others
Parameters
The parameters define as follows:
- length: The value specified in px or em, either negative or positive values
- percentage: This value specifies the percentage of the box element height.
- auto: It’s a default value and treats height as a value.
- inherit: This value inherits its parent container value.
sample example
When a value is assigned a positive and negative value moves towards it, the element moves away from a given side. For instance, if the bottom: -15 px, This sets the paragraph below the bottom edge of a window.
How @bottom works in CSS?
Let’s see how this property works by its effect on different positioned elements.
Relatively positioned: When the position is set to this property, the bottom adds a respective offset to the bottom edge, which moves its position from its original form to its top. Generally, a top property overrides the bottom property in many aspects. An offset based on the bottom values is applied to the element itself.
Absolute position: With this, the element would move toward the nearest parent. Understanding this example is given in the next section.
Static: This is the default value and does not affect any element.
In the case of JavaScript, the Syntax given as follows
Examples
Let’s see how this bottom property works in action with an example:
Example #1
Let’s take an example – the effect on the absolute property.
Code:
Output:
Example #1a
We can place an image in the bottom property with the same pattern.
Code:
Output:
Example #2
With a position set to relative and using the value ‘Length’.
Code:
When a bottom is set on the element with respect to the relative position, the element moves up from the original placement of the document. Assigning the bottom to 60px, it shift its positions to the top.
Output:
Example #3
Setting a default value for the bottom property.
Code:
Output:
Example #4
Code:
Output:
Example #5
An example is demonstrating the bottom property on the Static element.
Code:
The code above shows static in which if I had happened to change the value of the right, bottom we could see the unchanged output.
Output:
Example #6
Code:
Here we could see a percentage value calculated on the bottom with absolute position. This code has two <div> classes with absolute positioning; the bottom value of the Abc class is 15, and xyz is zero. In the output, we can see the difference where the ‘0’ bottom value places the text on the bottom edge, whereas the 15 % value places the bottom text quite up.
Output:
Conclusion
Therefore, coming to an end, this CSS article explains how to use the Property called Bottom with their working and examples. Here we have seen a well-organized explanation with many examples of how to use this in CSS. This property, along with attributes like left-right, helps to display exact positions.
Recommended Articles
We hope that this EDUCBA information on “CSS @bottom” was beneficial to you. You can view EDUCBA’s recommended articles for more information.