Link causing chaos in CSS animation

I've created a CSS animated banner. You can view the result here. However, I'm facing an issue where adding a hyperlink to some of the pictures is causing the animation to mess up. The first picture has a href attribute, making it smaller and not fitting into the same length div as the others. Here is the HTML code:

<header class="mainheader">

<div>
<img class='photo'  src="temp/temp/img/cut/camera.jpg" alt="camera"/>
<img class='photo'  src="temp/temp/img/cut/girl.jpg" alt="asian student"/>
<img class='photo'  src="temp/temp/img/cut/kids.jpg" alt="campus kids"/>
<img class='photo'  src="temp/temp/img/cut/books.jpg" alt="books" onclick="javascript:location.href='http://www.flickr.com/photos/lemuelinchrist/2657001395/'" />
<img class='photo'  src="temp/temp/img/cut/field.jpg" alt="cambridge" onclick="javascript:location.href='http://www.flickr.com/photos/ericatkins/7927420108/'" />
<img class='photo'  src="temp/temp/img/cut/icl.jpg" alt="icl" onclick="javascript:location.href='http://www.flickr.com/photos/herry/2924207957/'" />
<img class='photo'  src="temp/temp/img/cut/math.jpg" alt="math" onclick="javascript:location.href='http://www.flickr.com/photos/featheredtar/76976279/'"/>
<img class='photo'  src="temp/temp/img/cut/student.jpg" alt="student" onclick="javascript:location.href='http://www.flickr.com/photos/merchau/8548057127/'"/>
<img class='photo'  src="temp/temp/img/cut/ucl.jpg" alt="ucl" onclick="javascript:location.href='http://www.flickr.com/photos/stevecadman/371199372/'"/>

</div>

</header>

</body>

My CSS file, ypicstyle.css in the temp folder, is structured like this:

