2

How do I make all divs the same width as its narrowest sibling.

Eg: I have a:

<div class="wrapper">
  <div class="div1">Hello</div>
  <div class="div2">Hello this s some text</div>
</div>

Here I want to make the div2 element the same width as its narrowest sibling (div1) without changing the HTML part.

Just Mohit
  • 141
  • 1
  • 13

2 Answers2

2

If you want to apply the css style only to the elements that have "div" keyword in their classname like "div1","div23" or "super_div" and which are child of "wrapper" class then you can use this css selector.

.wrapper [class*="div"] {
  width="100%"
}

<div class="wrapper">
    <div class="div">Hello</div>
    <div class="div">Hello this s some text</div>
</div>
Shivam Arora
  • 354
  • 2
  • 8
1

Try using this CSS:

.div1 {
    width: 100%;
}
.div2 {
    width: 100%;
}
<div class="wrapper">
    <div class="div1">Hello</div>
    <div class="div2">Hello this s some text</div>
</div>
Just Mohit
  • 141
  • 1
  • 13