Using both the HTML picture tag and list tag together

I am looking to design a CSS3 slideshow similar to the one demonstrated in this example:

Pure CSS Slideshow

Currently, my HTML code utilizes the <picture> tag to display specific images based on the orientation of the display-port, whether portrait or landscape. The tutorial for the slideshow involves using an <ul> with multiple <li> elements to define the pictures in the slideshow.

However, when I attempt to include these <ul> and <li> elements within my <picture> element, the browser is unable to locate the image(s).

Here is a snippet of my code:

HTML:

<div id="image">
  <picture>
    <source media="all and (orientation: portrait)" srcset="images/faust_portrait.jpg">
    <source media="all and (orientation: landscape)" srcset="images/faust_landscape.jpg">
    <img src="images/faust_1024.jpg" alt="faust">
  </picture>
</div>

CSS:

#image {
  width: 100%;
  height: auto;
  line-height: 0;
  animation-name: move;
  animation-duration: 1s;
  animation-timing-function: ease-in-out;
  animation-delay: 0.5s;
  animation-iteration-count: 2;
  animation-direction: alternate;
}

@keyframes move {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(100%);
  }
}

#image img {
  width: 100%;
}

Currently, the image assigned is sliding out and back into the screen once. My goal is to have around 5 pictures, each available in two versions depending on the viewport's orientation, sliding continuously. This would serve as a header for the webpage. Any advice on how I can achieve this?

Answer №1

The standard set by WHATWG states that the content within a picture tag should consist of zero or more sources followed by an img tag, with the possibility of being mixed with script-supporting elements. It is important to note that ol and ul tags are not listed as acceptable types within a picture tag.

To address orientation issues with images, it is recommended to place the picture tag within an ol or ul tag instead; treating it as a list of pictures rather than a single picture within a list (although this cannot be confirmed with 100% certainty). This adjustment should help resolve any problems related to image orientation.

In terms of creating a slideshow, following a detailed tutorial like the one you have linked can lead to achieving the desired outcome. The tutorial suggests using a unique id for each picture, but there is also the option to use the nth-child selector to target specific images based on their position in the sequence.

However, it's important to consider that this method of creating a show reel may lack flexibility, especially when adding or removing images which requires adjusting the timing of each image. Additionally, ensuring the final image transitions smoothly back to the beginning is essential for a cohesive presentation.

When running the snippet, selecting "Full page" allows for manipulation of client size and orientation by resizing the browser window. This feature can provide valuable insights into how the images behave under different display conditions. Hope this information proves helpful.

.showreel
{
  /* Applying absolute positioning to child elements. */
  position:relative;
  z-index:0;
  overflow:hidden;

  /* Setting default dimensions assuming landscape mode. */
  width:64px;
  height:32px;

  /* Removing default list-style formatting. */
  list-style:none;
  padding:0;
  margin:0;
}
/* Adjusting showreel size for portrait mode. */
@media (orientation:portrait){.showreel { width:32px; height:64px;}}

.showreel li
{
  position:absolute;
  left:0; top:0;
}

/* Utilizing nth-child() selector instead of ids. */
.showreel li:nth-child(1){animation: picture_1 3s linear infinite;}
.showreel li:nth-child(2){animation: picture_2 3s linear infinite;}
/* Repeat for additional images as needed. */    

/* Timings must be customized for each new image in the reel. */
@keyframes picture_1
{
  0%{top:0; z-index:1;} 
  25% {top:0; z-index:1;} 
  50% {top:-100%; z-index:0;} 
  75% {top:100%; z-index:0;} 
  100% {top:0; z-index:1;} 
}
@keyframes picture_2
{
  0%  {top:100%; z-index:0;}
  25% {top:100%; z-index:0;}
  50% {top:0; z-index:1;}
  75% {top:0; z-index:1;}
  100%{top:-100%; z-index:0;}
}
<ul class="showreel">
  <li>
    <picture>
      <source media="all and (orientation:portait)" srcset="https://i.sstatic.net/h2Ojs.png" />
      <source media="all and (orientation:landscape)" srcset="https://i.sstatic.net/ZcG03.png" />
      <img src="https://i.sstatic.net/h2Ojs.png" alt="Detailed illustration showcasing landscape or portrait depending on orientation." />
    </picture>
  </li>
  <!-- Add more images to the showreel as needed. -->
  <li>
    <!-- Different images are recommended for variety. -->
    <picture>
      <source media="all and (orientation:portait)" srcset="https://i.sstatic.net/h2Ojs.png" />
      <source media="all and (orientation:landscape)" srcset="https://i.sstatic.net/ZcG03.png" />
      <img src="https://i.sstatic.net/h2Ojs.png" alt="Similar image to the previous one." />
    </picture>
  </li>
</ul>

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 there a way to have the information on the table automatically update based on the selection made in a drop-down menu?

When a user is selected from the combo box, I want the table displaying user data from the database to only show information related to the selected user. I attempted to use an array to store values but was unable to make it work. A Combo Box that allows ...

Ways to repair an element

