Div that adjusts according to the width of an image

I have some images of a laptop and a tablet displayed on my webpage. The issue I am facing is that the div above the laptop should always match the width of the laptop. Everything looks great at full width, but problems arise when I scale down the window size.

I want the layout to scale properly when viewed on smaller screens or mobile devices.

Here is how it looks at full width: https://i.sstatic.net/XJtro.png

And this is how it appears on smaller devices: https://i.sstatic.net/jzT49.png

Here is the HTML block:

            <div class="col-lg-6">
            <div class="rain">
                 /* raindrops here */
            </div>

            {{-- RAIN DROPS(IMAGES) --}}
            <div class="parent">
                <img src="{{ url('img/header/laptop.svg') }}" class="laptop">
                <img src="{{ url('img/header/tablet.svg') }}" class="tablet">
            </div>

        </div>

And here is the CSS:

    .rain {
    position: relative;
    width: 536px;
    height: 329px;
    opacity: 0.52;
    background-image: linear-gradient(to bottom, rgba(107, 233, 228, 0), #6be9e4);
    left: 120px;
    top: -60px;
}

    .parent {
        position: relative;
        top: 50;
        left: 0;
    }
    .laptop {
        position: absolute;
        left: -45px;
        top: -145px;
    }
    .tablet {
        position: absolute;
        left: -45px;
        top: 15px;
    }

How can I ensure that the layout displays correctly on all devices? Any tips or suggestions?

https://jsfiddle.net/fa8711au/1/

Answer №1

/* Custom design for header and devices */

.rain {
  position: relative;
  width: 536px;
  height: 329px;
  opacity: 0.52;
  background-image: linear-gradient(to bottom, rgba(107, 233, 228, 0), #6be9e4);
  left: 120px;
  top: -60px;
}

header {
  background-image: linear-gradient(91deg, #7602f0, #00c7ff);
  min-height: 610px;
}

.parent {
  position: relative;
  top: 50;
  left: 0;
}

.laptop {
  position: absolute;
  left: -45px;
  top: -145px;
}

.tablet {
  position: absolute;
  left: -45px;
  top: 15px;
}

@media screen and (max-width:767px)
{
  .rain
  {
    width:100%;
    left:0px;
  }
  .laptop
  {
    max-width:100%;
  }
  .tablet
  {
    max-width:50%;
  }
  .parent
  {
    max-width:320px;
  }
  .tablet
  {
   top: -70px; 
  }  
}
<header>
  <div class="col-lg-6">
    <div class="rain">
      <div class="Oval Orval-Main color-1"></div>
      <div class="Oval-Copy Orval-Main color-1"></div>
      <div class="Oval-2 Orval-Main color-2"></div>
      <div class="Oval-3 Orval-Main color-1"></div>
      <div class="Oval-4 Orval-Main color-1"></div>
      <div class="Oval-5 Orval-Main color-1"></div>
      <div class="Oval-6 Orval-Main color-2"></div>
      <div class="Oval-7 Orval-Main color-7"></div>
      <div class="Oval-8 Orval-Main color-1"></div>
      <div class="Oval-9 Orval-Main color-9"></div>

      <div class="Rectangle Rectangle-main"></div>
      <div class="Rectangle-Copy Rectangle-main"></div>
      <div class="Rectangle-2 Rectangle-main"></div>
      <div class="Rectangle-3 Rectangle-main"></div>
      <div class="Rectangle-4 Rectangle-main"></div>
      <div class="Rectangle-5 Rectangle-main"></div>
      <div class="Rectangle-6 Rectangle-main"></div>
      <div class="Rectangle-8 Rectangle-main"></div>
      <div class="Rectangle-9 Rectangle-main"></div>
      <div class="Rectangle-10 Rectangle-main"></div>
      <div class="Rectangle-11 Rectangle-main"></div>
    </div>

    <div class="parent">
      <img src="https://image.ibb.co/kAKVOn/laptop.png" class="laptop">
      <img src="https://image.ibb.co/iyOqOn/tablet.png" class="tablet">
    </div>

  </div>
</header>

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

Conceal all div elements except for displaying the initial two

Can an entire div be hidden with only the first 2 entities visible? <div class="inline-edit-col"> <span class="title inline-edit-categories-label">Brands</span> <ul class="cat-checklist product_brand-checklist"> < ...

Using createStyles in TypeScript to align content with justifyContent

Within my toolbar, I have two icons positioned on the left end. At the moment, I am applying this specific styling approach: const useStyles = makeStyles((theme: Theme) => createStyles({ root: { display: 'flex', }, appBar: ...

Animating or transitioning CSS keyframes to an inline value when the page is initially loaded

In my current project, I am working on creating HTML and CSS-based bar representations of percentage values. The structure of the code is as follows: Using HTML: <div class="chart"> <div class="bar" style="width:43%"></div> </div&g ...

I need assistance getting a <div> perfectly centered on the page while managing the bottom and right margins

I created a design resembling the French flag and I want to maintain the same margin from the edge of the browser window. However, the ratio of the container may change. The image below illustrates what I have implemented. https://i.sstatic.net/mInBn.png ...

on clicking GTM, obtain a different child element

My HTML code is structured as follows: <div onclick="location.href='https://ford-parts-accessories.myshopify.com/products/ash-cup-coin-holder-with-lighter-element?refSrc=6748959244479&amp;nosto=productpage-nosto-1-fallback-nosto-1';&q ...

Tips for creating responsive images when using two images stacked on top of each other:

One of my challenges with using Bootstrap is trying to place an image on top of another image. Here's the HTML code I currently have: <section id="test"> <div class="row"> <div class="imgbg"><img src="img/bg_pres.png ...

Various instances of the jQuery niceScroll plugin

I successfully set up jQuery niceScroll on the body, but now I want different themed scrollbars on one page. Below is my code snippet: Here is my fiddle: http://jsfiddle.net/JPA4R/135/ <script> $(document).ready(function () { $("body").niceScroll ...

What is the best way to locate the final text node within the <p> element?

Looking at the code below, my goal is to identify and retrieve the text node that serves as the last child element. <p class="western" style="margin-bottom: 0.14in"> <font color="#000000"> <font face="Arial, serif"> <font ...

Ensure that the Materialize CSS modal form remains open even after submission

Is there a way to reload a form inside a materialize modal with empty fields without closing the modal after submitting? The issue is that currently, when the submit button is clicked, the modal closes and redirects. <div class="modal" id="docM ...

What could be causing the failure in revealing these elements?

Within my Meteor application, I utilize Template.dynamic to seamlessly replace the current Template with the next one. In my "main" html file, the setup looks like this: <div class="container"> {{> postTravelWizard}} </div> </body> ...

Vue 3's Paged.js does not respond to requests for page breaks

Currently, I'm working on implementing page breaks in Vue.js 3. Despite my efforts and utilization of the specified CSS code, I am facing challenges with the ".page-break" class parameter. While I can successfully modify other elements like titlePage ...

Tips on aligning a v-btn alongside v-expansion-panels on the same row

Struggling with aligning my layout. Trying to get a single set of v-expansion-panels and a v-btn in the same row, both visually centered within a card. I managed to almost achieve it in this codepen: https://codepen.io/anzuj/pen/PoPPbdw with the following ...

Reversed Sink CSS3 Animation moving to the left side

Currently, I am working on creating an animation that gives the illusion of a div sinking backward and then being pushed to the left once it has finished falling back. Although I am using CSS3 for this project, I am not very familiar with the animation pr ...

Blank YouTube Popup Modal

I am in the process of creating a pop-up modal that contains an embedded YouTube video, but my modal is not displaying properly. I am utilizing Bootstrap and have two separate sections along with JavaScript code. When the modal appears, it remains empty. I ...

Discovering the block's height with the power of Jquery

I have written a piece of code that sets the height of a block of text and then applies that height to an image within the block. However, the size of the image ends up being smaller than the size of the block. https://i.stack.imgur.com/QUFWy.png <scr ...

Why is there excessive whitespace appearing in Internet Explorer 9?

Visit mimictrading.com/index.php When viewed in Firefox, the website displays as intended. However, in IE9, there seems to be a strange space at the top and above the recent topics list. I suspect that it might be related to the 'header' divisio ...

Unexpected resizing of DIV element in Chrome

Working on my new PHP website, I encountered a strange issue recently. I have a file for the top navbar that is included on every page and it was functioning perfectly fine. However, while creating a register form, I noticed something odd happening. When r ...

What should we name this particular style of navigation tab menu?

What is the name of this tab menu that includes options for next and previous buttons? Additionally, is there a material-ui component available for it? https://i.sstatic.net/0m9rH.png ...

Is it necessary to convert SCSS into CSS in React?

I have a query about whether it is necessary to first compile our scss files into css and then import the css files into our react components, or if we can simply import the scss directly into the components? I've successfully imported scss directly ...

Is it considered poor practice to modify a Bootstrap class in Bootstrap 4?

For instance: form-control appears like this Would it be considered inappropriate if I incorporate this scss code? .form-control { -webkit-transition: all 0.30s ease-in-out; -moz-transition: all 0.30s ease-in-out; -ms-transition: all 0.30s ea ...