The CSS div extends beyond the border of its containing div

Currently, I am in the process of creating a responsive form for my webpage. However, I have encountered an issue with styling where the div containing the form content is not properly aligned within the main div as confirmed by adding borders to it. Despite knowing that there must be a simple solution, I am unable to find it.

When viewed on a mobile device, the div appears off-centered on the page. Here's what it looks like:

https://i.sstatic.net/LbvPQ.png

Here is how the content div actually appears:

https://i.sstatic.net/F9hQQ.png

Below is the CSS code for the 'new_user' class (the inner div):

.form.new_user {
            display: inline-block;
            width: 100%;
            min-width: 230pt;
            max-width: 270pt;
            border-color: #3e3e3e;
            border-width: 1px;
            border-style: solid;
            padding: 5pt;
        }

        @media screen and (max-width: 600pt){
            .form.new_user {
                min-width: 100px;
                max-width: inherit;
            }
        }

And here is the CSS for the content div:

.content {
    padding: 7pt;
    margin: 7pt;
}

Thank you for any help in advance!

EDIT:

Below is the HTML code:

<body>
<div class="content">
<div class="form new_user>
</div>
</div>
</body>

Additionally, this is the CSS for the body:

body {
    margin: 0;
    font-family: Helvetica, sans-serif;
}

Answer №1

Due to the nature of the CSS box model, when you assign width and height to an element, it typically only applies to the content box of that element. Any borders or padding will be added on top of the specified width and height, affecting the overall size of the rendered box.

To ensure that the specified width and height include both the content box and any borders/padding, you can simply add *{box-sizing: border-box;}. More information can be found here.

*{box-sizing: border-box;}
body {
    margin: 0;
    font-family: Helvetica, sans-serif;
}
.form.new_user {
            display: inline-block;
            width: 100%;
            min-width: 230pt;
            max-width: 270pt;
            border-color: #3e3e3e;
            border-width: 1px;
            border-style: solid;
            padding: 5pt;
        }
.content {
    padding: 7pt;
    margin: 7pt;
}

        @media screen and (max-width: 600pt){
            .form.new_user {
                min-width: 100px;
                max-width: inherit;
            }
        }
<body>
<div class="content">
<div class="form new_user">
</div>
</div>
</body>

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

Position the image between two div containers in the center of the screen, ensuring it is responsive and does not overlap with any text

I've been working on trying to position an image between two divs on my webpage. So far, I've managed to place the image there but it's not responsive (only displays correctly at a width of 1920) and ends up overlapping the text in both divs ...

Having trouble displaying an image using output buffering in PHP and HTML, only to end up with a broken image

I've been working on a script that combines two PNG images - one as a watermark and the other as the source image. The idea is to blend these images together using the imagecopy function and display the result in the browser. However, despite my effor ...

Creating a stunning visual effect in Angular: Nebular flip card with varying front and back heights

Is it possible to customize the heights of Nebular card front and back individually, rather than having them automatically adjust to match the content? For example, setting a specific height for each side regardless of the amount of text or content on th ...

Use sed to extract integers from HTML based on various criteria

Before we continue, I must confess: I realize using regex to parse HTML is generally frowned upon, but if Chuck Norris can do it, why can't I? ;) My goal is to extract specific data from this HTML page: http://pastebin.com/unAifctF based on thre ...

Form that is generated dynamically is malfunctioning

Having issues with an AJAX function that dynamically populates a list of elements from the database. Each element includes a display picture and a name, along with a hidden field containing a variable captured on another page via POST to display image and ...

Modify the bootstrap dropdown background to display only an image

I am looking to make the image in a dropdown/dropup menu fill the entire background of the dropdown. Currently, there is still white space visible around the image. How can I ensure that the dropdown shows only the image and includes a scroll wheel? Addit ...

Removing the "%20" code from URLs in your Django project

Currently, I am using Django 1.3 and implementing template inheritance. However, I have encountered an issue with the /static/ settings path once I navigate away from the home page. The problem arises when I load home.html, which inherits from base.html - ...

The first-child and last-child selectors are not working properly in the CSS

In the family of elements, the first child should proudly show off the image icon for home while the last child remains humble without any background imagery: Check out the evidence here: http://jsfiddle.net/gUqC2/ The issue at hand is that the first chi ...

Understanding the concept of displaying labels even when the field is empty in React

One issue I am facing is with a label that displays a string from a text input filled in by the user. The string is saved in a variable called question and shown as: <label className={css('form-title-label')}> {question} </label ...

JavaScript and jQuery experiencing difficulty rendering proper style and image in output display

I am currently working on code that extracts information from a JSON variable and displays it on a map. The code looks like this: marker.info_window_content = place.image + '<br/>' +"<h4>" + place.name + "</h4> ...

How can the end event of a custom CSS animation be bound using jQuery or JavaScript?

We are currently managing multiple animations on the same object and need to execute different actions once each animation is complete. At present, we listen for the webkitAnimationEnd event and use a complex if/then statement to handle each animation sep ...

Exploring test automation methods for selecting HTML elements - whether based on Element ID or DataAttribute

As I work on implementing ID's for UI Test automation, I am considering whether using data-attributes (such as data-testHandle="mybutton") would be a more readable option for future developers. These ID's are solely for testing purposes. Accord ...

Styling will be applied to the first element that matches the CSS

I have a series of div sections with repeated paragraphs, and I am looking to apply specific CSS styles to only the first matching paragraph within each div. div.example1 p.special~p.special { color: green; } <p>Top Paragraph</p> <di ...

How can you identify when an input value has been modified in Angular?

For my current project, I am developing a directive to be used with a text input field in order to format currency input. This directive has two HostListeners - one for when the input loses focus and one for when it gains focus. When the blur event occurs, ...

Tips for deleting directory path from a file name

Similar Question: How to extract file name from full path using PHP? echo '<td width="11%" class="imagetd">'. ( ( empty ($arrImageFile[$key]) ) ? "&nbsp;" : htmlspecialchars( is_array( $arrImageFile[$key] ) ? implode(",", $arrImag ...

Is there a way to align text in the middle while having different icons on each side?

Is there a way to center align the text in this image with minimal use of CSS/HTML? The icons on the left are causing it to be off center: https://i.sstatic.net/TKOYG.png Below is the relevant HTML and CSS for this top section: <div class="navbarhead ...

What is the best way to retrieve the values of "qty" and "price" and access them within the item [array] without knowing the IDs?

I am currently working on a shopping cart project, specifically on the "previous orders" page to display order details. My goal is to output this information in an (.ejs) file. The data structure includes nested objects, and within one object, propertie ...

Retrieve the HTML content starting from the nth tag and beyond

I am currently working on a table... <table class="col-xs-12"> <thead class="testhead col-xs-12"> <tr class="col-xs-12" id="row1" style="color: white;"> <th>0</th> ...

Basic color scheme

I'm attempting to change the background color behind a partially transparent .png div. The CSS class that modifies the div is ".alert". Manually editing the .alert class background color works perfectly, and now I want to automate this on a 1-second c ...

A tutorial on dynamically adding fields with a dropdown list (populated from a database) and a text box using PHP and JQuery

I have multiple form components that I need to add dynamically, allowing users to add more than one. Firstly, there is a dropdown list with values populated from MySQL, followed by a text box for inquiries entry. The dropdown list displays a list of users, ...