Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Extending Image Past Edge of Browser Window

An image with part of itself extending past the edge of the browser window is relatively unusual. Which attracts the eye.

Examples are an image of a business card, a product image, or a logo. Perhaps a calendar. Or a currency symbol.

The image can extend past the left or top edge of the browser window or be tucked into the top-left corner.

The CSS position:absolute definition is used for these. The images will scroll with the content of the page.

(To have the image stay in position within the browser window when scrolling, use position:fixed, instead. The CSS Positioning page and the How to Position Text and Images Exactly and Relatively page have more positioning information.)

Put the img tag near the bottom of the web page. That's so, when it's positioned, it will be layered over anything it may overlap.

Example code below shows how to give the image a position:absolute definition to place it exactly where you want it. Position it so part of the image extends past the edge of the window.

The part of the image that extends past the edge will not be visible on the page, as the image will be cropped. The part that is visible will extend all the way to the edge.

Positioning the Image

For the example code, I'll use the WebSite's Secret logo:

<img 
   src="//www.willmaster.com/08images/wslogo150x156.jpg" 
   width="150" 
   height="156" 
   border="0" 
   alt="WebSite's Secret logo">
   
   

To give the image a position:absolute definition, insert a style attribute into the img tag.

Extending image past the left edge of browser window.
<img 
   style="position:absolute; left:-25px; top:200px;" 
   src="//www.willmaster.com/08images/wslogo150x156.jpg" 
   width="150" 
   height="156" 
   border="0" 
   alt="WebSite's Secret logo">
   
   

Note the style attribute with its CSS definition:

style="position:absolute; left:-25px; top:200px;"

The minus value for the left definition extends the left side of the image 25 pixels past the left edge of the window. The top definition puts the top of the image 200 pixels down from the top of the window.

Extending image past the top edge of browser window.
style="position:absolute; top:-25px; left:200px;"

The minus value for the top definition extends the top of the image 25 pixels above the top edge of the window. The left definition puts the left side of the image 200 pixels in from the left edge of the window.

Tucking image into the top-left corner.
style="position:absolute; top:-25px; left:-25px;"

The minus value for the top definition extends the top of the image 25 pixels above the top edge of the window. The minus value for the left definition extends the left side of the image 25 pixels past the left edge of the window.

The CSS position:absolute definition positions the image relative to the first parent element that has a position other than static. In other words, if the image is in a div (or other element) that itself has a position definition (except position:static;), then the position of the image will be relative to that div rather than relative to the <body...> tag.

If the image does not position itself as expected, you may have encountered what the above refers to. You can either:

  • Adjust the top and left definitions until the image is in the position you want it.

Or:

  • Move the image tag to almost near the bottom of the source code, immediately above the page's closing </body> tag. The img tag should then be beyond the influence of any element of the type referred to above.

It is also possible to position images to extend past the right and bottom edges of the browser window and to tuck them the other three corners. However, at least on some browsers, this creates a scrollbar that, when used, reveals the entire image.

In other words, the positioning is within the non-scrolled browser window - the content visible in the window when the page first loads. Scrollbars are created or adjusted as needed to accomodate the positioning.

Extending image past the right edge of the non-scrolled browser window.
style="position:absolute; right:-25px; top:200px;"

The minus value for the right definition extends the right side of the image 25 pixels past the right edge of the non-scrolled window. The top definition puts the top of the image 200 pixels down from the top of the window.

Extending image past the bottom edge of the non-scrolled browser window.
style="position:absolute; bottom:-25px; left:200px;"

The minus value for the bottom definition extends the bottom of the image 25 pixels below the bottom edge of the non-scrolled window. The left definition puts the left side of the image 200 pixels in from the left edge of the window.

Tucking image into the top-right corner of the non-scrolled browser window.
style="position:absolute; top:-25px; right:-25px;"

The minus value for the top definition extends the top of the image 25 pixels above the top edge of the non-scrolled window. The minus value for the right definition extends the right side of the image 25 pixels past the right edge of the window.

Tucking image into the bottom-right corner of the non-scrolled browser window.
style="position:absolute; bottom:-25px; right:-25px;"

The minus value for the bottom definition extends the bottom of the image 25 pixels past the bottom edge of the non-scrolled window. The minus value for the right definition extends the right side of the image 25 pixels past the right edge of the window.

Tucking image into the bottom-left corner of the non-scrolled browser window.
style="position:absolute; bottom:-25px; left:-25px;"

The minus value for the bottom definition extends the bottom of the image 25 pixels past the bottom edge of the non-scrolled window. The minus value for the left definition extends the left side of the image 25 pixels past the left edge of the window.

With this article as a guide, images can be extended past the edge of the browser window using the CSS position:absolute definition. The images will scroll with the content of the page. (Use position:fixed for non-scrolling images.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC