Utilize CSS Grid to adjust the size of an image

Hi there! I'm currently working on resizing an image using a CSS grid layout. Here's the CSS code I have so far:

/* Reset */
* {
    padding: 0;
    margin: 0;
}
html {
    height: 100%;
    background-image: url("/assets/images/background.png");
    background-repeat: repeat;
}
body {
    height: 100%;
}
/* Grid Layout */
.grid-container {
    height: 100%;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(12, 1fr);
}
/* Menu for Logged Out Users */
.menu-logged-out {
    grid-column: 3 / 11;
    grid-row: 2;
}
.menu-logged-out img {
    min-width: 100%;
    min-height: 100%;
    display: block;
    object-fit: cover;
}

Here is the HTML code I have to display the image within the grid:

!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>asd</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='/assets/css/header.css'>
</head>
<body>

<!-- Grid Layout -->
<div class="grid-container">
    <div class="menu-logged-out">
        <img src="#####">
    </div>
</div>


</body>
</html>

Unfortunately, I'm facing an issue where the image overflows the CSS grid. It looks something like this: https://i.sstatic.net/I485i.png

Any suggestions on how to resolve this problem would be greatly appreciated!

Thanks, Dominik :)

Answer №1

I have made some adjustments to the properties, I hope this meets your requirements

* {
    padding: 0;
    margin: 0;
}
html {
    height: 100%;
}
body {
    height: 100%;
}
/* Grid */
.grid-container {
    height: 100%;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(12, 8.5%);
}
/* Menu-Logged-Out */
.menu-logged-out {
    grid-column: 3 / 11;
    grid-row: 2;
    width: 100%;
    height: 100%;
    border: solid 1px red;
}
.menu-logged-out img {
    max-width: 100%;
    max-height: 100%;
    display: block;
    object-fit: cover
}
<div class="grid-container">
    <div class="menu-logged-out">
        <img src="https://via.placeholder.com/150">
    </div>
</div>

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

Easily collect form information from an HTML <form> element

I've been struggling to figure out how to retrieve data from an HTML form and display it in the console. What step am I overlooking? Here is the HTML code I'm working with: <!DOCTYPE html> <html> <head> <title>U ...

Decoding JavaScript content with Python

Currently, I am dissecting this specific portion of HTML <script type="text/javascript"> var spConfig = new Product.Config({"attributes":{"150":{"id":"150","code":"size_shoe","label":"Schuhgr\u00f6\u00dfe","options":[{"id":"494","label ...

Sequentially loading Bootstrap columns as the page loads

Is there a way to load columns one by one with a time gap when the page is loaded? Here's the code snippet that can achieve this: setTimeout(function() { $("#box1").removeClass("noDisplay"); },1000); setTimeout(function() { ...

How can I create a dimming effect on a webpage while a Details View Control is being displayed?

I have come across websites that use a technique where when a message box pops up, the rest of the webpage dimmed to emphasize the message. Currently, I am working on building a website using Microsoft Web Developer 2010, specifically an ASP.net site. On ...

Adjusting the Size of a Slideshow: HTML Tutorial

I'm currently working on a project to develop an interactive website using PHP and HTML for educational purposes. My main challenge is trying to implement a 'slideshow' similar to the one demonstrated in this video: https://www.youtube.com/ ...

An issue with the animation script in Ionic

I'm having trouble converting this to an Ionic application. Here's my code sample. Can anyone help me with putting this code correctly in Ionic? I'm trying to achieve something like this example <script src="https://cdnjs.cloudflare.com ...

Is it possible to seamlessly incorporate a square image into a bootstrap background image slider without having to crop the image?

I've exhausted all the different solutions I've come across on other platforms to resolve this issue, but I'm still unable to find a fix. So here's what I'm struggling with: The problem I'm facing involves finding the correct ...

When the window is resized, the text and images become jumbled and distorted

As a beginner in CSS, I am encountering an issue where the text and images on my website get distorted when I resize the window. How can I resolve this? HTML <img src="images\titles_03.jpg" class="tt1" > <img src="images\titles_05.jpg ...

Using JavaScript to swap between multiple images can be a powerful tool, but sometimes the wrong image

I'm having an issue with duplicating an image swap function. The problem is that the mouseout event is triggering image 3 on each of the three swaps, when I actually want it to trigger only on the last one. Can anyone provide some guidance on how to m ...

How can I customize the styling of Autocomplete chips in MUI ReactJS?

Trying to customize the color of the MUI Autocomplete component based on specific conditions, but struggling to find a solution. Any ideas? https://i.stack.imgur.com/50Ppk.png ...

Using PHP to nest a table within HTML and populate it with numbers ranging from 1 to 100

I am struggling with a practice question that involves creating a table using PHP nested in HTML. I need some help fixing it and understanding where I went wrong. The task is simple: generate numbers from 1 to 100 in a table, with each row containing 10 n ...

Changing animation during mouse hover off

I've been experimenting with using 'translate3d' and 'transition' on hover to animate a div into view. While the animation works smoothly when hovering over the element, I'm having trouble getting it to transition back out of ...

Designing divs that intersect

Struggling to replicate a design due to issues with the overlay section. I have separate divs for the menu bar, globe, and header text but positioning them as overlays is proving problematic. Attempted to use zIndex without success. https://i.sstatic.net/ ...

Displaying specific data points

I am encountering an issue where I want to select multiple values and have each selected value displayed. However, when I make a selection, I only see one value from a single box. I do not wish to use append because it keeps adding onto the existing valu ...

Tips for making a bookmark for your iframe content

Within this HTML code, there is a list element with the ID "about_ma" and an iframe named "page" that is initially hidden. <div id="navigation"> <ul id="nav"> <li id="about_ma"><a href="index1.php?name=about.php">Ab ...

Accessing and manipulating web elements using either XPath or CSS selectors

Having trouble selecting a specific piece of information using xpath or css selector. Error messages keep appearing. Can someone help identify the issue? This snippet is from my code: output = driver.find_element_by_xpath("//td[@class_= 'sku']" ...

Enhancing Website Design with Image Borders

I'm currently designing a website for a Media Agency and I'm looking to add a Frame-style border that gives the impression of being placed inside a television. The Television Image I have is a PNG file with a solid outer frame and a transparent i ...

Tips for showcasing colorful XML script within an HTML text field

In the process of developing a web application utilizing Symfony, I am looking to incorporate functionality that allows users to send XML requests to remote servers. As part of the design, I have included a textarea on the page where users can input their ...

The mysterious workings of the parseInt() function

As I begin my journey to self-teach JavaScript using HeadFirst JavaScript, I've encountered a minor obstacle. The chapter I'm currently studying delves into handling data input in forms. The issue arises when I attempt to utilize the updateOrder( ...

Error encountered in jQuery's addClass and removeClass functions: Unable to read the property 'length' of an undefined value

Upon loading my page, I aim to have some of the div elements hidden initially and display only one. Here is a script that accomplishes this goal: <script> $(document).ready(function () { $(".total").click(function () { $("#pi ...