Ensure that the image remains positioned at the bottom of the page

Although it may seem like a repetitive question, the answers I have come across are quite unbelievable. Why would multiple lines of code be needed for such a simple task? It just doesn't make sense.

I specifically want to ensure that the img is located at the very end of the page, not just at the bottom of the displayed screen - as I am currently experiencing this issue.

Here is the code that I'm using now:

#footerimg {
  position: absolute;
  right: 0px;
  bottom: 0px;
  z-index:-2;
}

I am looking for a solution where the image will only become visible once I scroll to the very bottom of the page.

It's baffling to think that there isn't a CSS option like bottom-page:0px.

EDIT: https://i.sstatic.net/pVnns.jpg

Answer №1

Discover the power of CSS transform property with the application of transform: translateY(100%).

Check out the demonstration below:

#footerimg {
  position: absolute;
  right: 0px;
  bottom: 0px;
  z-index:-2;
  transform: translateY(100%);
}
<img id="footerimg" src="http://placehold.it/200x200"/>

UPDATE:

Reviewing the image provided in the question, it seems that positioning is unnecessary - simply place the img as the last element in the HTML markup.

A potential solution could look like this:

.content {
  height: 120vh;
}
section {
  text-align: right;
}
img {
  vertical-align: top;
}
<section class="content"></section>
<section>
  <img id="footerimg" src="http://placehold.it/200x200" />
</section>

Answer №2

To create a new block formatting context, you should define a positioned relative block-level element at the end of the body. This will ensure that all absolute positioned elements inside it are placed relative to it.

Take a look at this code snippet example:

body {
  width: 100%;
}
.blk1 {
  display: block;
  width: 100%;
  height: 500px;
  background: orange;
}
.blk2{
  display: block;
  width: 100%;
  height: 300px;
  position: relative;
  background: #9c9;
}
img.btm {
  position: absolute;
  bottom: 0;
  right: 0;
  opacity: 0;
  transition: opacity 1s ease; 
}
.blk2:hover .btm {
  opacity: 1;
}
<div class="blk1">
</div>
<div class="blk2">
<img src="//placehold.it/100/100" class="btm">
</div>

Here is an alternative solution:

body {
  width: 100%;
  position: relative;
}
.blk1 {
  display: block;
  width: 100%;
  height:200vh;
  background: orange;
}
body:after {
  content: "";
  display: block;
  position: absolute;
  bottom: 0;
  right: 0;
  width: 100px;
  height: 100px;
  background-image: url('//placehold.it/100/100');
}
<div class="blk1">
    </div>

To apply the above solution, simply add position: relative to the body CSS styles.

body {
  position: relative;
}

Then include body:after:

body:after {
  content: "";
  display: block;
  position: absolute;
  bottom: 0;
  right: 0;
  background-image: url('//placehold.it/100/100');
}

Answer №3

I find your question a bit confusing as you mentioned needing to scroll to the bottom of the page to see an image.

My suggestion is to simply place the image under the footer container. This way, when you reach the bottom of the page, the image will be right there. No need for any complex coding tricks, just a traditional approach.

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

Is it possible to implement a hover animation within another hover animation in WordPress?

Trying to incorporate two hover animations for the images in my photo galleries. When hovering over an image, I want a text to appear in a black overlay, and then when hovering over that text, it should become underlined. Looking for something similar to ...

The WebView in HTML5 does not support the navigator.online feature

I'm currently building a hybrid application that combines Android with offline HTML5 pages stored in the Android asset. Unfortunately, I am facing an issue where navigator.online is not functioning properly in the Android Webview. Any assistance would ...

Disabling Sidebars on Blog Articles Exclusively for Mobile Devices

I own the website Onthecomeupartists.com and am currently using the Impreza Theme 2.10 on WordPress 4.5.2. However, I want to enhance the mobile compatibility of my site by removing the sidebar on blog posts when viewed on mobile devices only, while keepin ...

How do you eliminate row highlighting on the <TableRow> component within Material-UI's <Table> using ReactJS?

I am facing an issue with a table and row highlighting in my code. Even after clicking on a row, it remains highlighted. I attempted to use the <TableRow disableTouchRipple={true}> but it didn't work as expected. What can I do to remove the high ...

