The left side of my image doesn't quite reach the edges of the screen as desired

Even after setting the padding and margin in the parent container to 0, the image is still not filling to the edges. Here is the image. This snippet of code shows my JavaScript file:

import styles from './css/Home.module.css';

export default function home()
{
    return(
        <>
            
            <div className= {styles.container}>
                <div className= {styles.pictures}>
                    <img src = "../pictures/home.jpg"/>  
                </div>
            </div>
            
        </>
    )
}

This excerpt displays my CSS file:

.container{
    /* position: absolute;
    display: flex;
    justify-content: center;
    margin:0;
    padding:0;
    height: 100%;
    width: 100%; */
    margin: 0;
    padding: 0;
}
.container .pictures img{
    /* max-width: 100%;
    max-height: auto;
    margin-right: 10%;
    padding: 0px;
    border: 10px solid orange;
    border-top-right-radius: 12px;
    border-top-left-radius: 12px;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px; */
    margin-right: 20px;
}

I have been struggling with this issue for two days now. Despite resetting the padding and margin values to 0 in the parent container, no changes are visible. Additionally, attempts to adjust the picture's positioning with margin-right have proven futile. I am perplexed as to what may be causing this issue in my code.

Answer №1

Try using this CSS code instead of the one you initially provided

.container {
  width: 100%;
  height: 500px;
  margin: 0;
  padding: 0;
  border: 2px solid black;
}

.pictures {
  position: relative;
  height: 100%;
  width: 100%;
}

.pictures img {
  position: absolute;
  width: 100%;
  height: 100%;
  /* object-fit: contain; */
}

I've adjusted the picture container's positioning to be relative, and the image's positioning to be absolute. This ensures that the image will always remain within the container, allowing you to customize its dimensions as desired. Additionally, if you wish to ensure proper image fitting, simply uncomment the object-fit line.

Answer №2

Everything seemed to function properly during my code testing. Have you double-checked that the issue isn't related to padding or margin from a parent element? It's worth considering if it could be stemming from the body element's margins.

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

Exploring the functionality of window.matchmedia in React while incorporating Typescript

Recently, I have been working on implementing a dark mode toggle switch in React Typescript. In the past, I successfully built one using plain JavaScript along with useState and window.matchmedia('(prefers-color-scheme dark)').matches. However, w ...

Ways to stop a form input value from disappearing when clicking on other fields?

Upon loading the page, the form's campaignid input value is automatically filled. However, clicking on other fields causes it to reset to default. Is there a way to prevent this default behavior and preserve the input value of campaignid? I've ...

React state updates lag by one step

Whenever I click the next page arrow, my goal is to update the page number in the state and call getData() to fetch data from a remote database. However, I'm facing an issue where the state doesn't update immediately; it's always one step be ...

Unable to apply 3rd condition with ngClass into effect

I've been attempting to incorporate a third condition into my ngClass. Initially, I managed to get two classes working in my ngClass to change the row colors alternately. [ngClass]="{ totalrow:i%2 != 0, odd:i%2 == 0}" Now, I'm trying to introdu ...

Slider UI handle in jQuery sliding out of the div container

Could you assist me with a technical issue I am facing? I need to know how and where to prevent the .ui-slider-handle from exceeding the div when it reaches 100%. Feel free to check out the live preview at https://codepen.io/Melwee/pen/Exjwoyo I have inc ...

Handling an HTTP Get request by utilizing Server-Sent Events (SSE)

Exploring the possibilities of HTML5 and node.js has led me to test out Server Sent Events successfully using this example. My experiment then involved responding to a button press with an SSE. Upon clicking the "Increment" button, I extracted a number fr ...

Change the background color on hover without affecting the text color

I am having some trouble with my code. I can only change the color of the "popup1_btn" button when hovering, but the text color remains the same. If I use .popup1_btn a:hover, it only changes the background and text color of the text, not the entire button ...

Function exhibiting varying behavior based on the form from which it is called

Currently, I'm utilizing AJAX to execute a server call, and I've noticed that the behavior of my function varies depending on its origin. Below is an excerpt of the code that's causing confusion: <html> <body> <script> ...

What impact does reducing the window size have on my header?

While working on a website with a navigation bar, I encountered an issue where the navbar was not responsive. When the window size was reduced, the nav bar shifted to an awkward position vertically, as shown in the first image. The navbar shifts below the ...

Conceal the scrollbar while navigating within the parent container

I'm currently working on implementing a parallax header on my WordPress site using the Divi theme. Below is the code I have so far: <div class="parallax"> <div class="parralax__layer parallax__layer--back"> <img src="https://crisp ...

Experiencing Difficulty Retaining Checkbox State Using LocalStorage Upon Page Reload

At the moment, I have a script that automatically clicks on a random checkbox whenever the page loads or refreshes. Through localStorage, I can also view the value of the input assigned to the randomly selected checkbox. However, I'm facing an issue ...

Manipulating divs by positioning them at the top, left, right, bottom, and center to occupy the entire visible portion of the page

Many suggest avoiding the use of table layouts and opting for divs and CSS instead, which I am happy to embrace. Please forgive me for asking a basic question. I am looking to create a layout where the center content stretches out to cover the entire visi ...

What makes CSS Overflow: hidden toggle from working initially to suddenly not working?

There seems to be an issue with the code below - it works fine initially, but as soon as I tweak the height values for .Image, it stops functioning as expected. The test image starts overflowing instead of staying hidden, and no matter how many times I a ...

Fixing TypeError in React App: How to Resolve the "Cannot read property 'prototype' of undefined" Issue

I am completely new to JavaScript and I am struggling to understand the error that keeps popping up. After doing some research, it seems like the error could be due to a poorly written function or something along those lines. Here are the classes involved ...

Establish a connection to a regular socket by utilizing WebSocket technology

I am attempting to connect a client interface to a hardware device using WebSocket in a browser like Chrome. The code snippet I have been using for connection is as follows: var ws = new WebSocket("ws://127.0.0.1:13854"); ws.onopen = function() ... Howev ...

The clickable area for the radio button cursor is too large

As I embark on my journey with HTML and CSS, I have encountered two issues while creating a form: The spacing between the question and answers is too wide. The second picture depicts how I would like it to appear. The cursor:pointer seems to be extending ...

Using Typescript and JSX to render a component that has been passed as an argument

I am seeking to create a function that will render a React component passed as an argument. I aim to accommodate both Component and StatelessComponent types with the following approach: function renderComponent(component: React.ComponentClass<any> | ...

remove all content from tinymce editor in react

I'm currently utilizing the tinymce editor within my project. Here's the code snippet: <Editor initialValue={selectedDocument.html_content} init={{ pl ...

What is the best solution for adjusting spacing in justified text columns within bootstrap?

As I work on creating a div with two columns, I am facing an issue with maintaining justified alignment. It looks great with two divs using col-lg6- in Bootstrap, but when I switch to col-md-6 or col-sm-6, there are excessive spaces between words to keep t ...

Modifying the CSS design of specific columns within a table created using JavaScript

A unique way to showcase JSON data in a table is by utilizing a for loop within a function. This method, however, does not assign an ID or Class to the table. To hide the final three columns of this table using CSS, the following code can be employed (whe ...