Versatile, stationary division - Looking to attach a different division at the bottom

Element A has a flexible and fixed position (at the top of the window) with a high z-index, allowing items below to pass underneath when scrolling.

Element B is positioned below Element A, and I want it to remain attached to the bottom of Element A while the height adjusts when resizing the window. The goal is to maintain a consistent margin between A and B.

I may have overcomplicated this issue, as the solution might be simple and right in front of me, yet I cannot seem to see it.

The HTML

<div id="A">
       some content
   </div>

   <div id="B">
       some content
   </div>
   

The CSS

#A {
      position: fixed;
      z-index: 200;
      width: 100%;
   }

   #B {
      position: relative;
      z-index: 100;
      width: 100%;
   }
   

Answer №1

x {
  position:fixed;
}

y {
  position:absolute;
  bottom:0;
}

My assumption is that this code will function properly, however I am unsure of how it will behave with the fixed positioning of element "x" instead of relative.

Answer №2

For A, I recommend incorporating B and following this approach

http://jsfiddle.net/NicoO/CAF3q/2/

CSS:

#a
{
    position: fixed;
    left:0;
    right:0;
    height: 200px;
    top:0;
    overflow: hidden;
    background-color: gray;
}

#b
{
    overflow: hidden;
    background-color: gold;
    position: absolute;
    bottom:0;
    left:0;
    right:0;

}

HTML:

<div id="a">
    <p>Content of any kind...</p>
    <p>Content of any kind...</p>
    <div id="b">
        <p>Feeling pressure from everyone 8(</p>
    </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for displaying nested components in React

I am currently facing a challenge involving rendering different database tables as HTML tables in React. The issue at hand is that each table has a different number of columns. In my component, I receive header data along with the full table data in JSON f ...

Leveraging the ng-hide property of one controller to adjust the ng-style attribute of another controller through a centralized global controller

Seeking assistance with accessing the boolean value of ng-hide from one controller in order to alter CSS properties of another controller utilizing a global controller. Here is the jsfiddle link: https://jsfiddle.net/dqmtLxnt/ HTML <div ng-controller= ...

Having trouble with multiple slideshows not functioning correctly. Any ideas on how to fix this

My current challenge involves setting up multiple slideshows on a single page with navigation dots to switch between each slideshow. The issue arises when I try to incorporate more than one slideshow, as the navigation dots either stop working or begin con ...

Is there a way to keep my <nav> positioned in the top right corner of my header?

I'm in the process of setting up a fresh homepage and I've implemented the code below: menu { width: 100%; height: 60px; background: rgb(0, 0, 0); z-index: 2; position: fixed; } #content { margin: 0 auto; width: 1024px; height: ...

Are there any inventive methods to dynamically populate HTML content directly from a URL?

My objective is not to avoid incorporating code (such as JavaScript) here, but rather to create a specific tool. Imagine I have a URL string like domain.com/something, which can produce either a single string like "John", or potentially JSON data dependin ...

Can you provide examples of design patterns commonly used in HTML and CSS?

Starting out with Ruby on Rails is exciting, but I am feeling overwhelmed by CSS and HTML. While there are plenty of books on CSS and HTML patterns, I am more interested in learning what is actually used on real webpages. For example, when creating a simpl ...

Remove the presence of a black square when selecting elements using CSS

Update: After some investigation, I discovered that the mysterious black square is actually a part of the scroll bar. By adding the following code snippet: select::-webkit-scrollbar { display: none; } The square no longer appears. Initially, my se ...

Issues with the use of overflow:hidden

I need to create 5 divs aligned horizontally next to each other, spanning the width and height of the window. Each div should occupy 20% of the window width, and any overflow content should be hidden. Below is the CSS code for two of the divs: #container1 ...

Locating the value of a data attribute from a distant parent div using jQuery

How can I access the closest div from an anchor tag that has a data-id attribute without using multiple parent() methods? Even though .parent().parent().parent() works, I am trying to find a better solution. <div class="panel panel-default" data-id="@ ...

How can I use jQuery to identify the numerical range within class/td/div elements and modify their CSS styles?

1# I need assistance in changing the CSS properties of a TD, Class, and div using a selector that specifies a specific number range. Specifically, I am looking to modify the css of torrent results with a seed count between 250-25000. Any torrents with a se ...

"Debunking the traditional class assignment concept: What happens when two different classes

While working on creating a <div> element for a thumbnail gallery, I encountered a situation where I needed to apply two different classes to the <div>. One class was for positioning and the other for styling. However, when I tried to combine t ...

Loading screen while all files and audio are being loaded

My JavaScript code is responsible for displaying and playing audio on my website. Unfortunately, the load time of the page is quite slow. To address this issue, I decided to follow a tutorial on installing a preloader, which can be found at . Although I ...

Is it possible to utilize the computed value from one query in a subsequent query?

I am performing a calculation for one parameter (X) in the following manner: <?php $link=mysql_connect("localhost","root",""); mysql_select_db("hand"); $result = mysql_query("select * from sessions",$link); $num_calls = mysql_num_rows($result); echo ...

The Bootstrap nav-justified feature fails to utilize the entire width available

Have you heard of the bootstrap-4 class called nav-pill? It's meant to make links have equal width and occupy all horizontal space. To achieve equal-width elements, simply use .nav-justified, as suggested. This will ensure that nav links take up al ...

Error 403 with Firefox on Font Loading for CodeIgniter Website

Utilizing font-face in CSS to integrate custom fonts onto a web application being developed with CodeIgniter. This is the CSS code: @font-face { font-family: 'UniversLT-UltraCondensed'; src: url('../Fonts/LTUnivers/universlt59ultrac ...

Display or conceal 5 divs simultaneously

A while back, I stumbled upon this amazing code that has been incredibly helpful. However, I am unable to locate the original author (whoever you are, THANK YOU)... http://jsbin.com/amituh/11/ It's truly awesome, but I would like to add another butt ...

Using SCSS to target a sibling class when hovering over an element with CSS

Is there a way to alter styles of a sibling element on hover using only CSS? I attempted something similar but was unsuccessful. HTML: <ul> <li class="item active">name1</li> <li class="item">name2</li> <li clas ...

What is the best way to calculate the sum of for-loop values in a Django template

Inside my Django template, I have a code snippet that looks like this: {% load mathfilters %} {% with total=0 %} {% for item in numbers %} {{ total | addition:item }} {% endfor %} {% endwith %} At the conclusion of this code, the total value remain ...

Creating a div that functions as a scrollbar controller

I am in search of a unique way to customize the scrolling functionality on my application, resembling more of a navbar that scrolls. However, I have not been able to find any existing plugins that meet my specific requirements. My inquiry includes: Whic ...

Angular4 - Div with ngIf doesn't respond to click event

I'm attempting to add a click event to a specific div. Within this div, there is another div that is dynamically generated based on a Boolean condition that I receive as input. Unfortunately, in this case, the click event is only functioning when clic ...