Can anyone help me troubleshoot the issue with my count text on a div block? It seems to be affected by changes in screen size. Normal https://i.stack.imgur.com/RZkgr.png On screen resize https://i.stack.imgur.com/hTdCG.png The Code: span.right-cor ...

How can I avoid duplicating code in HTML? I find myself utilizing the Bootstrap 4 collapse feature around 20 times on a single page

<div class="card" style> <div class="card-header" id="headingOne"> <h5 class="mb-0"> <button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria- expanded="true" aria-controls="collapseO ...

What steps should I follow to create a photo gallery similar to Facebook?

I am currently developing a 4x3 image gallery showcasing pictures sourced from a database. Each picture varies in size. Utilizing Bootstrap and CodeIgniter, I create rows and columns for each image. My goal is to ensure that wide images adjust to the heigh ...

PHP - attempted to restrict file size, only to receive a warning: The POST Content-Length surpasses the designated limit

Recently, I decided to experiment with the file upload functionality on my website. The upload file code allows users to either select a file for upload or submit it without any attachment. Initially, I implemented an error message that restricts the file ...

Is it possible to nest CSS Variables within CSS Variable names?

Is it feasible to embed a CSS Variable inside another CSS variable's name or perform a similar action like this: :root { --color-1: red; --index: 1; } span { color: var(--color-var(--index)) } ...

Exploring Hover Effects in Reactjs and Material UI

I've been working with reactjs and material ui, but I'm having trouble changing the background color of selected items in various components, like in the SelectField. <SelectField floatingLabelText="Choose a sport" value={this.state.val ...

Preventing users from entering negative values in an input type=number by implementing Angular FormControl Validators

Is there a way to prevent users from decrementing the value of an input field with type=number to a negative value? I am aware that we can use min=0 in the HTML input element, but I'm looking for another method using Angular FormControl Validators. S ...

What is the rationale behind placing the CSS outside of the React function components, near the imports?

Recently, I encountered an issue with loading CSS inside a React function component using Material UI. Even though I managed to resolve it, I am still intrigued by the underlying reason. Initially, I had something like this setup where I placed both makeSt ...

Disabling the movement of arrows in the client-testimonials-carousel plugin

This plugin that I'm currently using is working flawlessly: However, I'm unsure about how to make the arrows stationary and prevent them from moving. Currently, they are centering themselves based on the height of the div, but I want them to rem ...

Place 2 images side by side within a row using Bootstrap's grid system

https://i.sstatic.net/RVBpK.png Is there a way to center the images for the 2 app download links within the class="row" section? <div class="container"> <div class="row"> <div class="col-xs-4" style="text-align:right"&g ...

Encountering a glitch while iterating through function results in failure after the initial modification

I am facing some errors with the script provided below: var sections = ["#general_info", "#address_records", "#employment_history", "#driver_experience", "#military_experience", "#eeo_survey", &qu ...

Exploring carousel elements in Selenium using Python

As a user of Selenium, I am trying to loop through the games displayed in the carousel on gog.com and print out all the prices. Below are two random XPaths that lead to the information within the carousel: /html/body/div[2]/div/div[3]/div/div[3]/div[2]/di ...

Visual Latency when Quickly Toggling Between Images in Succession

I have a series of 50 images that need to be displayed sequentially inside a div. The time interval between displaying each image is initially set at 750 milliseconds and decreases with each subsequent image. To ensure all images are loaded before the an ...

Make sure all the table rows have the same height to completely fill the table regardless of the number of rows

Looking for a solution to create a table with a fixed height of 280px, whether it has 3 or 4 rows. Is there a method to adjust the row heights based on the number of rows in the table, so that they fill up the table's height? To clarify, when the ta ...

Is it possible to dynamically change a form's input value using a JavaScript keyup function based on input from other form elements?

My form utilizes the keyup function to calculate the total value of 3 input fields by multiplying them and displaying the result. Below is a fiddle showcasing this functionality: $(document).ready(function () { $(".txtMult1 input").keyup(multInp ...

Utilize the dropdown menu across all table cells in a table

My p-table has a unique feature - the last column contains three dots that trigger a dropdown menu when clicked. The only issue is that the fixed position of the dropdown menu does not align properly with the td element in each row. Check out the HTML cod ...

Adjust the height of a div containing variable elements

I'm having trouble adjusting the height of a div so that it can be scrolled all the way through. This div is positioned next to another one, so I set the overflow-y to scroll. Initially, I thought setting the height to auto would solve the issue, but ...

Inconsistencies in spacing between shapes bordering an SVG Circle using D3.js are not consistent across platforms

After creating a SVG circle and surrounding it with rectangles, I am now attempting to draw a group of 2 rectangles. The alignment of the rectangle combo can either be center-facing or outside-facing, depending on the height of the rectangle. However, I am ...

Take charge of Bootstrap 4 dropdown transformation class while creating a Megamenu

I am currently working on creating a Megamenu using Bootstrap 4's dropdown Component. The issue I'm facing is related to Javascript adding CSS styles with transform, such as transform: translate3d(9px, 5px, 0px); This is causing disruption in m ...