Try this CSS hack: Display images in a row instead of stacking them vertically

Is there a clever trick or hack to make images load from left to right instead of top to bottom?

Any ideas on how to achieve this?

  • I've been thinking about rotating images 90° and then using CSS transformations to bring them back to normal while masking them. So far, I haven't had much luck with this approach. Does anyone have a better solution or trick for accomplishing this?

To clarify, I'm referring to a seemingly simple task which may not be so simple after all and might even be impossible.


Update: I am unsure where to begin... here is a sample fiddle with a large image that takes some time to load: http://jsfiddle.net/cfpqw9Lc/

<div class="img-container">
    <div class="img-inner">
        <img src="https://s3.amazonaws.com/f.cl.ly/items/0j0g2N1T2w3X0I3Y3Y3Z/dsc_2107.jpg" alt="Large Cat Image"/>
    </div>
</div>

Answer №1

One creative way to achieve a loading effect using only CSS is by leveraging absolute positioning and CSS animations. This clever "hack" involves covering an image with a div element and animating it off the image, creating the illusion of the image loading from the side.

Here's how you can implement this technique:

<div id="parent">
  <div id="child"></div>
  <img src="example.jpg"/>
</div>

To style the elements, apply the following CSS:

#parent {
  width: 500px;
  height: 500px;
  position: relative;
}

#child {
  position: absolute;
  right: 0;
  background-color: white;
  height: 500px;
  -webkit-animation: slider linear 10s;
  animation: slider linear 10s;
}
@-webkit-keyframes slider {
  from {width: 500px;}
  to {width: 0px;}
}
@keyframes slider {
  from {width: 500px;}
  to {width: 0px;}
}

You can view this technique in action on a live demo at: http://jsfiddle.net/74c983wr/

It's important to note that while this method creates the visual effect of images loading from the side, the images themselves will still load top to bottom as usual. Additionally, this approach works best with a solid background, although you can experiment with z-index manipulation to slide the actual image instead of just its cover.

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

Please ensure all information is completed before submitting

My registration page function is alerting users to fill in all required data, but the form is still submitting incomplete information. I need it to prevent submission until all fields are filled correctly. function checkdetails() { if (document.form ...

Responsive design in Android does not function as intended

My goal is to create a responsive design for my website, but I am encountering issues with importing the CSS files into the HTML. When I try to view the site in both the Windows version of Chrome and the Android version, all I see is a white screen. I am c ...

What could be the reason for the text covering the image on the larger breakpoint?

I am having an issue with this code where the Lorem Ipsum text is not staying centered at all times. Instead, it overlaps the image when I reach the large breakpoint. Can you please explain why this is happening and suggest a solution? Here is the curren ...

Problem occurs when tab links vanish after clicking on another part of the website

Exploring the world of Javascript as a newcomer has been quite an adventure, but I've encountered a hurdle with tab links on my website. Everything seems to be working fine – the links cycle through and display the correct content. However, when it ...

Is it the right time to dive into HTML5 & CSS3?

The excitement around HTML5 and CSS3 is hard to ignore. But when is the right time to start incorporating them into our projects? How close are we to fully utilizing their capabilities? Update: I'm not interested in following the principles of: Grac ...

Steps for eliminating redundant lines in a CSS drop-down navigation bar

When looking at the following CSS code, I noticed that the bottom and top borders seem to overlap, creating a thick line. I'm having trouble figuring out how to remove it. Any suggestions or advice would be greatly appreciated. Thank you! HTML Code: ...

Creating a dynamic word cloud in D3: Learn how to automatically adjust font sizes to prevent overflow and scale words to fit any screen size

I am currently utilizing Jason Davies' d3-cloud.js to create my word cloud, you can view it here 1. I'm encountering an issue where the words run out of space when the initial window size is too small. To address this, I have a function that cal ...

How can I split my button into two distinct colors?

Here is a button example with CSS styling: CSS .Btns { width:200px; height:75px; background-color:lightblue; color:black; font-weight:bold; } HTML: <button id="btnProduct" type="button" clas ...

The link in the navbar isn't functioning properly, which indicates that it's not redirecting to the specified ID on this one-page application

<!-- NAVBAR --> <nav class="navbar navbar-expand-lg py-3 sticky-top navbar-light bg-white"> <div class="container-fluid"> <a class="navbar-brand" href="#acasa"> <img class="logo" src="./assets/img/xxxxx_psiholog_logo. ...

Organizing Angular Material Styles using Namespacing

In an attempt to develop reusable components with Angular 1.4.3 and Angular-Material 1.0.5, the goal is to seamlessly integrate these components across various applications. However, a challenge arises as the Angular Material CSS contains styling rules th ...

What is the best way to handle HTML files that have the same name as folders?

I am looking to incorporate a News section on my website with the unique URL: mysite.com/news Each news article should be stored in a specific folder named "News" like this: mysite.com/news/2021 However, when I attempt to access the news.html file (witho ...

Retrieve the JQuery element using its ID or class identifier

I need some assistance with retrieving the innerHTML of element number 5 in a JQUERY Object. Can someone provide guidance on how to achieve this? Your help is greatly appreciated. ...

JavaScript Function Not Executed in Bottom Section

I've implemented AngularJS includes in my project. Below is the code snippet from my index.html: <!DOCTYPE html> <html ng-app=""> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> ...

"Utilize form submissions and PDO to easily insert multiple rows into a

Hey everyone, I could use some assistance with my PHP code for inserting multiple rows using a form and PDO. Below is the code snippet, so please lend a hand in fixing it. I'm open to all suggestions and solutions, and please bear with me as I am new ...

Instructions on how to invoke a function defined in a JavaScript module (type=module) from an HTML document

I've been facing difficulties with using JavaScript modules... I have an HTML file and a JS module. In the javascript file, I have a function defined that I want to call from my HTML page. Here is my code: index.html <html> <head> < ...

Crafting a Dynamic Forms Manager

Recently, I challenged myself to create a complex input form that would enable users to add an infinite number of inventory items for efficient management. Throughout this process, I have sought assistance and have significantly enhanced my script with eac ...

Difficulty with font rendering across different web browsers such as Firefox, Chrome, and Opera

Visit the following website: I have implemented font-face on my site: @font-face { font-family: 'SegoeUI'; src: url('{site_url}themes/site_themes/agile_records/fonts/segoeui.eot?') format('eot'), url(' ...

Ways to emphasize a specific row within a table for special occasions

I have limited knowledge of CSS and JavaScript, but I am looking for a way to create a notification highlight that functions similarly to when someone comments on a Facebook post. When clicked, it should direct me to the specific comment with a temporary h ...

Creating a website using the Hugo Tikva theme and Bootstrap-4 for a seamless and modern design

Embarking on a complete overhaul of my company's website, I've decided to utilize the Hugo framework and Bootstrap for the revamp. While web development isn't my expertise, I'm in need of guidance on how to effectively leverage a Hugo t ...

Selenium failed to locate the element that already exists

I have developed an application that utilizes the Selenium Internet Explorer webdriver. The program functions properly on my own computer, however, when attempting to run it on another PC with the same driver, an exception is thrown regarding the inability ...