0

I'm trying to put this <hr> and text at the bottom of the page, so once the page loads it will stay at the bottom of the page even if I open developer tools in the browser.

It looks like this:

Screenshot

My code is currently like this:

<div class="container body-content">
    @RenderBody()
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year</p>
    </footer>
</div>

I've tried wrapping hr and footer in a div, giving it id and css style

#footer {
position: absolute;
bottom: 0px;
}

but it causes <hr> to shrink from current width to the width of text date below it. If I add width: 100% in css, <hr> extends all the way to the right side of the screen, meanwhile I want it to be same as the current width. I've also tried giving wrapping <div> class="container" which almost do the job, but then it moves text a bit to the right, so it's not aligned with the text fields and submit button. How can I solve this?

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
  • 2
    I would consider putting the `
    ` and `
    ` outside of your div as it could be causing a problem if you have something in your CSS.
    – Ryan C Sep 26 '18 at 15:05
  • I guess you are looking for sticking
    always at bottom, even if body height changes. https://stackoverflow.com/a/19723677/1129978 will be helpful.
    – Himalaya Garg Sep 26 '18 at 15:09
  • @HimalayaGarg from the demo on Matthew's page, his footer moves up as soon as I open developer tools in the browser, meanwhile I would like to render the footer at the bottom of the screen when the page loads and to leave it there even if developer tools (or something else) get opened. – Rick Jabels Sep 26 '18 at 15:26
  • @RyanC that's default markup of asp.net application. I assume they put it there, so `
    ` and `
    ` get a nice border on both side of the screen, so I would leave it as is, just to move it down.
    – Rick Jabels Sep 26 '18 at 15:28

1 Answers1

0

HTML:

<div class="container">
    <div class="form">
        <h2>Login</h2>
        <input type="text" placeholder="email">
        <input type="text" placeholder="password">
        <button>Sign In</button>
    </div>

    <footer class="footer-width">
        <div class="inner">
        <p>&copy; @DateTime.Now.Year</p>
        </div>
    </footer>
</div>

CSS:

footer {
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
}

.inner {
    border-top: 1px solid black;
    width: 100%;
}

input {
    display: block;
    margin-bottom: 15px;
}

button {
    margin-bottom: 15px;
}

.container {
    width: 75%;
    margin: 0 auto;
}
CodeBoyCode
  • 2,227
  • 12
  • 29
  • Yes, I've tried that as I explained in the OP, but [this is what I get](https://image.ibb.co/foqee9/1.png). `
    ` goes all the way to the right side, meanwhile I want it to keep its original width like on the first picture. I assume it gets its width from the parent div, but dunno how to place it there.
    – Rick Jabels Sep 26 '18 at 15:19
  • I have updated my answer and it's cleaner and it works - I would recommend using a border on the footer instead of a
    so it will always be the same size and it's easier to manage.
    – CodeBoyCode Sep 26 '18 at 15:53
  • Thanks for the edit, but seems like maybe I didn't explain clearly. When I add the code from the edit. [this is what I get](https://i.imgur.com/oh8bfdJ.png), meanwhile I'm trying to achieve [this](https://i.imgur.com/QJGBzLs.png). So the `
    ` or border-top in your code, to be align with the form itself and just to put it at the bottom of the page.
    – Rick Jabels Sep 26 '18 at 16:13
  • Awww man i'm really sorry, I totaly missunderstood - check my latest code pen https://codepen.io/CodeBoyCode/pen/dqxqLp – CodeBoyCode Sep 26 '18 at 16:24
  • I'm sorry, but I tried the code you posted, even on codepen website, footer is just below the login button and not at the bottom of the page as it should be. Width is correct now. – Rick Jabels Sep 26 '18 at 16:37