.mainheader div/*.container*/{
width: 100%;
height: 300px;
margin: 2% 0;
overflow:hidden;
border:0px solid;
border-top-color:#856036;
border-left-color:#5d4426;
border-bottom-color:black;
border-right-color:#5d4426;
position:relative;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
.photo{
position:absolute;
width:100%;
height:auto;
-webkit-animation:round 36s infinite;
-moz-animation:round 36s infinite;
-ms-animation:round 36s infinite;
-o-animation:round 36s infinite;
animation:round 36s infinite;
opacity:0;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;

}

@keyframes round{
11.1%{opacity:1;}
22.2%{opacity:0;}
}

...

I'm trying to correctly format it here, but it's been challenging. Does anyone have suggestions on how I can add links to my pictures without affecting the CSS animation? Thank you for any help. :::edit::: Can someone point out what I'm doing wrong? It seems like the animation timing might be off, or there could be another issue. When I try the URL example, some pictures have links and some don't. However, when I click on any picture, it takes me to the link of the last one. Can someone please assist?

Answer №1

Try including both width: inherit and height: inherit in the element's properties to observe the impact it has on the layout.

Answer №2

One alternative is to utilize the anchor tag in the following manner:

<a class='picture pic1' href=''></a>
<a class='picture pic2' href=''></a>

.picture {
    display: block;
    width: 250px;
    height: 150px;
    background-image: url(image-url);
}

.picture.pic1 {
    background-image: url(image-url-1.jpg);
}
.picture.pic2 {
    background-image: url(image-url-2.jpg);
}

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

Altering the PHP text hue

Is it possible to customize the color of the print and echo text on your HTML page, rather than having it just in black? Thank you. ...

Issue with CSS styles not linking correctly to ejs templates

I'm having trouble linking my CSS stylesheet in my project. I have the CSS file stored in a public folder with a css subfolder within it. Despite trying various methods, I can't seem to get the stylesheet to connect properly. Below is a snippet f ...

creating styles for css elements using equations

I am curious about defining CSS element dimensions before they are rendered without using offset and jQuery. Is it possible to echo PHP into the width/height or position values? For example: <?php $width = 290px; $altwidth = 290; ?> <style> ...

What is the best way to insert images into a div in Ionic framework?

I am facing an issue with fitting an image inside a div container. Here is my code structure: <div style="background-color: red; height: 200px; width: 200px;"> <ion-img src="{{kategori[i].img}}"></ion-img> & ...

Every time I attempt to visit my website on a mobile device, it seems to appear larger than normal, as

After developing a responsive website and adding media queries to make it mobile-friendly, I encountered an issue. Despite my efforts, the website's width is still larger than the mobile viewport, requiring users to zoom out to view it properly as sho ...

Trouble with Chrome's CSS making table cell display as block

After searching, I stumbled upon this question that appeared to have the solution I needed. Surprisingly, even when using chrome 32.0.1700.102, the fiddle provided in the first answer worked perfectly for me. However, when I copied the HTML code into a ne ...

Why aren't Material UI v5 styles being applied to the class?

I have been attempting to customize the MUI slider by applying styles using the className prop. However, I am facing an issue where the styles assigned to the main class are not being applied, but other styles such as the 'hover' state are workin ...

Emojis representing flags displayed on screen

Is there an option to display a flag icon? For example, I am able to write Hello ...

Aligning text to the right within a div that is placed inside an image element

I have a simple structure that looks like this: <div class="inline"> <div class="photo-group thumb_wrapper"> <img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQYZ35nsT0CRTlGBtNmPHikH74wXBldsPe8LQYfhXnzADYo-xSU" ...

Impeccable method to safeguard element from external css interference

Currently, I am working on a script that will be utilized across various pages and I want to ensure that the elements it generates are not affected by the CSS styles of those pages. Some individuals suggest using CSS like this: body>*{min-height:200px; ...

Utilizing two distinct CSS frameworks within a single Rails application

At the moment, I have an application with its frontend built using Bootstrap 3 (leveraging the bootstrap-rails gem). Now, I am looking to incorporate the Materialize.css framework into the same app. After downloading the Materialize.css stylesheet, my conc ...

Add a captivating backdrop to a div element

So I have this unique HTML element that showcases a large headline with two decorative lines on either side, extending to the full width of the element. However, I now have a requirement to display some text as a background behind this element. The issue ...

Here's a new take on the topic: "Implementing image change functionality for a specific div in Angular 8 using data from a loop"

I need to create a list with dynamic data using a loop. When I click on any item in the list, I want the image associated with that item to change to a second image (dummyimage.com/300.png/09f/fff) to indicate it's active. This change should persist e ...

Div text with superfluous line breaks

Whenever a user clicks the sign-up button ("Cadastrar" in Portuguese) on my website, the newsletter form successfully hides. However, there seems to be unnecessary line breaks in the success message. Why is this happening? I am trying to make sure that th ...

How can CSS files be shared among multiple projects within Visual Studio 2012?

I am working on a Visual Studio Project Solution that includes 3 separate projects. To streamline the process and avoid duplication, I aim to have a shared CSS file for all 3 projects since they all follow the same CSS rules. Despite trying the Add As Lin ...

I'm struggling to achieve the placement of my logo and navigation bar side by side

Check out the codes here body{ margin: 0; } .logo { text-indent: -999999px; background: url('logo3.png'); width: 216px; height: 219px; } .header{ width: 100%; height: auto; background-color: #eef3f5; padd ...

Changing color in JQuery based on class and the content of HTML elements

I am attempting to utilize jQuery to extract the inner html of a div with the class name "box_bottom". These divs are dynamically generated by JavaScript, fetching data from XML. As a result, there could be multiple occurrences based on the XML, and I nee ...

What method is most effective for loading HTML content depending on the device being used?

Looking for the optimal method to load different div elements based on the device accessing my website without relying on user agent checks. As of now, I am utilizing CSS media queries to determine device specifications and display the appropriate div acco ...

Displaying selected list item while concealing the original

I have a dropdown menu with several options. What I am looking for is to have it so that when we click on the drop down, a list of choices appears. Then, when we select an option from the dropdown, the original selection should be replaced with the one th ...

CSS: selecting the adjacent siblings of a certain class, starting from the first and

I am working on achieving the following goal: https://i.sstatic.net/xHoIG.png Elements containing values should have a gray 'ribbon'. Elements with values are given a class selected, while elements without any value do not have this class. Thi ...