Several images displaying identical dimensions

I am in the process of creating a website for an exhibition but I am struggling with maintaining consistent dimensions for multiple photos without sacrificing quality. For reference, I would like my images to resemble those on this particular website: .

Below is the HTML code I have been using:

<div class="work">
      <a href="#"><div class="boxx"><div class="box" style="background: 
         url('img.jpg') no-repeat center center ; 
         -webkit-background-size: contain;
         -moz-background-size: contain;
         -o-background-size: contain;
         background-size: contain;">
      </div></div></a>
      <a href="#"><div class="boxx"><div class="box" style="background: 
         url('img1.jpg') no-repeat center center ; 
         -webkit-background-size: contain;
         -moz-background-size: contain;
         -o-background-size: contain;
         background-size: contain;">
      </div></div></a>
</div>

And here is the corresponding CSS:

.work {
      width: 75%;
      margin: 0 auto;
      text-align: center;
      padding: 40px 0 70px 0;
}

.work .boxx {
      width: 350px;
      height: 400px;
      display: table-cell;
      vertical-align: middle;
}

.work .boxx .box {
      margin: 0 auto;
      width: 300px;
      height: 300px;        
}

Answer №1

To achieve a consistent appearance for images of varying dimensions, consider using cover instead of contain for the background-size:

<div class="work">
    <a href="#">
        <div class="boxx">
            <div class="box" style="background: url('img.jpg') no-repeat center center;
                -webkit-background-size: cover;
                -moz-background-size: cover;
                -o-background-size: cover;
                background-size: cover;"></div>
        </div>
    </a>
    <a href="#">
        <div class="boxx">
            <div class="box" style="background: url('img1.jpg') no-repeat center center;
                -webkit-background-size: cover;
                -moz-background-size: cover;
                -o-background-size: cover;
                background-size: cover;"></div>
        </div>
    </a>
</div>

Note that using cover may result in cropping parts of the image. To control which parts are visible, explore the options available for the background-position CSS property.

For further guidance on background-size and background-position, refer to these resources:

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

Can Bootstrap be used to emphasize changed input text?

Is there a feature or customizable tool that can visually highlight input elements when they have been changed? This could involve applying a distinguishing visual cue, such as an orange border, to any input that no longer contains its default value. To ...

Is it possible to apply a style change to several components at once using a single toggle switch

I am looking to implement a day/night feature on my web app, triggered by a simple toggle click. While I can easily add this feature to a single component using the navigation menu, I am faced with the challenge of incorporating it into multiple component ...

Font reference in IE and Chrome causing HTTPS to fail

Take a look at in both Internet Explorer and Chrome. The header tags (h1 through h6) all have font specifications that rely on a javascript fonts.com specification. However, there seems to be an issue with rendering properly. Interestingly, the fonts ar ...

Has CSS3 been recognized as an official standard?

Can you confirm whether CSS3 has been officially recognized as a W3C standard or is it currently in the status of "CR" (Candidate Recommendation)? ...

The chosen color for the link button in CSS

PHP CODE : $getOID=$_GET["id"]; for($i=$getOID-($getOID-1); $i<=5;$i++){ echo '<a class="current" href="postlogin.php?id='.$i.'">'.$i.'</a>'; } CSS STYLING FOR BUTTONS : .pagging { height:20px; ...

Ways to conceal overflow at the base of a container while enabling the image to break free from the top of the container

Trying to create a visual effect where an image of a person appears to be partially hidden inside a container, with the bottom part concealed by overflow: hidden. However, I want the top part of the image to extend out of the container. Is there a way to a ...

Trigger a div to transform upon hover among multiple divs sharing the same class

I have encountered an issue with multiple divs having the same class. I've written a JavaScript code to adjust certain CSS properties on hover, but the problem is that when I hover over one box, all others with the same id and class are also affected. ...

What is the best way to deselect the first radio button while selecting the second one, and vice versa, when there are two separate radio groups?

I am looking to achieve a functionality where if the first radio button is selected, I should receive the value true and the second radio button should be unselected with the value false. Similarly, if the second radio button is selected, I should receive ...

What is the best way to extract a CSS rule using PHP?

Below is an example of the stylesheet I am currently using: #thing { display: none; } I am looking to retrieve the value of the 'display' property using PHP instead of Javascript. While I know how to do this with Javascript, I would prefer to u ...

The div extends beyond its parent due to its height

This issue is concerning. https://i.stack.imgur.com/on8t9.jpg The border of the div extends beyond the red line. I have set this for body and html: html { height: 100%; } ::-webkit-scrollbar { width: 0px; background: transparent; /* make scrol ...

How can I convert dates into a different format?

I have various event dates that are stored in the format 20131212 or 20100125, or any date submitted by a user for an event (formatted as yyyymmdd). I have created a function that displays all events for a specific month. However, the date is currently di ...

Discovering the selected radio button following a div's appearance

How do I determine which radio button is selected after clicking a specific div? For instance: <div class="largelines"> <p class="line">OPTION 1</p> <div class="delete"> <a href="#" title="Delete"></a> ...

Is it possible to incorporate both Bootstrap 3 and Bootstrap 4 within the same HTML file for separate div elements on a webpage? If so, what is the best way to achieve this?

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Using Bootstrap 3 and Bootstrap 4 in the Same HTML File</title> </head> <body> <div class="bootstrap3"> Some code her ...

Is it possible to merge data from two different models into a single table in Django?

I am currently facing a challenge in consolidating data from two models into a single table, with connectivity established through a Foreign Key. Despite my thorough search of the forum, I have yet to come across a solution that aligns with my specific dat ...

Show/hide functionality for 3 input fields based on radio button selection

I need assistance with a form that involves 2 radio buttons. When one radio button is selected, I want to display 3 text boxes and hide them when the other radio button is chosen. Below is the code snippet: These are the 2 radio buttons: <input type= ...

Implementing CSS Transform for Internet Explorer

Hello, is there a way to make this function in IE ?? I have been looking into IE transformations but it appears that they are not supported.. Is there an alternative method or something else? It works in other browsers like Firefox, Chrome, and Opera. I s ...

Struggling to implement touch event functionality for CSS3 spotlight effect

I'm experimenting with implementing touch events on an iPad to achieve a certain effect. Currently, I have it working smoothly with mouse events on JSFiddle at this link: http://jsfiddle.net/FwsV4/1/ However, my attempts to replicate the same effect ...

Is it possible to manipulate class attributes using an if statement in your code?

I am looking to dynamically change the classes based on user clicks on two different headings. When heading one is clicked, I want the font color to turn red and be underlined in red as well. The styling changes are already set up in the respective classe ...

Exploring IP geolocation integration within Rails 3

I am looking to add a dynamic feature to my homepage that will display the location object closest to the reader's physical location. Currently, I have a Location model with longitude and latitude fields. My goal is to retrieve the location model obj ...

Creating a div's height to dynamically adjust based on another div that is positioned absolutely

I am working on a web design project where I want the height of the content division to adjust based on its nested divs. Here is how I have set it up: <div id="content"> <div id="col1">content</div> <div id="col2">content&l ...