Expansive Child Division with Ample Margins

I'm currently working with a nested set of divs and I need the inner div to occupy the full width without extending beyond the parent div's margins. Despite trying to use max-width:100%, it hasn't been successful so far. For this particular case, #test2 should be full width minus the left margin.

HTML

<div id="test">
    <div id="test2">
        <div>123</div>
    </div>
</div>
<div id="test3"></div>

CSS

#test{
    width:100%;
    height:100px;
    float:left;
}
#test2{
    margin-left:51px;
    float:left;
    width:100px;
    max-width:100%;
    background:blue;
    height:100px;
}
#test3{
    width:50px;
    float:left;
    background:red;
    height:100px;
    margin-left:-100%;
}

JS FIDDLE

I would appreciate any suggestions on how to achieve this without resorting to JavaScript or introducing new CSS commands like calc. Thank you!

Answer №1

Give this a shot:

min-width:120px;
max-width:100%;

Answer №2

Replace the width property from 100px to 100% as shown below:

#test2{
margin-left:51px;
float:left;
width:100%;
background:blue;
height:100px;
}

Answer №3

Check out the solution provided below:

<a href="http://jsfiddle.net/LHSfQ/24/" rel="nofollow">FIDDLE</a>

This should help resolve your issue.

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

Why Isn't AJAX Displaying the Output from PHP?

Currently, I am implementing ajax to display a string received from a php file. This particular php file is generating rows for an html table. My goal is to have ajax place these rows within a with a specific id that resides inside a and I want this oper ...

immediate removal upon pressing the button

Struggling to remove data from a datatable when clicking the delete button for quick admin side action. My code isn't functioning properly, even after attempted fixes. Here's my code: <div class="table-responsive"> <table id="datas" cl ...

Is the background color not being implemented?

I'm struggling with an issue - I can't seem to apply a background color to my top bar. I've tried multiple times but it's still not working. Could you please help me fix this error? Below is the code for my simple top bar: topbar.htm ...

Unable to interact with a button element of type="button" using Selenium, but successful with elements of type

In my attempt to interact with the webpage, I am specifically focusing on this button: <button class="button-text-like marg-l-0 float-l desktop-only remove-button" data-bind="click: $root.removeCartItem" type="button"> <i class="gicon-cross">& ...

Can Bootstrap CSS take precedence over a theme's styling?

After working with various WordPress theme templates, I am now ready to take on the challenge of creating my own custom themes. One aspect I would like to incorporate is utilizing Bootstrap to ensure my website is responsive. However, I have some questions ...

Tips for eliminating the default hover and active states from a textfield in Material UI

Currently, I am in the process of creating a login form and have incorporated Material UI textfields. However, I am facing an issue where the textfield's default hover and active states cannot be removed. Below is my password textfield: (https://i.st ...

Design a captivating Profile Picture form using HTML and CSS styling

In my form, I am looking to include a user's Profile picture which should be displayed in either a circular or rectangular shape. Initially, the image area will show a black background or a placeholder image. When the user clicks on this area, they sh ...

Tips for choosing elements in jQuery that do not contain a particular element

How can I target elements in jQuery that do not contain a specific element within them? I am trying to create a sidebar that will close when the user clicks either the menu or the sidebar itself, excluding dropdown menus. Below is the structure of the menu ...

Closing the space between navigation bar choices

I'm currently working on my website's navbar menu and struggling to eliminate the gap between each of the navbar links. It seems that the li attributes with the class dropdown are slightly wider than the rest of the links, causing this issue. I&a ...

Trouble getting proper alignment displayed with JavaScript and CSS

If anyone has a solution for printing content in a div using JavaScript and CSS, please help. The main div with the id 'preview' contains content taken from a database using PHP and MySQL. However, the data on the print page appears vertically an ...

I'm encountering an issue with VUEJS components including my show route in their get call. How can I make my journals/:id pages function properly without encountering a Mime

I encountered a MIME type error stating: Refused to apply style from 'http://localhost:8080/journals/assets/css/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. ...

Creating a mandatory 'Select' component in Material UI with React JS

Is there a method to show an error message in red until a choice is selected? ...

How can you prevent an element from overflowing when employing window.pageYOffset and using a switch case to alter the background color at specified pixel thresholds?

I want the <body> element's background-color to change every 500px as I scroll down. I've scoured the web for answers, but still can't figure out what's going wrong. Please review the code. However, Firefox Browser indicates that ...

Issues with $.post function causing HTML to be displayed instead of the intended value

I have a question about sending the value of an HTML element to the server using POST. When I alert the result, I expect to only see the value but I am also getting the HTML content of the PHP file included in my code. Why is this happening? function post ...

"Enhance Your Website with Drag-and-Drop Cart Functionality using HTML

Seeking assistance from anyone who has the knowledge. I've searched through similar questions on this platform but haven't been able to resolve my issue. Currently, I'm working on developing a basic shopping cart using HTML5 (Drag and Drop ...

What is the method for loading a subcategory based on the category by invoking a jQuery function within the <td> element of a JavaScript function that adds rows dynamically?

Whenever I click the add row button, the category dropdown list successfully loads. However, when I select an option from this category list, the subcategory does not load any list. The Javascript function responsible for adding rows dynamically is as fol ...

Issue with jquery curvy corners not functioning properly on Internet Explorer 8

Check out my website at If you view the page in IE8 and then in IE7 compatibility mode, you'll notice a strange issue. The box on the right disappears in IE8 but displays perfectly rounded corners in IE7. I am currently using the jQuery Curvy Corner ...

SASS mixin that enables flexbox capabilities without supporting older, legacy versions of flexbox

Is it possible to provide support for browsers lacking flexbox compatibility (such as IE) while using SASS mixins? I have been quickly implementing the display:flex property with the following mixin. However, I am facing challenges with IE and need to man ...

Struggling to make `align-items="baseline"` function properly

I'm encountering an issue with alignment in my sandbox project. Specifically, I want the bottom of texts with different font sizes to be on the same y axis but I can't seem to figure out how to make it happen. Check out this picture to see exact ...

Deactivate a specific button within a row on a Primeng table by clicking on it

I'm trying to modify my primeng table so that each row has a button, and when I click on a button, only that specific button should be disabled. However, in my current code, all buttons are getting disabled with a single click. Can someone please help ...