Bottom in CSS Language

Bottom in CSS Language

When it comes to positioning elements in CSS, various properties like “position,” “top,” “left,” &#

8220;right,” and “bottom” play a crucial role. In this article, we’ll focus on the “bottom” property and how it can be used to control the vertical position of elements within a web page.

The “bottom” property is typically used in combination with the “position” property, which defines the type of positioning an element should have. There are four common values for the “position” property:

  1. static: This is the default value, and elements are positioned according to the normal flow of the document.
  2. relative: When an element has a position: relative; property, the “bottom” value can be used to move the element from its normal position, relative to itself.
  3. absolute: Elements with a position: absolute; property are positioned relative to their nearest positioned ancestor, or the initial containing block if there is no such ancestor.
  4. fixed: Elements with a position: fixed; property are positioned relative to the viewport, which means they stay in the same place even when the page is scrolled.

Let’s dive into some practical examples to understand how the “bottom” property works in different scenarios:

Example 1: Using “bottom” with position: relative;

.relative-box {
  position: relative;
  bottom: 20px;
}

In this example, a div element with the class “relative-box” will be moved 20 pixels up from its normal position.

Example 2: Using “bottom” with position: absolute;

.parent {
  position: relative;
}

.absolute-box {
  position: absolute;
  bottom: 10px;
}

In this case, the “absolute-box” element is placed at the bottom of the “parent” element, but with a 10-pixel gap.

Example 3: Using “bottom” with position: fixed;

.fixed-box {
  position: fixed;
  bottom: 0;
}

This code ensures that the “fixed-box” element stays fixed to the bottom of the viewport.

Remember, the “bottom” property is just one piece of the positioning puzzle in CSS. It works in conjunction with other positioning properties, and it’s essential to consider the overall layout and the desired effect when using it. Also, keep in mind that it may not work as expected if the parent elements don’t have a defined height or if there are conflicting positioning properties.


Discover more from PiEmbSysTech

Subscribe to get the latest posts sent to your email.

Leave a Reply

Scroll to Top

Discover more from PiEmbSysTech

Subscribe now to keep reading and get access to the full archive.

Continue reading