-1

I would like to know how to resize the size of a div according to the width of the text, avoiding this wasted space, leaving the div compressed. Example:

Default size

The div should receive a cut such as:

Desired size

Example code:

.linhaCodigo{
  background: #C0C0C0;
  position: relative;
}
<div class="conteudo2">
              <h3>Cap 2 - Title</h3>
              <p align="left"><h4 align="left"><b>Title 2:</b></h4>
                textexttexttexttexttexttexttexttexttexttexttexttext
              </p>
              <div class="linhaCodigo"> print("I like it!")<br>
                <b>Outup:</b><br>
                I like it!
              </div><br>
            </div>

2 Answers2

1

try this

.myclassDiv{
   display: inline-block;
 }
hoover_D
  • 620
  • 4
  • 9
0

Change your CSS to this:

.linhaCodigo{
  background: #C0C0C0;
  position: relative;
  display: inline-block;
}
Hamzaouiii
  • 438
  • 3
  • 14