Is there a way to create a flex component that stays fixed at the bottom of the browser, while still allowing the top

Currently, I am working with a third-party component that utilizes display:flex. The component is functioning correctly in terms of its top position, but my objective is to have the bottom of the component remain fixed to the bottom of the browser window.

If you'd like to see the code, feel free to check it out here: https://codesandbox.io/s/18ox21zqm4

const App = () => (
  <div>
    <Menu fixed="top" inverted>
      <Container>
        <Menu.Item as="a" header>
          Navbar
        </Menu.Item>
        <Menu.Item as="a">Home</Menu.Item>
      </Container>
    </Menu>

    <div style={{ position: "fixed", top: "100px" }}>
      <Header as="h1">Dynamic Height Content</Header>

      <TextArea placeholder="This container height may grow or shrink based on content." />
      <Segment style={{ backgroundColor: "red" }}>
        <Grid>
          This particular third-party component using display:flex should be positioned just below the above component's placement and have its bottom fixed to the bottom of the browser window (resizing accordingly).
        </Grid>
      </Segment>
    </div>
  </div>
);

render(<App />, document.getElementById("root"));

I attempted placing the component within a div with both top and bottom positions set to fixed. I utilized a reference to this div in order to capture the height and calculate the appropriate height for the flex component. However, the height gathered from the reference does not dynamically update upon window resizing, only after a browser page reload.

I am seeking advice on how best to achieve my desired outcome. Any suggestions would be greatly appreciated!

Answer №1

Performing a task in the following manner is possible, however, it is generally considered poor coding practice (I currently lack sufficient reputation to leave a comment)

<Segment style={{ backgroundColor: "red", height: "100vh" }}>

Answer №2

Here is the HTML output you requested:

<div style="position: fixed; top: 100px; bottom: 0px;">
  ...
  <div class="ui segment" style="background-color: red;">
    <div class="ui grid" style="height: 100%;">This third-party component uses display:flex and should align below the above component at the top, while staying fixed to the bottom of the browser window (adjusting with window resizing).</div>
  </div>
</div>

If your <div class="ui segment"> does not have a set height, applying height: 100% to <div class="ui grid"> will not work as intended. Instead, assign the height: 100% property to the wrapping <div class="ui segment">, so it can expand to fill the space defined by its parent.

<div style={{ position: "fixed", top: "100px", bottom: "0px" }}>
  <Header as="h1">Dynamic Height Content</Header>

  <TextArea placeholder="This container's height may change based on its content." />
  <Segment style={{ backgroundColor: "red", height: "100%" }}>
    <Grid>
      This third-party component, using display:flex, should be positioned just below the preceding element at the top, while remaining fixed to the bottom of the browser window (adjusting with window resizing).
    </Grid>
  </Segment>
</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

Guide on uploading and displaying images in MySQL database with React, Fetch API, and Node.js

Is it possible to save an image to a MySQL database by using and then display it on an element with the help of Node.js and React? Here is the Node.js code snippet: const { ISBN, publisher, category, edition, image, title, price, quantity, author } = r ...

Remove all styling applied through Javascript

If we consider the following scenario: var e = document.getElementById("someElement"); e.style.borderColor = "gold"; e.style.background = "yellow"; e.style.padding = "5px"; // more style changes made through javascript It's possible that additional ...

Header and footer that stick in place while content scrolls automatically

To create a layout where the header and footer remain sticky while the content has a minimum height and shows a scrollbar when the viewport is too small, I found success with this codepen: http://codepen.io/DlafCreative/pen/wzdOEN inspired by another sourc ...

Error encountered in typescript when trying to implement the Material UI theme.palette.type

Just starting out with Material UI and TypeScript, any tips for a newcomer like me? P.S. I'm sorry if my question formatting isn't quite right, this is my first time on Stack Overflow. https://i.stack.imgur.com/CIOEl.jpg https://i.stack.imgur.co ...

The behavior of -webkit-border-radius differs from that of -moz-border-radius

My website is displaying differently on Safari compared to Firefox. I want the CSS to make it look consistent across both browsers. I understand that I could use two div boxes - one for the outline and one for the image. However, I prefer how Firefox only ...

React Error: Unable to Call function this.state.Data.map

I'm encountering an issue with mapping objects in ReactJS. Even though I am able to fetch data, when I try to map it, I receive the following error: this.state.Data.map is not a function Here's the code snippet: import React, { Component } fro ...

What steps should I take to create a Python API to support a React/JavaScript frontend?

My goal is to create a website that combines a React/JS frontend with a Python backend that interacts with AWS Lambda, EC2, and other services. Users will log in through GitHub OAuth. Through my research and reading, it appears that using Flask and deploy ...

IE failing to display bottom border properly

In all browsers, my divs display with rounded borders except for IE. I believe I need to add some compatibility CSS. Check out this link for more details. Here is the HTML code: <div class="upper_button"> <a href="http://www.yahoo.com/" tar ...

Retrieving information from an API and incorporating it into JSX results in displaying text within the HTML element

I have retrieved data from an API with the following response: { "name": "family: woman, woman, girl, girl", "unicode": "1F469 200D 1F469 200D 1F467 200D 1F467", "html": "&#128 ...

Is there a way to alter the color of radio buttons?

Is there a way to use CSS to change the background color of a radio button? I've searched online, but all the solutions I found involve JavaScript, which I don't fully understand. I attempted this CSS code, but it didn't have the desired eff ...

Remove bulleted list from HTML using JavaScript DOM

My task involved deleting the entire "agent" array using the removeChild() function, requiring the id of a <ul> element. However, I faced an issue as I couldn't set the id for the "ul" due to using the createElement() function. //old code < ...

What is the best way to hide the background of an extension's HTML?

Currently, I am working on developing a Chrome extension for a university project. However, I am facing challenges in making the background or body of the extension's HTML completely transparent to achieve a cleaner interface. The issue specifically l ...

How can I implement the ternary operator in React Native and resolve my code issue?

Hello, I'm looking to implement the ternary operator in my code. Specifically, I want to render a FlatList if `cookup` has a value. However, if `cookup` is an empty array, I want to display some text instead. <FlatList data={cookUp} ...

What is the best way to align this button to the right?

I'm really struggling with this issue and could use some assistance. I've been trying to place this green button on the right side since yesterday, but traditional methods like using margin aren't working. HTML <ion-header> &l ...

The error message "getStaticPaths is not a valid method in NextUI/NextJS"

Encountering a Type Error: getStaticPaths is not a function specifically when using NextUI components like Buttons or Chips is becoming a roadblock for me. This issue has resurfaced, and the previous solution that worked before does not seem to be effecti ...

Navbar in Bootstrap 3 is overlapping

Below is the code snippet I am using on my website to implement a menu with Bootstrap 3: <html> <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bd ...

Obtain the array of children from an object using ES6 filtering techniques

I came across this data structure: parent = [{ child1 : [ {value:'Jhon', selected:false, status:false}, {value:'Marie', selected:false, status:false}, {value:'Less', selected:false, status:false}, ], child2 : [ {val ...

Limiting the number of rows in an HTML table: a comprehensive guide

Need help with displaying item names in a table with a limit of three rows. If there are more than 3 items, the 4th item should move to the second column, and if there are more than 6 items, the 7th item should go in the third column. Currently, I am using ...

Ways to enlarge the diameter of the inner circle

I've implemented some CSS with JQuery, as seen in this JSFiddle. However, I'm having trouble increasing the width and height of the green circle to be slightly larger than the gray circle (referred to as the main circle) which is positioned at a ...

Send Material UI designs to a React component

I am currently working with a functional component in React, where I need to display an SVG Icon based on the state. I am aiming to dynamically load the relevant icon based on the state. Therefore, in the parent component, I only want to include: <icon ...