Adjust the child element's width to be the same as its parent, taking into

Is there a way to adjust the width and alignment of the .inner class to perfectly match its parent?

Potential solutions include:

  • Applying box-sizing: content-box and adjusting the left property by the border size.
  • Adjusting both the left and right properties by -1px each.

However, these solutions may not be ideal as they require knowledge of the parent's border size or the use of box-sizing: content-box, which we want to avoid.

Additionally, changing the DOM hierarchy is not an option since we need to style elements generated by a JS-framework.

Do you have any better alternatives?

*, *:before, *:after{
  box-sizing: border-box;
 }

.outer{
  border: 1px solid black;
  width: 50%;
  position: relative;
  }

.inner{
  position: absolute;
  top: 100%;
  left: 0px;
  width: 100%;
  border: 1px solid black;
  // box-sizing: content-box;
  // left: -1px;
 }
<div class="outer">
  text
  <div class="inner">Inner</div>
</div>  

Answer №1

An alternative approach could involve leveraging the CSS3 outline attribute, which provides a similar functionality to border without increasing the element's width.

Answer №2

Here is a straightforward solution:

(All other adjustments are not effective - you must set left: -1px;, as there is no way to correlate it with the border width.

.outer{
  border: 1px solid black;
  width: 50%;
  position: relative;
  }

.inner{
  position: absolute;
  top: 100%;
  width: 100%;
  border: 1px solid black;
  left: -1px;
 }
<div class="outer">
  text
  <div class="inner">Inner</div>
</div>

Answer №3

.container{
  border: 1px solid black;
  width: 50%;
  position: relative;
  }

.content{
  position: relative;
  top: 100%;
  left: 0px;
  width: 100%;
  border-top: 1px solid #000;
 }

Does this meet your requirements? Feel free to utilize the border of the container div, which is already positioned at the bottom and spans the width of the container.

To achieve this effect, simply add border-top: 1px solid #000;.

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

Maintaining the image's aspect ratio while cropping it to fit within the maximum or minimum height

Is there a way to make an image responsive by resizing it while keeping its aspect ratio intact at all sizes? I want the height of the image to stay fixed above 650px, cropping the top and bottom to maintain the ratio without stretching. Additionally, I do ...

The CSS Columns layout feature is not functioning properly in Firefox browser

I attempted to design a layout with 5 columns where the height adjusts based on its content, so I couldn't set a fixed height. However, my codepen project isn't functioning as expected. Visit this link to view it. body { height: 100%; } #ou ...

"Using Vue's v-model directive in conjunction with a select input

I'm attempting to set any option within my select input as a value in an object. My goal is to utilize v-model for this, but I'm still unsure of the process. Below is my current attempt: <div class="select-wrapper"> <select r ...

Find the IDs of all input boxes that have a specific class attached

Is there a way to retrieve the ID of an input field that has a specific class attribute? For example: <input id="first" class="failed" /> <input id="last" class="failed" /> <input id="city" class="failed" /> <input id="state" class=" ...

Trouble encountered when implementing multiple conditions for checkboxes in an Angular 8 application

In my form, there are four checkboxes (3 for options and 1 for setting a plan) which have specific requirements: If all three options are checked, the set plan checkbox is automatically checked and the options disappear If the set plan checkbox is checke ...

What are the steps to create a basic star-rating system?

I attempted to create my own star rating system using HTML and CSS, but encountered issues with its functionality. While solutions like using direction: rtl or float: right worked, I am unable to implement them due to constraints related to PHP. Is there ...

Adding a scroll bar: A simple guide

My project includes hidden menus and submenus, but I'm having trouble accessing the last menu because there is no scroll bar. How can I add a scrollbar to my project? If you'd like to check out my project, click here. ...

The HTML form does not function properly on OSX when it contains buttons with Cyrillic names in windows

After installing a site locally on my OSX, which was developed under Windows with cyrillic encoding for some string values, I encountered an issue. I noticed that certain buttons with cyrillic values were not functioning properly until I changed the value ...

Having trouble with my PHP index not properly redirecting to the dashboard file after logging in

I have created a login form and implemented some functionalities. One of the key features is redirecting to the dashboard file after successful password validation. I attempted to troubleshoot using chatgpt, but the issue persists. I am reaching out for as ...

Retrieve the text input from the text field and display it as

Is there a way to display what users enter in a textfield when their accounts are not "Activated"? Here's an example: if(active == NULL);{ //I've attempted the following methods. //In this scenario, 'username' is the name of ...

How can the placeholder of a Kendo Multiselect widget be altered through CSS?

Is there a way to modify the placeholder text of a kendo multiselect widget using CSS? .k-multiselect-wrap > .k-input { color: #f02c0c; /* set the default input color */ content: "HOME"; } Unfortunately, this method does not achieve the desired ...

Altering the innerHTML of a <p> tag with a smooth transition

I am a beginner in the world of web design. I am currently working on a project where I need to continuously change the text inside a <p> element with a transition effect similar to a slideshow. Below is the code I have so far: <p id="qu">S ...

Make sure to enable contentEditable so that a <br> tag is inserted

When using a contentEditable, it automatically wraps words to create a new line once the width of the editable area is reached. While this feature is useful, I am facing an issue when parsing the content afterwards as I need it to insert a <br> tag ...

Is there a way I can insert a line break right before a lengthy hyperlink?

I'm currently exploring ways to ensure that a line-break occurs before a link in order to prevent it from being wrapped on a new line. To clarify, let's consider a scenario where I have a few words followed by a long link displayed on a narrow d ...

Please request user input in order to generate a multiplication chart

Is there a way to ensure that the program works properly so that when the user inputs a value, it is included in the multiplication table? <html> <head> <title> Multiplication Table </title> <style> body{ font-family: aria ...

Determining the timestamp for when an AJAX request and response are executed

I'm looking to use a stopwatch to track the seconds elapsed between sending an AJAX request and reaching the success function. ...

Tips for submitting a form and retrieving session count without the need to refresh the page after submitting the form

I have set up a form that includes hidden input fields to send data to a PHP script. The script stores the values in an array of sessions by using AJAX to reload the page. Once the data is submitted successfully, an HTML alert message is displayed in <p ...

Avoid making the check mark disappear in an SVG animation

After perfecting my CSS animation, I have the circle looping around to complete its shape while a check mark fills in the middle with a slight delay. Once both shapes are completed simultaneously, the check mark disappears. The reason for the disappearing ...

Preserving CSS styling while loading an HTML page with InnerHTML

By using the following code snippet, I have successfully implemented a feature on my website that allows me to load an HTML page into a specific div container when clicking a link in the menu. However, I encountered an issue where the background color of ...

Out-of-sync movement in animated characters

Looking for some assistance with my page coding. I have a scenario where two stars are moving around a button, simulating an animation by incrementing the CSS properties top and left. Initially, everything appears fine and they move synchronously. However, ...