Header width does not expand to match sibling width when sibling content overflows

When my current code displays a container with a header and content div, the header does not extend to match the sibling width when the sibling overflows. I initially thought using flex-1 would solve this issue, but it didn't work. Is there another solution for this problem?

<div class="flex w-[500px] flex-col overflow-x-auto bg-red-300">
  <h1 class="flex-1 bg-orange-300">Header</h1>
  <div class="h-96 w-[750px] bg-green-300">Content</div>
</div>

Check out Tailwind Play for more.

Answer №1

To make the child component extend to the same width as the parent, you have two options available:

(i) Create a div that will wrap around both the Header and Content:

<div class="w-[500px] overflow-x-auto bg-red-300">
  <div class="w-[750px]">
    <h1 class="bg-orange-300">Header</h1>
    <div class="h-96 bg-green-300">Content</div>
  </div>
</div>

(ii) Assign the same width to both Header and Content (you can use a variable for this):

<div class="w-[500px] overflow-x-auto bg-red-300">
  <h1 class="w-[750px] bg-orange-300">Header</h1>
  <div class="h-96 w-[750px] bg-green-300">Content</div>
</div>

No need to use flexbox in this scenario.

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

Troubleshooting issue with jQuery validation functionality not functioning properly with select dropdown

My default validator settings include displaying a red error message when validation fails. However, it works on Input and textareas, but not on select. $.validator.setDefaults({ ignore: "", errorPlacement: function(error, element) { ...

Tips for executing a function on a specific class selector using the document.getElementsByClassName method

When I click on a specific class, I want to implement a fade-out function in JavaScript. However, I am struggling to make a particular class fade out successfully. I attempted to use the this keyword, but it seems like I might be using it incorrectly bec ...

What makes styling the iconic Browse button (file input) such a challenge?

Many people are curious about how to style a file input in an HTML form, as evidenced by the plethora of well-known techniques available. However, I am more interested in understanding why we encounter such technical limitations that seem so trivial and fr ...

Exploring Bootstrap datatables to search through nested table data with Codeigniter

I have implemented a table using bootstrap datatables and successfully enabled search functionality within the table. However, I have also included nested tables within each row of the main table. These nested tables are supposed to be displayed when clic ...

Unable to center text within a CSS div rotated 90 degrees due to width limitations caused by rotation; solution involves utilizing flexbox

Currently, I am working on creating a tab positioned on the right side, as illustrated in the image below: https://i.sstatic.net/QGTEB.png The desired width for the tab on the right is only 25px. To achieve this layout, I am utilizing flexbox for the cont ...

Storing an email address in local storage using the Angular CLI

I'm currently working with Angular CLI and I want to save an email in Local Storage. Here is my HTML code: <input type="text" name="email_field" id="email"> <input type="submit" value="registration" onclick="save_email()"> Here is my Ty ...

Incorporating PlayN games into an HTML/JS application

I've been considering creating a game using PlayN. While it's great for the game itself, I would rather handle menus, navigation, high-score lists, etc in HTML (possibly with GWT). If I develop a game using PlayN, are there ways to integrate it ...

I am currently facing the challenge of how to properly upload a font to my website

One issue that arose was the font displaying incorrectly, despite all connections being correct. After investigating the HTML and CSS source code, I found the solution on how to properly implement the font, which resulted in it being displayed correctly. I ...

Moving responsive table cell to a new line

Currently, I am faced with the challenge of embedding third-party content via dynamic means without any knowledge of Ajax or jQuery. My question is whether it's feasible to move a table cell onto a new line, essentially creating a new row. The embedd ...

Tips for identifying when the value of a div changes using Selenium

Currently, I am using selenium to gather data from a website. The structure consists of a parent div with 30 children divs. Periodically, one value is updated and stored in the first child while the last child is removed, maintaining a history of the las ...

Avoid combining empty inputs using JavaScript/jQuery

Currently, I have a group of inputs that are automatically combined into a single output. However, the issue arises when empty inputs are concatenated as well. As it stands, users have to manually delete the unnecessary spacing or commas left by empty inp ...

Implementing designs and incorporating shortcodes in the page template of WordPress

Struggling with adding shortcodes and bullet items to my page.php file in order to display a plugin on all pages due to the lack of widget areas. Unfortunately, the plugin is not showing up on the pages and the bullet items are not styled correctly. Is th ...

Interactive Dropdown-Buttons dynamically inserted

I have been utilizing a third-party library called Materializecss from this link: My issue arises when attempting to create a Dropdown feature upon clicking a button. It works perfectly fine when I manually place the button in the HTML and click on it, tr ...

Different responsibilities assigned to a single user in PHP

I'm thinking about setting up a back office for my website. The issue I'm facing is that if a user has multiple roles, I want them to be able to choose which role they want to work with. However, I've been struggling to figure out how to imp ...

How to create a Vue.js animated navbar with scroll opacity

I am looking to create a fixed navbar that changes opacity based on user scrolling behavior. Initially, I want the navbar background to be transparent and then transition to white as the user scrolls down the page. An example of what I am trying to achieve ...

How to trigger a JavaScript function using a button click

I've been struggling to figure out why my JavaScript code isn't functioning properly within Ionic. Can anyone guide me on how to store a number in a variable, display that variable, and increment it when a button is clicked? I have successfully ...

What are some ways to customize the appearance of Skype for Business HTML messages when integrating with the Bot Framework?

Recently, I created a bot using Microsoft's bot framework and I've noticed that while it supports sending HTML messages, the CSS styling doesn't seem to work. As a result, the HTML messages appear quite bland and I'm really eager to add ...

Modify content once it has been rendered using Jquery

After loading, I want to adjust the style of a specific element. However, I am running into a null pointer issue. function loadFriends() { $("#friendsContainer").load("friends.html"); } selectCurrentSetting(); function selectCurrentSetting() { c ...

How to Stop Chrome from Prompting to Save Password with PHP Header Location

I would like to address the issue regarding Chrome's default behavior of prompting users to remember their sign-in details. Specifically, I want this prompt to appear only when the password is correct, not when it is incorrect. While I have searched ...

Develop an Android application package

Recently, I developed a fun and engaging memory game using HTML and Javascript in Phpstorm. Now, I am eager to convert my creation into an APK file so that I can publish it on Google Play. The only issue is that I am not familiar with the process of creati ...