Home  >  Q&A  >  body text

Set the bottom to 100% of its own height

I want to set up an element so that it is hidden from the page view and its top just touches the bottom of the page (the element is out of view). When the height of the element is constant 66px, I first do botttom: -66px;' . But now I need this to handle elements of any size.

If I do bottom: -100%; it sets it to 100% of the parent's size. How can I set it to -100% of its own height.

P粉098417223P粉098417223168 days ago1425

reply all(1)I'll reply

  • P粉005105443

    P粉0051054432024-04-05 15:26:28

    You are looking for "position:fixed" and "transform:translateY(100%);". This allows you to move the div 100% out of the viewport, regardless of the div's height.

    Example:

    div {
      position: fixed;
      bottom: 0px;
      left: 0px;
      width: 100%;
      height: 40px;
      background-color: red;
      color: #fff;
      transform: translateY(100%);
    }

    reply
    0
  • Cancelreply