1

After I added div that defining backgound color of text, whole value of 'Ime' goes to new row. Why? Something like this:
Ime:
Stephen

This is code:

   <div class="rightmiddle">
<?php 
while ($row = mysql_fetch_array($query)){
    ?>
<div class="divmobilni">
<div class="floatright"><img src="images/nokia-lumia-720.jpg" height="66px" width="50px" /></div>
Ime:<div class="imepozadina"> <?php echo $row['Ime'];?></div>
Okrug: <?php echo $row['Okrug'];?>
<br />
Telefon: <?php echo $row['Telefon'];?>
</div>
<br />
<?php } ?>
</div>
</div>

Css:

imepozadina{
background-color:red;
width:auto;

}

Stefan
  • 1,283
  • 15
  • 33

2 Answers2

1

This is because <div> is displayed as a block element as default, which takes 100% of width without further styling.

You might add display: inline or display: inline-block in order to shrink the div to its content width.

Please refer here for more information on display in CSS.

Lee Han Kyeol
  • 2,371
  • 2
  • 29
  • 44
1

If you set width property to auto the browser will automatically calculate,and occupy all the available space. It is the default for div and P. to understand the difference between setting a div 100% width and auto look at this answer [difference between width auto and width 100 percent

Community
  • 1
  • 1
ambes
  • 5,272
  • 4
  • 26
  • 36