Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda