CSS: how to position element in lower right?

后端 未结 2 2161
忘了有多久
忘了有多久 2020-12-12 17:34

I am trying to position the text element \"Bet 5 days ago\" in the lower right-hand corner. How can I accomplish this? And, more importantly, please explain so I can conqu

相关标签:
2条回答
  • 2020-12-12 18:29

    Lets say your HTML looks something like this:

    <div class="box">
        <!-- stuff -->
        <p class="bet_time">Bet 5 days ago</p>
    </div>
    

    Then, with CSS, you can make that text appear in the bottom right like so:

    .box {
        position:relative;
    }
    .bet_time {
        position:absolute;
        bottom:0;
        right:0;
    }
    

    The way this works is that absolutely positioned elements are always positioned with respect to the first relatively positioned parent element, or the window. Because we set the box's position to relative, .bet_time positions its right edge to the right edge of .box and its bottom edge to the bottom edge of .box

    0 讨论(0)
  • 2020-12-12 18:31

    Set the CSS position: relative; on the box. This causes all absolute positions of objects inside to be relative to the corners of that box. Then set the following CSS on the "Bet 5 days ago" line:

    position: absolute;
    bottom: 0;
    right: 0;
    

    If you need to space the text farther away from the edge, you could change 0 to 2px or similar.

    0 讨论(0)
提交回复
热议问题