Tips for maintaining image dimensions on the screen using html and css?

Hello everyone! I am excited to be diving into the world of html and css, as I have a course lined up for next month. However, I currently have a project that I need to tackle on my own. One issue I'm facing is keeping the products within the screen size. How can I achieve this?

Here is the html code snippet:

<div class="product-container">
    <li *ngFor="let product of products">
    <div class="product-title">

            <h2>
                {{product.title}}
            </h2>
            <div class="product-details">
                <img id="productImage" src={{product.imageUrl}}>
                <div>
                    <p>Description:</p>
                    <p>{{product.description}}</p>
                </div>
                <div >
                    <p>Location: <span>Mock Location</span></p>
                </div>
    
            </div>
            
        </div>
    </li>

</div>

And here is the css styling I have implemented so far:

.product-container {
    display: flex;
    gap: 90px;
}
.product-container li{
    list-style: none;
}
#productImage{
    height: 250px;
    width: 350px;
}
.special-details{
    display: flex;
    justify-content: space-between;
    font-size: large;
}
.product-title{
    text-align: center;
}

I admit it does not look great at the moment: https://i.sstatic.net/0VAZJ.png

I would greatly appreciate any advice or help in improving the layout. Thank you!

Answer №1

The margin css property is causing them to overflow the boundaries of the itemSection. To maintain the layout of the items, you can apply the following styles:


.item-section {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); // additional line
}

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

Send the error message to the ajax error handling function

Utilizing jQuery's ajax, I am invoking a controller method on the client side. $.ajax({ url: "/Services/VendorServices.asmx/SendVendorRequestNotifications", type: 'POST', contentType: "application/json", dataType: "json", ...

Utilizing the length property of arrays for mathematical computations

I'm currently exploring the possibility of achieving this using javascript. In my scenario, I have an array named cart that consists of objects with product.quantity, and I aim to incorporate the value of cart.length in a calculation. However, I cons ...

Retrieving POST information from a PHP script

I have 3 php files and I need to extract the month data from form1.php for use in form3.php. However, the data processing also involves form2.php. How can I specifically retrieve the month from form1 and display it in form3? form1.php <form action=&quo ...

A step-by-step guide on inserting a date into a MongoDB database using data from

I have a JSON file that contains an object with a date. How can I ensure that this date field is correctly inserted as a "date" data type in MongoDB? This needs to be achieved using Node.js. { "name": "Jeff Johnson", "email": "<a href="/cdn-cg ...

What steps do I need to take to activate the spell check function for an HTML text area?

Is it feasible to activate the spell check functionality in HTML text areas while utilizing ColdFusion? ...

What is the method for creating a vertical line similar to this one?

I am looking to create a contact information list similar to this: Sample Could someone please advise on how to add a vertical line between the email and hotline sections, as shown in the example image? Thank you in advance! ...

Tips for directing attention to a specific row with an input field in JavaScript

I duplicated a table and added an input field for users to search or focus on a specific row. However, there are two issues: When a user enters a row number, the table displays the wrong row - for example, if the user enters 15, the table shows row number ...

File not being successfully sent through form submission using Jquery

I have created a form setup like this: <label for="pdffile">Please Upload File</label> <form class="form-horizontal" role="form" method="POST" name="upload" id="upload" enctype="multipart/form-data"> {{ csrf_fi ...

Finding the Xpath for an element that contains only a span tag, with identical attributes except for the text within

I am struggling to find the xpath for a button element that says 'Cancel'. <div class="uipresk"> <button class="something" role="button" type="button"> <span class="thisthing">OK</span> </button> ...

Translating SQL Query Results to JavaScript Array

I am currently working on creating a video gallery with blueimp. You can find the documentation for blueimp here. I am facing a challenge as I am not very experienced with MySQL and need some guidance on how to retrieve query results containing YouTube URL ...

Customizing the display field in an ExtJs Combobox

I am working on a java web application that utilizes an entity class to populate a combobox with ExtJs. The issue I am facing is as follows: Some entries in the displayField may contain html code. To prevent any issues, I used flexjson.HTMLEncoder during ...

Is the sliding navigation glitching due to the video background?

Currently, I am in the process of developing a website with a captivating full-page video background. The nav menu gracefully slides out from the left side using jQuery UI when users scroll down to view the site's content. To view the work-in-progres ...

Nested React Components in React Router Components

class AppRoutes extends Component { render () { return ( <Suspense fallback={<Spinner/>}> <Switch> <Route exact path="/" component={ HomePage } /> <Route exact path="/acti ...

Eradicating a character from an Object using Jquery/Javascript

Looking at this code snippet, it appears that the 3rd column is not calculating correctly due to a comma being present in one of the values. Is there a way to rectify this issue without directly removing the comma? I am aware that using .replace(/,/g,&apos ...

What could be the reason for Sequelize to completely replace the record when updating in a put request?

I've been attempting to implement an "edit" feature within my project, but I've hit a roadblock in the process. Here's a snippet of the put request code: export const updateEvent = (event, id) => (dispatch, getState) => { request ...

What impact does setting a variable equal to itself within a Dom Object have?

Within my code example, I encountered an issue with image sources and hrefs in a HTML String named tinymceToHTML. When downloading this html String, the paths were set incorrectly. The original image sources appeared as "/file/:id" in the String. However, ...

How can I make my navbar visible once a specific section has been reached?

Is there a way to conditionally display my navbar in react only when a specific section is reached? Currently, I am monitoring scroll position but this method becomes unreliable on larger screens due to varying scroll positions. I need the navbar to beco ...

Ways to modify the input field value in my form based on the current page context

I am currently developing a website for a sports event organization company using Angular, HTML/CSS. The focus of this website is on the triathlon sport and it consists of several stages. On the home page, there are five image tags representing each stage ...

Guide on aligning a division within another division?

Included below is my HTML code: <div id="background_div"> <img id="background_img" src="images/background.jpg" alt="dont matter"> <i class="material-icons">perm_identity</i> <div id="dropdown"> <ul id=" ...

Difficulty encountered while using React.js map function to access specific JSON data

I'm encountering an issue where I am unable to read data from a JSON file. After checking that the data is stored in the component state and logging it to the console once the component is mounted, I attempted to render the URL string from the JSON da ...