Ensure that divs can adjust in size while maintaining the same dimensions of their contained

I'm currently facing a slight issue with these two divs. I want them to be scalable, which I know can be achieved by using percentages, but every time I do so, the divs end up out of position. When I try setting widths, they look fine in Google Chrome but not in IE, and they are clearly not scalable. Also, there's a gray filter over the images that looks odd when the divs are not perfectly aligned next to each other.

If you could take a look at the code and let me know if I'm making any major mistakes, which I assume I am.

Firstly, here is the link to the Jsfiddle and the full-screen view. And now, the code, starting with the basic HTML:

  <div class="My-Gems">
   <div class="item item-type-double"> <a class="item-hover">
    <div class="item-info">
      <div class="date">Branding</div>           
      <div class="line"></div>            
      <div class="headline">Money Matters</div>
      <div class="line"></div>
     </div>
   <div class="mask"></div>
 </a>

                      <div class="item-img">
                          <img src="http://s29.postimg.org/8safbuqmf/Money_Matters_Logo_gif.png " style="width:100%;" alt="" />
                      </div>
                  </div>
                  <div class="item item-type-double"> <a class="item-hover" href="https://www.youtube.com/watch?v=S74yj5rnvAo" target="_blank">
         <div class="item-info">
          <div class="date">Events</div>           
          <div class="line"></div>            
          <div class="headline">Metaphon Fitness</div>
          <div class="line"></div>
         </div>
      <div class="mask"></div>
     </a>

                      <div class="item-img">
                          <img src="http://s29.postimg.org/wrpgkar0n/Metaphon_Fitness.png" />
                      </div>
                  </div>
              </div>
              <!-- end of my-gems-->
      `

Next is the CSS code, keeping it simple as well:

    .My-Gems {
    width: 100%;
    height: 100%;
}

h2.Second-Header {
    color: black;
    font-weight:400;
    font-family:'Abril Fatface', cursive;
    font-size: 3em;
    margin: 80px;
}


.item {
    text-align:center;
    float:left;
    position:relative;
}
.item, .item-hover, .item-hover .mask, .item-img, .item-info {
    width: 600.5px;
    height: 600px;
}
.item-hover, .item-hover .mask, .item-img {
    position:absolute;
    top:0;
    left:0;
}
.item-type-double .item-hover {
    z-index:5;
    -webkit-transition: all 300ms ease-out;
    -moz-transition: all 300ms ease-out;
    -o-transition: all 300ms ease-out;
    transition: all 300ms ease-out;
    opacity:0;
    cursor:pointer;
    display:block;
    text-decoration:none;
    text-align:center;
}
.item-type-double .item-info {
    z-index:10;
    color:#ffffff;
    display:table-cell;
    vertical-align:middle;
    position:relative;
    z-index:5;
}
.item-type-double .item-info .headline {
    font-size:2.4em;
    font-family:'open sans';
    text-transform: uppercase;
    width:90%;
    margin:0 auto;
}
.item-type-double .item-info .date {
    font-size:20px;
    font-family:'Canter';
    text-transform: uppercase;
}
.item-type-double .item-hover .mask {
    background-color:#000;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
    filter: alpha(opacity=50);
    opacity:0.5;
    z-index:0;
}
.item-type-double .item-hover:hover .line {
    width:90%;
}
.item-type-double .item-hover:hover {
    opacity:1;
}
.item-img {
    width:100%;
    z-index:0;


}

Answer №1

Initially, there is an issue where one image has a width of 100% while the other does not, causing their sizes to differ.

Furthermore, avoid using table cell display outside of a 'table' element as it may malfunction in certain browsers (such as Firefox).

To ensure that the width:100% property functions properly on all browsers, the parent element must either be the body or have its own width setting. Each element in the hierarchy should have a width of 100%, except for the first one which can have a width of 50%. Remember to eliminate unnecessary margins, paddings, and borders from all elements.

You can view the corrected version here: https://jsfiddle.net/r469x2at/17/embedded/result/ Reorganize the HTML structure to accommodate dynamic height: Latest Works

<div class="item item-type-double">
    <div class="item-img">
        <img src="http://s29.postimg.org/8safbuqmf/Money_Matters_Logo_gif.png " style="width:100%;" alt="" />
    </div> <a class="item-hover">
           <div class="item-info">
               <div class="mycell">
            <div class="date">Branding</div>           
            <div class="line"></div>            
            <div class="headline">Money Matters</div>
            <div class="line"></div>
               </div>
           </div>
         <div class="mask"></div>
       </a>

</div>
<div class="item item-type-double">
    <div class="item-img">
        <img src="http://s29.postimg.org/wrpgkar0n/Metaphon_Fitness.png" style="width:100%;" />
    </div> <a class="item-hover" href="https://www.youtube.com/watch?v=S74yj5rnvAo" target="_blank">
           <div class="item-info">
               <div class="mycell">
            <div class="date">Events</div>           
            <div class="line"></div>            
            <div class="headline">Metaphon Fitness</div>
            <div class="line"></div>
               </div></div>
        <div class="mask"></div>
       </a>

</div>
</div>
<!-- end of my-gems-->

To achieve dynamic height and auto-width, implement the following CSS modifications:

.item {
text-align:center;
float:left;
position:relative;
width: 50%;
height: 100%;
}
.item-hover, .item-hover .mask, .item-img, .item-info {
width: 100%;
height: 100%;
}
.item-hover, .item-hover .mask {
position:absolute;
top:0;
left:0;
}
.item-type-double .item-hover {
z-index:5;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
transition: all 300ms ease-out;
opacity:0;
cursor:pointer;
display:block;
text-decoration:none;
text-align:center;
}
.item-type-double .item-info {
z-index:10;
color:#ffffff;
display:table;
position:relative;
}
.item-type-double .item-info div.mycell {
vertical-align:middle;
height: 100%;
display:table-cell;
}

Apologies for the incomplete response, please refer to this link for the full details: https://jsfiddle.net/r469x2at/17/

Answer №2

After noticing that the Alpha Mask hover was overflowing the div slightly, I discovered that the issue was caused by a small gap due to display:inline.

To solve this problem, I implemented Gabriel's solution by adding the following CSS:

.item-img img {
    display:block
}

The final CSS code snippet is as follows:

Your final HTML structure will look like this:</p>
<div class="My-Gems">
  <h2 class="Second-Header">Latest Works</h2>
  <div class="item item-type-double">
    <div class="item-img">
      <img src="http://s29.postimg.org/8safbuqmf/Money_Matters_Logo_gif.png " alt="" />
    </div>
    <a class="item-hover">
      <div class="item-info">
        <div class="mycell">
          <div class="date">Branding</div>
          <div class="line"></div>
          <div class="headline">Money Matters</div>
          <div class="line"></div>
        </div>
      </div>
      <div class="mask"></div>
    </a>
  </div>
  <div class="item item-type-double">
    <div class="item-img">
      <img src="http://s29.postimg.org/wrpgkar0n/Metaphon_Fitness.png" />
    </div>
    <a class="item-hover" href="https://www.youtube.com/watch?v=S74yj5rnvAo" target="_blank">
      <div class="item-info">
        <div class="mycell">
          <div class="date">Events</div>
          <div class="line"></div>
          <div class="headline">Metaphon Fitness</div>
          <div class="line"></div>
        </div>
      </div>
      <div class="mask"></div>
    </a>
  </div>
</div>
<!-- end of my-gems-->

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

Problem with Google+ Button Alignment

I arranged my social media buttons in a row - Twitter, Facebook & Google+. The issue is that the Google+ button is not aligning properly. It appears to be spaced out about 3 times further than the Twitter and Facebook buttons. I attempted adjusting the p ...

Is it possible to incorporate a Material-UI theme palette color into a personalized React component?

My custom Sidebar component needs to have its background color set using Material-UI's primary palette color. Sidebar.js import styles from '../styles/Home.module.css'; export default function Sidebar() { return ( <div className={ ...

How can I arrange a table in Angular by the value of a specific cell?

Here's the current layout of my table: Status Draft Pending Complete I'm looking for a way to sort these rows based on their values. The code snippet I've been using only allows sorting by clicking on the status header: onCh ...

The horizontal overflow in the HTML code was unsuccessful

I stumbled upon an interesting issue where I applied a div with specific styling: overflow-x: scroll However, the outcome was not as expected. Instead of overflowing, the content simply started on a new line. Here is the source code for reference: & ...

Adjust the size of col-lg-3

Is there a way to adjust the size of my col-lg based on different screen resolutions? I'm looking for a solution that can change the size of col-lg depending on the screen resolution. For example: .col-lg-3 { /* styles for screens with 1366x768p ...

The inputs are not responding to the margin-left: auto and margin-right: auto properties as expected

I'm having trouble aligning an input in a form to the center. Even though I have included display: block in the CSS, using margin-left:auto and margin-right: auto is not yielding the desired result. To illustrate the issue more clearly, I've cre ...

Using Python to retrieve data from MySQL and display it in HTML

I am looking to create a system that queries an SQL database every hour and displays the values on a website using Python. However, I am unsure of where to begin. Most resources online mention PHP or focus on pulling data from a website into a database. ...

Implement PHP script to send email upon form submission with POST method in HTML

I am new to PHP and trying to set up mail functionality, but I'm facing a problem where clicking on the submit button opens a new window that displays part of my PHP code. My goal is to send an email from a user's email address to mine with the c ...

Verify the presence of a particular attribute in an HTML tag using Capybara and polling techniques

In my HTML code, the attributes of buttons (such as "AAAAA") will change based on external events. This real-time update is achieved through AJAX pooling. <div class="parent"> <div class="group"><button title="AAAAA"/></div> <di ...

A JavaScript code snippet that stores the total number of bytes read from a CSV file in a variable

I currently have a CSV file located on a web server that is regularly updated with numeric and string data of varying lengths. I am seeking a solution to calculate the total byte values of each row when reading the file, as the byte count is crucial due ...

Tips for returning an element to its starting position following animation

Hey there, I’m fairly new to the world of HTML and CSS. Recently, I was working on creating a YouTube clone website and I’ve run into an issue with the navigation. On the official YouTube website, when you click on the hamburger menu icon, the naviga ...

I find myself struggling to manage my javascript dependencies

Currently, I am utilizing NPM along with various angular packages. As per the tutorial on Basic Grid Part 1 at this link, I am encountering challenges. This is my file directory structure: D:/nodeStuff/uiGrid includes: node_modules uigrid.css uigrid.h ...

Choose items in a particular order based on the class name of their category

How can I dynamically select and manipulate groups of elements? My intention is to select and modify the msgpvtstyleme elements, then select the msgpvtstyle elements separately and work with them as well. The ultimate goal is to apply classes to these grou ...

Tips for updating the content of a div with fresh data using a slideshow effect in jQuery

Imagine you have a div called A and an array filled with text data. When t=0, div A will display $data[0]. Then, after every n seconds, I want the div to show the next piece of data in the array. I am interested in creating a transition effect similar to ...

Converting HTML content into Java objects

I have a log of messages from a messaging platform saved in HTML format. Each message is displayed as follows: <div class="message"> <div class="message_header"> <span class="user">User Name</span> <span class="meta"&g ...

An instructional guide on utilizing Python to extract the URLs of companies from a LinkedIn search

I'm having an issue extracting company profile URLs from a LinkedIn search as I keep getting a "not found" message. Despite my code running smoothly, the problem persists. Here is my code: import requests import csv import time import numpy from bs4 ...

Are custom boolean attributes supported in HTML?

When working in HTML5, we have the ability to utilize custom data-* attributes. However, since these are considered attributes, they generally require a string value. Is there a different option within HTML that allows for custom properties, where boolean ...

What is causing the mouse to malfunction when interacting with this HTML form?

What is causing the mouse to not work with the form on this specific webpage? The issue here is that the mouse does not seem to be functioning correctly when attempting to interact with the input boxes within the Form. Upon clicking any of the input boxe ...

Connect ng-models with checkboxes in input field

I am facing an issue with binding ng-models using ng-repeat in an input checkbox tag. Let me share my code and elaborate further. app/main.html: <div ng-repeat="feature in features"> <input type="checkbox" ng-model="features[$index].name"> ...

What strategies can I implement to ensure my modal dialog box remains responsive? Adjusting the window size causes the modal box to malfunction and lose its structure

Whenever I adjust the size of the browser window, the elements inside the modal box become misaligned. HTML <div class='modal'> <div class='modal-content'> </div> </div> Below is the CSS for the modal ...