Alignment within bootstrap using accordion

I am new to using bootstrap. Currently, I am creating a simple FAQ page with bootstrap and facing some challenges. https://i.sstatic.net/6fUW3.png I have been trying to adjust the position and margin of elements, but I am struggling to center the title a ...

React Native CSS Triangles not functioning anymore

I'm currently developing an application that involves triangles overlaying other containers and divs. This issue was previously resolved using CSS with the following code: .triangle:after { content: ""; display: block; position: absolu ...

"Discover the process of utilizing jQuery to trigger an action when scrolling past a

I'm currently working with this code snippet: #main { max-width: 500px; height: 900px; margin: auto; background: green } .menu1 { height: 30px; background: red } .menu2 { display: none; } <div id="main"> <div class="menu1"& ...

Alter the color of the initially chosen option in the dropdown selection

I'm struggling to modify the color of the initial selection while keeping the remaining selection-options at their default black color. Unfortunately, I haven't been successful in achieving this. Currently, all colors are #ccc. What I want is fo ...

Positioning a box at the bottom rather than at the top

I am on the lookout for a solution to shift/arrange divs to the bottom instead of the top. For example, when attempting to delete some of the divs with the "box" class in this code snippet: Current code: #hol ...

Finding and removing a specific CSS pattern from a webpage that has been loaded

Encountered a troublesome Amazon.com page that appears blank in print preview, specifically the Online Return Center\Your Return Summary page. After much troubleshooting on a locally saved copy of the webpage, I pinpointed the issue to a problematic l ...

JavaScript Age confirmation Overlay

I designed an age verification popup with the help of some online tutorials and a friend due to my limited knowledge of JavaScript. Check it out live here- My issue is that I want this popup to load/appear after the page content loads, but I'm not s ...

Creating a dynamic navbar in an ASP.NET website by populating it with data from a

Seeking guidance on creating a dynamic Bootstrap navbar in an ASP.NET website based on the user's role stored in a database, while maintaining the same style. I have extensively searched for a solution without success. Any assistance would be greatly ...

Creating a Collage with Varied Image Sizes

Hey there, I'm trying to achieve something that seems simple, but I can't quite figure it out. What I want to do is query a table and display the results in two separate divs on my webpage. Here's an example of the HTML structure I have: &l ...

Hierarchy in CSS: The battle between author and user styling

Following a hierarchy of precedence: User agent declarations User normal declarations Author normal declarations Author important declarations User important declarations The CSS specification distinguishes between author and user: Author. The author s ...

What is the best way to keep my bottom navigation bar attached to my top navigation bar?

I am facing an issue with my two navbars. The top navbar sticks to the top of the page when the user scrolls down, which works perfectly fine. However, when the user logs in, the bottom navbar becomes visible. Unfortunately, the bottom navbar is not sticky ...

What is the best way to efficiently pass a prop from a Parent styled component to its children's styled components, regardless of how deeply nested they are?

I am utilizing these customized components: import styled, { css } from 'styled-components' const Container = styled.div` background-color: ${props => props.theme === "light" ? "hsl(0, 0%, 98%)" : "hsl(235, 24%, 19% ...

Execute the script when the document is fully loaded

Is there a way to show a dialog in jQuery when the document loads without using <body onload="showdialog();">? Can the javascript code be placed in the main div or footer div to work like the onload event? <body onload="$('#dialog').sli ...

Tips for showcasing cards in a horizontal inline layout

Hello everyone! I'm currently working on creating dynamic cards, but I'm having trouble displaying them inline. I'd like to arrange the cards horizontally with a scroll bar. https://i.sstatic.net/zqcua.png I want to make them display in ho ...

Performing a subtraction operation using HTML5 and JavaScript

While I wish I could write about something more exciting than value subtraction, unfortunately that's not the case. In a game scenario where asteroids are approaching the player, who has the ability to move around, the intention is for the player&apos ...

The navigation menu collapses upon itself when resizing the browser window

Every time I try to adjust the browser size, the navigation menu seems to collapse within itself, creating a strange effect. I can't figure out what's causing this issue. I've experimented with max-width and sometimes including the "wrapper ...