Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display div next to label without breaking line

Tags:

html

css

I would like to drow a label and input text next to it.
the input text must be inside a div - later I would like to add element to the div.
I am using float in order to display the div next to the label/

here is me html:

<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 transitional//EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" >
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title></title>
</head>
<body>
        label: <div style="float:left;"><input type="text" /></div>
</body>
</html>

Ihe problem is that I get the div before the text.

http://jsfiddle.net/2wNbR/

How can I fix it?

UPDATE
I actually want to use an autocomplete plugin I've wrote instead of the input text. The autocomplete uses a div. I don't want to create a "prerequisite" to the label so solution like add <span style="float:right"></span> around the label are not good.

UPDATE2
I thought it is not necessary but I see it is importent.
Here is the full example: http://jsfiddle.net/2wNbR/16/

.Autocomplete {
    direction: ltr;
}

.Autocomplete, .Autocomplete .Arrow, .Autocomplete .CodeField,
.Autocomplete .SmartField, .Autocomplete .Selector {
    float:left;
}

.Autocomplete .Arrow {
    background-image:url(drop.gif);
    background-position:top right;
    height:17px;
    width:17px;
    cursor:pointer;
}

.Autocomplete .OptionsListHolder {
    height:0px;
    width:0px;
}

.Autocomplete .OptionsList
{
    position:relative;
    z-index:999;
    top:0px;
    right:0px;
    border: 1px solid #888888;
    font-weight: normal;
    font-size: 12px;
    font-family: Arial (Hebrew);
}

.Autocomplete .CodeField
{
    width:40px;
    border: 1px solid #888888;
    height:13px;
}

.Autocomplete .SmartField
{
    width:auto;
    border: 1px solid #888888;
    height:13px;
    font-weight: normal;
    font-size: 12px;
    font-family: Arial (Hebrew);
}

    Customer:
    <div class="Autocomplete">
        <input type="text" class="CodeField" />
        <div class="Selector">
            <input type="text" class="SmartField" />
            <div class="Arrow"></div>
            <div class="OptionsListHolder">
                <select class="OptionsList" size="8">
                    <option>opt 1</option>
                    <option>opt 2</option>
                    <option>opt 3</option>
                    <option>opt 4</option>
                    <option>opt 5 - long item text</option>
                </select>
            </div>
        </div>        
    </div>
    <br>
    text to check if the OptionsList is override this text
like image 820
Naor Avatar asked May 21 '11 11:05

Naor


Video Answer


2 Answers

<div style="display:inline-block;"><input type="text" /></div>

And you also might want to check the <label> html element.

like image 69
Arjan Avatar answered Nov 16 '22 01:11

Arjan


Just put a <span> around the label and float that too, remember to clear it.

<span style="float: left;">label: </span><div style="float:left;"><input type="text" /></div>
like image 44
Orbling Avatar answered Nov 16 '22 01:11

Orbling