html - Stretch the height of the parent to the height of the absolute element with css - Stack Overflow

I have a section element which should be floated above the header. But should not hide the footer below

I have a section element which should be floated above the header. But should not hide the footer below. Is there a way to do it using css alone?

function App() {
  return (
    <div className="container">
      <header>
        <h1>Header</h1>
      </header>

      <div className="absolute-child">
        Absolute child with dynamic content. .
      </div>

      <footer>
        <h2>Footer</h2>
      </footer>
    </div>
  );
}

The div absolute-child has dynamic content and its height can vary.

body,
html {
  margin: 0;
  padding: 0;
}

header {
  background-color: violet;
  height: 20rem;
}

.absolute-child {
  background-color: aquamarine;
  position: absolute;
  top: 3.5rem;
  width: 90%;
  padding: 1rem;
  height: 120vh;
}

footer {
  background-color: lightcoral;
  text-align: center;
  padding: 1rem;
}

How to fix it with css so that the footer is not hidden when the height of the absolute-element increase?

Tried using a ghost element along with the absolute element to stretch the height but it doesnt seem to work.

I have a section element which should be floated above the header. But should not hide the footer below. Is there a way to do it using css alone?

function App() {
  return (
    <div className="container">
      <header>
        <h1>Header</h1>
      </header>

      <div className="absolute-child">
        Absolute child with dynamic content. .
      </div>

      <footer>
        <h2>Footer</h2>
      </footer>
    </div>
  );
}

The div absolute-child has dynamic content and its height can vary.

body,
html {
  margin: 0;
  padding: 0;
}

header {
  background-color: violet;
  height: 20rem;
}

.absolute-child {
  background-color: aquamarine;
  position: absolute;
  top: 3.5rem;
  width: 90%;
  padding: 1rem;
  height: 120vh;
}

footer {
  background-color: lightcoral;
  text-align: center;
  padding: 1rem;
}

How to fix it with css so that the footer is not hidden when the height of the absolute-element increase?

Tried using a ghost element along with the absolute element to stretch the height but it doesnt seem to work.

Share asked Mar 9 at 1:00 WebRTC NewbieWebRTC Newbie 54 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Remove the position: abolute; top: 3.5rem; and use translate: 0 -1.5rem; to paint the element over the header:

body,
html {
  margin: 0;
  padding: 0;
}

header {
  background-color: violet;
}

.absolute-child {
  translate: 0 -1.5rem;
  background-color: aquamarine;
  width: 90%;
  padding: 1rem;
  height: 120vh;
}

footer {
  background-color: lightcoral;
  text-align: center;
  padding: 1rem;
}
<div class="container">
  <header>
    <h1>Header</h1>
  </header>

  <div class="absolute-child">
    Absolute child with dynamic content. .
  </div>

  <footer>
    <h2>Footer</h2>
  </footer>
</div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744881332a4598855.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信