Tips for aligning 2 divs in the same position?

I am working on a slider feature that includes both videos and pictures. I need to ensure that the videos are hidden when the device width exceeds 600px.

Here is the HTML code snippet:

<video class="player__video" width="506" height="506" muted preload="auto" playsinline poster="[xfvalue_videopathimage]">
         <source src="[xfvalue_videopath]" type="video/mp4">
          Your browser does not support the video tag.
        <div class="player1">
    <img class="player2" src=[xfvalue_videopathimage] width="506" height="506">     
               </div>
                </video>

And here is the corresponding CSS:

.player {
      position: relative;
      text-align: center;
      cursor: pointer;
      width: 100%;
      height: 100%;
    }

    @media (max-width: 767px) {
      .player {
        overflow: hidden;
      }
    }

    .player__video {
      overflow: hidden;
      max-width: 100%;
      position: relative;
      vertical-align: top;
      height: 100%;
      width: 100%;
      -o-object-fit: cover;
         object-fit: cover;
    }

    @media screen and (max-width: 600px){
        .player__video{
            display:none;
        }

    }

    @media (min-width: 768px) {
      .player__video {
        border-radius: 50%;
      }
    }

@media (max-width: 767px) {
  .player__video {
    width: 100%;
    height: 100%;
    -o-object-fit: cover;
       object-fit: cover;
    max-height: 100%;
    position: static;
    overflow: hidden;
  }


    .player1
    {
        position: relative;
        text-align: center;
        cursor: pointer;
        width: 100%;
        height: 100%;
    }
    
    @media (max-width: 600px) {
        .player1 {
            overflow: hidden;
        }
    }

    .player2 {
        overflow: hidden;
        max-width: 100%;
        position: relative;
        vertical-align: top;
        height: 100%;
        width: 100%;
        -o-object-fit: cover;
        object-fit: cover;
    }

    @media screen and (min-width: 600px){
        .player2{
            display:none;
        }
    }

    @media (min-width: 768px) {
        .player2 {
            border-radius: 50%;
        }
    }
  
    @media (max-width: 600px) {
        .player2 {
            width: 100%;
            height: 100%;
            -o-object-fit: cover;
            object-fit: cover;
            max-height: 100%;
            position: static;
            overflow: hidden;
        }
    }

Answer №1

It's important to consolidate your media queries to avoid repeating the same styles. Remove any duplicates of "@media (max-width: 600px)" after the initial declaration to ensure proper settings.

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

When clicking on links that are not within the ng-view element, you will be redirected to the

I'm having trouble coming up with a name for this question, but here's my current situation This is the structure of my template: ├── index.html ├── ... ├── account │ ├── index.html │ ├── authorizat ...

Only initiate the loading of the iframe within the div upon clicking a specific element

Is there a way to delay loading the content of a div until it's clicked, instead of having all data loaded at once when the page loads? I noticed that removing unnecessary divs made the page load much faster. How can I prevent all data from being loa ...

Interact with a dropdown menu using Selenium

Typically, my approach with the Selenium Select object is as follows: val selectCode = new Select(driver.findElement(By.id("someID"))) selectCode.selectByValue("4") The issue arises when there is no value in the html code. Here is an example of a ...

Replace the instances of "foo" with "bar" in the phrases "foo bar" and "bar foo."

Using a regular expression, I am able to locate specific words and then manipulate them in some way. For example: I want to surround all the words I find with <strong> tags: $string = 'Hello, there is foo, after there is bar but now I need fo ...

"JQuery enables the dynamic cloning of form elements, allowing for attribute adjustments that can be easily reverted

I've been grappling with a puzzling issue recently. I used jQuery to clone a form and assigned IDs to the form elements to increase incrementally with each clone. However, following server validation errors (using Laravel), the IDs of the elements rev ...

Creating a visually dynamic stack of images using javascript, jquery, and HTML

I'm interested in creating a unique image viewer using javascript/jQuery/HTML that combines elements of a book page flip and iTunes coverflow, optimized for mobile device browsers. I've been searching for tutorials to help kickstart this project, ...

Navigating Through Secondary Navigation with Ease

In my React project, I am developing a mega-menu styled dropdown navigation. As a functional component, I am utilizing the useState hook to manage the state and control the display of sub-navigation items. The functionality of the dropdown is operational, ...

Determine if the webpage is the sole tab open in the current window

How can I determine if the current web page tab is the only one open in the window? Despite searching on Google for about 20 minutes, I couldn't find any relevant information. I would like to achieve this without relying on add-ons or plugins, but if ...

Is there a way to enable multiple selections in a particular section?

Currently, I am in the process of working on my step by step order and I want to express my gratitude for all the assistance I have received so far. Despite the help, I still have some unanswered questions! The steps in my project are categorized into dif ...

JavaScript Magic: Hide Div when Clicking Away

I need a solution where clicking outside of the My DIV with the ID Container_ID will hide all elements within the Container by setting their style to display: none;. Currently, the JavaScript code I am using partially achieves this functionality, but it al ...

Is there a way to ensure that neighboring divs have the same height as the tallest div in a row?

In the product description column, the value spans two lines, causing the row to adjust its height accordingly. However, the issue arises when adjacent divs do not match this height, resulting in an incomplete border as shown in the image below. This probl ...

Ways to eliminate class from HTML code

Trying to detect if a navigational element has a specific class upon click. If it has the class, remove it; if not, add it. The goal is to display an active state on the dropdown button while the dropdown is open. The active state should be removed when a ...

Ways to interact with elements lacking an identifier

Currently, I'm faced with an HTML challenge where I need to interact with an element labeled tasks. *<td class="class_popup2_menuitem_caption" unselectable="on" nowrap="">Tasks</td>* In my attempt to do so, I've implemented the foll ...

Photo Collection: Incorporating Images

I am currently working on a project to create a photo gallery and I am facing an issue with adding photos. The user should be able to browse for a picture and enter a title for it on a page. Both the image path and title need to be saved in an XML file fro ...

Error encountered during file upload - file field :input not found

I'm dealing with some HTML that looks like this: <div id="promocodesUpload"> <div class="qq-uploader"> <div class="qq-upload-drop-area" style="display: none;"> <span>Drop </span> </div> <a class=" ...

Encountering a problem when transitioning Bootstrap 3 code to version 5

After finding this template on github, I noticed it was a bit outdated with the use of Bootstrap 3. I decided to update it to Bootstrap 5 and replaced the Bootstrap 3 CDN accordingly. However, upon doing so, I encountered some issues. Can anyone help me ...

The issue of exceeding margins

I am facing an issue with some CSS. Below is my HTML code: <body> <div id="cn"> <div id="hd"> <ul> <some li's> </ul> </div><!-- /#hd --> <div id="bd"> ...

I don't understand why my BeautifulSoup code is throwing an attribute error even though the variable it's referring to is assigned a value

Currently, I am working with Python 3.9.1 along with selenium and BeautifulSoup to develop my first web scraper targeting Tesco's website. This is essentially a mini project that serves the purpose of helping me learn. However, upon running the code p ...

Optimizing loading times for mobile banners through media queries

I currently have a standard size banner that loads when my page is accessed on a computer. However, I would like to optimize the loading speed by having a smaller version specifically for mobile devices using a media query. My main question is how does t ...

implementing jquery for dynamic pop up placement

When I click the English button, a pop-up appears, but I can only see the full contents of the pop-up after scrolling down. Is there any way to view the entire pop-up without scrolling? Below is the code that I am using: http://jsfiddle.net/6QXGG/130/ Or ...