Search code examples
cssalignment

Align a dynamically created image in the right side of a div


I am trying to create a shopping list. The list is dynamically created using Javascript (jQueryUI). I want the thrash cans next to be on the right side (where this blue dots that I draw are). I tried to do it using left or style="right:350px" and float:right in tag but it didn't work.

enter image description here

Here is my code where it's row is generated:

var row=$('<div class"productsclass" id='+selectedproducts[i]+' style="width:400px">
<label style="font-size:20px">'+selectedproducts[i]+'</label><input type="text" 
name="Quantity" value="1" id='+thesi+'><img class=delete 
src="http://b.dryicons.com/images/icon_sets/handy_part_2_icons/png/128x128/recycle_bin.png"
 height="22" width="22" style="right:350px"></div>'); 
   rowID++;

   $("#productstable").append(row);

Here is the html:

<div id="maindiv" class="maindiv">
<input id="autocomplete_text_field">
<button id="add_product_button">Add product</button>
<form action="#" id="productstable" name="productstable">
<p></p>
</form>
</div>
</body>

and here is the CSS:

#body{
    background-color: #6E0D25
}

#maindiv {
    position:absolute;
    top: 50%;
    left: 50%;
    width:30em;
    height:18em;
    margin-top: -9em; /*set to a negative number 1/2 of your height*/
    margin-left: -15em; /*set to a negative number 1/2 of your width*/
    /*border: 1px solid #ccc;*/
    background-color: #6E0D25;
}

#productstable
{
    background-color:#F1EBE4;
    border-radius:10px;
    width:400px;
}

#product
{
    width:380px;
}
#autocomplete_text_field
{
    width:200px;
    height:40px;
    border-radius:10px;

}

#add_product_button
{
    width:200px;
    height:50px;
    border-radius:10px;
}

How can I do it? (Sorry if it is a very useless question, It's almost the first time I use CSS)

Solved after user2313440's answer:

enter image description here


Solution

  • Change img class=delete to img class="delete" then add float:right; to it in CSS.