Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Make CSS Max Width the width of an individual element?

I am trying to make a whole div's max width property the width of one element inside of it, how would I be able to do this? Or would I not be able to do this at all.

This is an example use case:

<div class="max-w-[610px]">
    <div class="mt-12 mb-12">
        <p class="mb-8">With RepoZoid, storing your own code is as easy as pie. Just add a new entry, paste your
            code in - and you're off to the races.</p>
        <p>It's as simple as 1, 2, 3 - with sharing options and more coming in the future!</p>
    </div>

    <div class="flex flex-row mb-3">
        <div class="grow">
            <input class="w-full text-[#9c9ea5] py-3 px-4 rounded-md" placeholder="Enter your email" type="email"
                name="emailinput">
        </div>

        <div class="pl-2">
            <button class="px-4 h-full rounded-md bg-[#6E6BFF] text-white">Sign Up to the Beta</button>
        </div>
    </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'm not that familiar with Tailwind, but I'll give you a solution in Pure HTML/CSS.

.parent {
  padding: 10px;
  background: yellowgreen;      
  display: flex;
  /* Add `flex-direction: column;` if you want each child to be in one-row */
  width: fit-content;
}

.child {
  width: 100px;
  height: 50px;
}

.child:nth-child(1) {
  background: red;
}

.child:nth-child(2) {
  background: blue;
}
<div class="parent">
  <div class="child"></div>
  <div class="child"></div>
</div>

If you don't want to use fit-content, you can just use display: inline-block; and remove the width from your parent as follows:

.parent {
  padding: 10px;
  background: yellowgreen;
  display: inline-block;
}

.child {
  display: inline-block; /* Make it `display: block;` if you want each child to be in one-row */
  width: 100px;
  height: 50px;
}

.child:nth-child(1) {
  background: red;
}

.child:nth-child(2) {
  background: blue;
}
<div class="parent">
  <div class="child"></div>
  <div class="child"></div>
</div>

Additionally, I would quote a comment by @voneiden in a similar question;

A block element will claim the horizontal space that the parent has to offer whereas an inline-block will take the horizontal space it needs to display the content (unless overridden). If the inline-block is bigger than the parent, it will overflow. You can make a block element to evaluate content width by setting width: fit-content however that is not IE compatible.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!