Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i Display div Elements in one row

Hi everyone i want o display 3 elements in a row. I have tried the following code but it is not displaying them correctly.

    <div id="mainDiv" style="background-color:#f77f00; width:90%; margin-right:5%; margin-left:5%; margin-bottom:1%; margin-top:1%;" >
        <div id="left" onclick="Deletefav(this)"  style="display: inline; width:20%; float:left; ">'+
            '<img style="display: inline;" src="" />
        </div>'+

        <div id="center" onclick=""  style=" width:30%;  display: inline;text-align: center; margin:10%;">
            <p style="display: inline;"><font color="#fff" face="verdana" size="4">testing</font></p>
        </div>

        <div id="right" onclick="Callfav(this)"  style="display: inline; width:20%; float:right;">
            <img style="display: inline;" src="" /> 
        </div>
    </div>

It is displaying like this

Above code is displaying  this, i don't know why text is according to images

I want to create it like the sample imageSample

like image 389
Nomiluks Avatar asked Jan 11 '23 13:01

Nomiluks


2 Answers

Give display property inline-block for inner divs:

  display:inline-block;

Update:

you need to set the height for div that has jo will fix it as other to div have images in them:

<div
  id="${id}"
  style="
    background-color: #f77f00;
    width: 90%;
    margin-right: 5%;
    margin-left: 5%;
    margin-bottom: 1%;
    margin-top: 1%;
  "
>
  <div
    id="${_id}"
    onclick="Deletefav(this)"
    style="background-color: #f77f00; float: left; width: 20%; display: inline-block"
  >
    <img style="" src="${del_image}" /> <font color="#fff" face="verdana" size="1">delete</font>
  </div>

  <div
    id="${_id}"
    onclick=""
    style="background-color: #f77f00; float: left; width: 50%; display: inline-block; height: 25px"
  >
    <font color="#fff" face="verdana" size="4">${name}</font>
  </div>

  <div
    id="${_id}"
    onclick="Callfav(this)"
    style="background-color: #f77f00; float: left; width: 20%; display: inline-block"
  >
    <img style="" src="${call_image}" /><font color="#fff" face="verdana" size="1">call</font>
  </div>
</div>
like image 123
Milind Anantwar Avatar answered Jan 18 '23 15:01

Milind Anantwar


Add display: inline-block; to the child divs.

Set the height of the child divs:

  1. Possibility: Set the height for all the child divs: height: 20px /* or in %, em, etc */;
  2. Possibility: Set the height for the child divs: height: inherit; which gives the height from the parent div to the children divs

From W3Schools:

The inherit keyword specifies that a property should inherit its value from its parent element.

The inherit keyword can be used for any CSS property, and on any HTML element.

like image 24
toesslab Avatar answered Jan 18 '23 14:01

toesslab