Adjust the size of a div using absolute positioning

Can a div with absolute position be resized?

I need this pink modal to maintain the same width as the input and resize accordingly. This modal will be utilized in a dropdown component, so it should resize along with the input.

Moreover, is using absolute position appropriate for this scenario?

<!DOCTYPE html>
<html>
  <head>
    <title>My CSS Grid</title>
    <style>
      body {
        color: #fff;
        font-family: "Nunito Semibold";
        text-align: center;
      }
      .page {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-auto-rows: minmax(100px, auto);
        grid-gap: 10px;
        max-width: 960px;
        margin: 0 auto;
        grid-template-areas:
          "header header header"
          "aside comp main";
      }
      .page > * {
        background: #3bbced;
        padding: 10px;
      }

      .header {
        grid-area: header;
      }
      .comp {
        grid-area: comp;
      }
      .input_cell {
        display: grid;
      }
      .input {
        flex: 1;
      }
      .modal_container {
        margin-top: 20px;
        flex: 1;

        background-color: pink;
        position: absolute;
      }
    </style>
  </head>
  <body>
    <div class="page">
      <div class="header">Header</div>
      <div class="comp">
        <div class="input_cell">
          <input class="input" />
          <div class="modal_container">Modal</div>
   </div>
& lt; /div>.

... etc
.
.

Answer №1

<!DOCTYPE html>
<html>
  <head>
    <title>My CSS Grid</title>
    <style>
      body {
        color: #fff;
        font-family: "Nunito Semibold";
        text-align: center;
      }
      .page {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-auto-rows: minmax(100px, auto);
        grid-gap: 10px;
        max-width: 960px;
        margin: 0 auto;
        grid-template-areas:
          "header header header"
          "aside comp main";
      }
      .page > * {
        background: #3bbced;
        padding: 10px;
      }

      .header {
        grid-area: header;
      }
      .comp {
        grid-area: comp;
        position: relative;
      }
      .input_cell {
        display: flex;
        position: relative;
      }
      .input {
        flex: 1;
      }
      .modal_container {
        position: absolute;
        left: 0;
        width: 100%;
        background-color: pink;
        margin-top: 20px;
        flex: 1;
      }
    </style>
  </head>
  <body>
    <div class="page">
      <div class="header">Header</div>
      <div class="comp">
        <div class="input_cell">
          <input class="input" />
          <div class="modal_container">Modal</div>
        </div>
      </div>
    </div>
  </body>
</html>

Ensure that the .comp and .input_cell classes have a position of relative. Also, style the .modal_container to have a width of 100%.

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

Fuzzy text in drop-down box on Chrome, clear on Firefox

I've encountered an issue with a dropdown menu in Google Chrome where the content appears blurry, while it displays correctly in Firefox. The problem arises when the dropdown exceeds a certain height, and I've tried setting a max-height with over ...

Utilizing jQuery for Summation Calculation

How can I use jQuery to calculate the total sum of prices for all products in a table with the column name "price"? Once calculated, how do I store this sum in a variable? <table id ="tab"> <th>Product</th><th>Price</th> ...

Align the image in the middle using JavaScript for Firebase

I am struggling to display the center of an image within a circle-shaped <img> tag with a border-radius of 50%. The issue arises when trying to display an image fetched from Firebase storage, rather than from a URL. In attempt to solve this problem, ...

What could be causing my Bootstrap 5 hover effect to malfunction?

Can anyone help with changing the hover effect of a bootstrap button in my code? Here's the HTML: <button type="button" class=" btn btn-dark">Sign Up</button> And here's the CSS I tried: .btn-dark:hover { color: ...

Joomla, Enhancement for iFrame Sizing

A close associate who runs his own construction business has asked me to create a website for him using Joomla. I have successfully implemented most of the features he wanted, but now I need some assistance. He wants to showcase references written about hi ...

My image is being cropped on larger screens due to the background-size: cover property

I am currently in the process of designing a website with a layout consisting of a Header, Content, and Footer all set at 100% width. To achieve a background image that fills the screen in the content section, I utilized CSS3 with background-size:cover pr ...

What is the best way to use jQuery to attach functions to every input element?

Imagine you have a set of HTML markup and CSS like this: #CSS .inputhelp_text { background: #000; color: #fff; } .nodisplay { display: none; } <input class="inputhelp" id="firstname" /><span class="inputhelp_text nodisplay" id="help_firstname"& ...

Using media queries in CSS to create responsive designs

<link type="text/css" rel="stylesheet" media="only screen and (max-device-width: 480px)" href="/assets/css/phone.css" /> <link type="text/css" rel="stylesheet" media="only screen and (min-device-width: 768px)" href="/assets/css/tablet.css" /&g ...

Difficulties in Adjusting the Size of Three Image Columns within a Website's Body

While working on my website layout, I encountered a problem with inserting three image columns in the body section. The images turned out to be too large and extended beyond the footer. Moreover, the third image was larger than expected, dominating the web ...

What is the best way to remove a CSS style using JavaScript?

For my website automation using Selenium, I encountered a challenging dropdown that was not the standard native one but a custom-designed version. To tackle this issue, I needed to set its CSS class to hidden in order to access the native functionality smo ...

Talwind Flexbox Grid Design

Currently, I am exploring the world of website layout creation using Tailwind Flexbox Grids as I believe it can add significant value. However, I have encountered some queries: How does one go about constructing a layout like this? Referencing this speci ...

The device-width value in the viewport width setting is causing issues

My angular app desperately needs a mobile responsive design as it currently looks dreadful on mobile devices. I've tried adding <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=yes">, but ...

Finding the div associated with the element that triggered an event

I've recently launched a website that allows users to post questions and receive responses from others. Each question is housed in a div, which then contains another div with the CSS property of display: none. Within the main div, there's a butt ...

Bootstrap 4 alert boxes extend the text to span the entire width of the alert

How can I make the paragraph text span across most of the box width in Bootstrap 4? <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJ ...

Changing color of Font Awesome Icons upon hover, without any animation

I need assistance with changing the color of font awesome icons on hover without any animation. Specifically, I want the icon colors to transition from indigo to blue and finally red when a user hovers over them, without the colored icon appearing abruptly ...

How to style a sublevel menu to appear next to its parent using CSS

I have a menu that is currently functioning well, but I would like to add a new sublevel onto it. However, if I directly add the new options, they end up hiding the existing ones on the menu. Here's an image for reference: I want the new options to ...

Using Jquery fadeIn along with responsive CSS media queries

Issue at Hand: An issue arises with my navigation bar and text block animations. The fading effect applied on the text element causes inline styles to be added, thus disrupting the media query set to hide the text on smaller screens. If you disable the s ...

Is there a way to utilize either css3 or css in order to change the icon displayed on a button

Currently, I am working on a button that contains a span element. I am interested in finding a way to change the background of the span when the button is clicked and have it remain changed. Is there a way to achieve this using CSS only? I am aware that ...

Mobile Exclusive Bootstrap 5 Collapse Feature

Trying to implement the default collapse feature in Bootstrap 5x specifically for mobile devices. Despite setting up a CSS media query as per my research, the .collapse function doesn't seem to work as intended? The goal is to have the collapsed DIV ...

Slight Misalignment of Elements

I am attempting to align two corners of an element so that they perfectly match the corners of another element. In simpler terms, I am aiming to synchronize the corners of one element with those of another element. Below is the code snippet: ... When y ...