display div next to label without breaking line - html

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

<div style="display:inline-block;"><input type="text" /></div>
And you also might want to check the <label> html element.

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>

label: <span><input type="text" /></span>
or
<div style="float:left">label:</div><div><input type="text" /></div>
will help but if you can say the purpose you will more likely get an appropriate answer

I'm guessing that the poster is actually using coldfusion and using <cfinput> rather than <input> -- if this is the case, here's the scenario:
You have a <cfinput> tag with an autosuggest= value and you want to put a text label to the left of the input field.
<cfinput with autosuggest uses ajax and automatically adds styled ajax divs to, including the cf.css which adds the float:left; style.
One way you can work around this is by surrounding your label and the cfinput in a table, with each in their own <td>'s..
so <table border=0><tr><td>label:</td><td><cfinput autosuggest="value1,value2,etc" name="inputname"></td></tr></table>
That should do it!

Related

How to style an element based on another element changes without JavaScript?

I have to style an input control based on the select box's class. If select box has a class "error", then I need a red border on the input control. How can I do that with SASS ? There is no common wrap, only one thing is that the wrap of the input control (.select-input-wrap) is adjecent to select box. Here is the DOM structure.
<select class="form-select error"></select>
<div class="select-input-wrap">
<input class="select-input" name="select-input" />
</div>
You need to style a sibling element, try the below code in your SASS file.
$red: #f00;
.error {
&.form-select {
+ .select-input-wrap {
> .select-input {
border: 1px solid $red;
}
}
}
}
In pure CSS (and so in SASS), you can target sibling elements using the + operator. For instance:
.form-select.error + .select-input-wrap input {
border: 3px solid red;
}
Related sandbox: http://www.cssdesk.com/r8Dh8
If your select and div elements share a parent, you can style based on that:
.parent .error + .select-input-wrap input {
border: 1px solid red;
}
<div class="parent">
<select id="some-sel" class="form-select error"> </select>
<div class="select-input-wrap">
<input class="select-input" name="select-input" />
</div>
<select id="another-sel" class="form-select"> </select>
<div class="select-input-wrap">
<input class="select-input" name="select-input" />
</div>
</div>
For the SASS version, just take out the extra punctuation!
This is a css solution. Hope you can convert to sass structure.
.error~.select-input-wrap input{
border: solid 1px red;
}
<select class="form-select error"></select>
<div class="select-input-wrap">
<input class="select-input" name="select-input" />
</div>

Why can't I use CSS to move button?

This is my code and I'm unable to style it using 'button {margin-top:10px}
<input type="text"></input><button type="button"><img src="searchlogo.png" id="search"></button>
It isn't aligning flush with the text input? Any tips?
To see how does margin working please see this demo
CSS
.b1{
background:orange;
color:white;
border:none;
}
.b2{
background:orange;
color:white;
border:none;
margin-top:100px;
}
HTML
<input type="text"></input><button class="b1">Button Title</button>
<br/>
<input type="text"></input><button class="b2">Button Title</button>
<br/>
<input type="text"></input><button class="b1">Button Title</button>
I suspect you have an overriding rule somewhere in your css somewhere that prevents your css code from doing what you intend to do.
You should specify the element that you want to implement the margin on instead of broadly calling on button for the margin-top: 10px; rule.
Try this:
On your HTML:
<button class="my-button"><img src="image.jpg" alt="image" /></button>
On your CSS:
button.my-button {
margin-top: 10px;
}
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" CssClass="button" />
<head runat="server">
<title></title>
<style type="text/css">
.button
{
margin-top: 20px;
}
</style>

CSS setting background white

I'm trying to set up the background white for #7 as seen here:
http://jsfiddle.net/eab6ytom/1/
I dont want a line going through my text where it says 7.Input Type "submit"/"reset"
Relevant code to this portion:
<div class="subHeader">
<h3>7.Input Type "submit"/"reset"</h3>
<div class="submit">
<div class="subBorder">
<div class="subBordColor">
<p> <input type="submit" value="Submit Information" />
<input type="reset" value=" Clear " />
</p>
</form>
</div>
</div>
</div>
</div>
h3{
position:absolute;
border-style: solid;
border-color: blue;
margin-left:-300px;
margin-top:200px;
font-size:12px;
background-color:white;
}
.subBordColor{
border-style:solid;
border-color:blue;
padding:10px;
}
.subBorder{
border-style:groove; border-width:10px;
border-top-color:#A0A0A0;
border-right-color:#A0A0A0 ;
border-bottom-color:#A0A0A0 ;
border-left-color:#A0A0A0 }
}
The background color works fine. The reason that the line goes through the box is that it's on top of it. The z order of elements is determined by the element order by default; the last element is on top.
You can add z-index: 1; to the h3 rule to place it on top of the other element.

CSS for displaying an indented ordered list with checkboxes before each list item

I'm not sure if this is possible, but I'm attempting to set up an ordered list with checkboxes in front of each list item, something like this:
I would like this to have a checkbox to the left of the item number and wrap to the first word in the sentence, not to the item number.
Same deal as item number 1, want a checkbox to the left of the item number and wrap to first word in sentence.
I've figured out the indenting stuff using this question, but haven't been able to get the checkboxes to show up on the same line as the <li>. Is there any way to do this?
Here's a jsFiddle I've been messing with.
http://jsfiddle.net/9v97V/2/
You can do something like this. You put the input inside the list item, then absolute position it so it appears before the list item.
Most relevant CSS:
li input
{
position: absolute;
margin-left: -40px;
margin-top: 5px;
}
I've made a new jsFiddle based on yours: http://jsfiddle.net/3VESY/1/
Basicly I've put the text in a span (could also be a div) and a float on the input. The span has a padding-left to create the indent.
Hope that's what you needed?
ol {
list-style-type:decimal;
margin-left:20px;
}
ol li span {
display:block;
padding-left:30px;
}
input
{
float:left;
}
edit updated fiddle: http://jsfiddle.net/3VESY/1/ to add numbers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
form{
border: 2px solid #f1f1f1;
text-align: left;
}
ol{
margin-left:40%;
font-weight:bold;
}
</style>
</head>
<body>
<div class="container">
<form action="/action.php">
<ol type="A" style="color: red" >
<li><p >CSE</p></li>
<ol type="i" style="margin-left:-13%; color: blue">
<li>
<input type="checkbox" id="cb1" name="op1">
<label for="cb1"> Artificial Intelligence</label>
</li><br>
<li>
<input type="checkbox" id="cb2" name="op2">
<label for="cb2">Machine Learning</label>
</li>
</ol><br>
<li><p>ECE</p></li>
<ol type="A" style="margin-left:-13%; color: blue">
<li>
<input type="checkbox" id="cb3" name="op3">
<label for="cb3">Embedded Systems</label>
</li><br>
<li>
<input type="checkbox" id="cb4" name="op4">
<label for="cb4">IOT</label>
</li><br>
</ol>
</ol>
</form>
</div>
</body>
</html>

Radio/checkbox alignment in HTML/CSS

What is the cleanest way to align properly radio buttons / checkboxes with text? The only reliable solution which I have been using so far is table based:
<table>
<tr>
<td><input type="radio" name="opt"></td>
<td>Option 1</td>
</tr>
<tr>
<td><input type="radio" name="opt"></td>
<td>Option 2</td>
</tr>
</table>
This may be frown upon by some. I’ve just spent some time (again) investigating a tableless solution but failed. I’ve tried various combinations of floats, absolute/relative positioning and similar approaches. Not only that they mostly relied silently on an estimated height of the radio buttons / checkboxes, but they also behaved differently in different browsers. Ideally, I would like to find a solution which does not assume anything about sizes or special browser quirks. I’m fine with using tables, but I wonder where there is another solution.
I think I have finally solved the problem. One commonly recommended solution is to use vertical-align: middle:
<input type="radio" style="vertical-align: middle"> Label
The problem, however, is that this still produces visible misalignments even though it should theoretically work. The CSS2 specification says that:
vertical-align: middle: Align the vertical midpoint of the box with the baseline of the parent box plus half the x-height of the parent.
So it should be in the perfect centre (the x-height is the height of the character x). However, the problem seems to be caused by the fact browsers commonly add some random uneven margins to radio buttons and checkboxes. One can check, for instance in Firefox using Firebug, that the default checkbox margin in Firefox is 3px 3px 0px 5px. I'm not sure where it comes from, but the other browsers seem to have similar margins as well. So to get a perfect alignment, one needs to get rid of these margins:
<input type="radio" style="vertical-align: middle; margin: 0px;"> Label
It is still interesting to note that in the table based solution the margins are somehow eaten and everything aligns nicely.
The following works in Firefox and Opera (sorry, I do not have access to other browsers at the moment):
<div class="form-field">
<input id="option1" type="radio" name="opt"/>
<label for="option1">Option 1</label>
</div>
The CSS:
.form-field * {
vertical-align: middle;
}
I found the best and easiest way to do it is this one because you don't need to add labels, divs or whatsoever.
input { vertical-align: middle; margin-top: -1px;}
I wouldn't use tables for this at all. CSS can easily do this.
I would do something like this:
<p class="clearfix">
<input id="option1" type="radio" name="opt" />
<label for="option1">Option 1</label>
</p>
p { margin: 0px 0px 10px 0px; }
input { float: left; width: 50px; }
label { margin: 0px 0px 0px 10px; float: left; }
Note: I have used the clearfix class from : http://www.positioniseverything.net/easyclearing.html
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {display: inline-block;}
/* Hides from IE-mac \*/
* html .clearfix {height: 1%;}
.clearfix {display: block;}
/* End hide from IE-mac */
This is a bit of a hack but this CSS seems to get it working very nicely in all browsers the same as using tables (apart from chrome)
input[type=radio] { vertical-align: middle; margin: 0; *margin-top: -2px; }
label { vertical-align: middle; }
#media screen and (-webkit-min-device-pixel-ratio:0) {
input[type=radio] { margin-top: -2px; }
}
Make sure you use labels with your radios for it to work. i.e.
<option> <label>My Radio</label>
If your label is long and goes on multiple rows setting the width and display:inline-block will help.
.form-field * {
vertical-align: middle;
}
.form-field input {
clear:left;
}
.form-field label {
width:200px;
display:inline-block;
}
<div class="form-field">
<input id="option1" type="radio" name="opt" value="1"/>
<label for="option1">Option 1 is very long and is likely to go on two lines.</label>
<input id="option2" type="radio" name="opt" value="2"/>
<label for="option2">Option 2 might fit into one line.</label>
</div>
I found the best fix for this was to give the input a height that matches the label. At least this fixed my problem with inconsistencies in Firefox and IE.
input { height: 18px; margin: 0; float: left; }
label { height: 18px; float: left; }
<li>
<input id="option1" type="radio" name="opt" />
<label for="option1">Option 1</label>
</li>
The following code should work :)
Regards,
<style type="text/css">
input[type=checkbox] {
margin-bottom: 4px;
vertical-align: middle;
}
label {
vertical-align: middle;
}
</style>
<input id="checkBox1" type="checkbox" /><label for="checkBox1">Show assets</label><br />
<input id="checkBox2" type="checkbox" /><label for="checkBox2">Show detectors</label><br />
This is a simple solution which solved the problem for me:
label
{
/* for firefox */
vertical-align:middle;
/*for internet explorer */
*bottom:3px;
*position:relative;
padding-bottom:7px;
}
There are several ways to implement it:
For ASP.NET Standard CheckBox:
.tdInputCheckBox
{
position:relative;
top:-2px;
}
<table>
<tr>
<td class="tdInputCheckBox">
<asp:CheckBox ID="chkMale" runat="server" Text="Male" />
<asp:CheckBox ID="chkFemale" runat="server" Text="Female" />
</td>
</tr>
</table>
For DevExpress CheckBox:
<dx:ASPxCheckBox ID="chkAccept" runat="server" Text="Yes" Layout="Flow"/>
<dx:ASPxCheckBox ID="chkAccept" runat="server" Text="No" Layout="Flow"/>
For RadioButtonList:
<asp:RadioButtonList ID="rdoAccept" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
For Required Field Validators:
<asp:TextBox ID="txtEmailId" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqEmailId" runat="server" ErrorMessage="Email id is required." Display="Dynamic" ControlToValidate="txtEmailId"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regexEmailId" runat="server" ErrorMessage="Invalid Email Id." ControlToValidate="txtEmailId" Text="*"></asp:RegularExpressionValidator>`
Below I will insert a checkbox dynamically. Style is included to align the checkbox and most important to make sure word wrap is straight. the most important thing here is display: table-cell; for the alignment
The visual basic code.
'the code to dynamically insert a checkbox
Dim tbl As Table = New Table()
Dim tc1 As TableCell = New TableCell()
tc1.CssClass = "tdCheckTablecell"
'get the data for this checkbox
Dim ds As DataSet
Dim Company As ina.VullenCheckbox
Company = New ina.VullenCheckbox
Company.IDVeldenperScherm = HETid
Company.IDLoginBedrijf = HttpContext.Current.Session("welkbedrijf")
ds = Company.GetsDataVullenCheckbox("K_GetS_VullenCheckboxMasterDDLOmschrijvingVC") 'ds6
'create the checkbox
Dim radio As CheckBoxList = New CheckBoxList
radio.DataSource = ds
radio.ID = HETid
radio.CssClass = "tdCheck"
radio.DataTextField = "OmschrijvingVC"
radio.DataValueField = "IDVullenCheckbox"
radio.Attributes.Add("onclick", "documentChanged();")
radio.DataBind()
'connect the checkbox
tc1.Controls.Add(radio)
tr.Cells.Add(tc1)
tbl.Rows.Add(tr)
'the style for the checkbox
input[type="checkbox"] {float: left; width: 5%; height:20px; border: 1px solid black; }
.tdCheck label { width: 90%;display: table-cell; align:right;}
.tdCheck {width:100%;}
and the HTML output
<head id="HEAD1">
<title>
name
</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR" /><meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE" />
</head>
<style type='text/css'>
input[type="checkbox"] {float: left; width: 20px; height:20px; }
.tdCheck label { width: 90%;display: table-cell; align:right;}
.tdCheck {width:100%;}
.tdLabel {width:100px;}
.tdCheckTableCell {width:400px;}
TABLE
{
vertical-align:top;
border:1;border-style:solid;margin:0;padding:0;border-spacing:0;
border-color:red;
}
TD
{
vertical-align:top; /*labels ed en de items in het datagrid*/
border: 1; border-style:solid;
border-color:green;
font-size:30px }
</style>
<body id="bodyInternet" >
<form name="Form2" method="post" action="main.aspx?B" id="Form2">
<table border="0">
<tr>
<td class="tdLabel">
<span id="ctl16_ID{A}" class="DynamicLabel">
TITLE
</span>
</td>
<td class="tdCheckTablecell">
<table id="ctl16_{A}" class="tdCheck" onclick="documentChanged();" border="0">
<tr>
<td>
<input id="ctl16_{A}_0" type="checkbox" name="ctl16${A}$0" />
<label for="ctl16_{A}_0">
this is just dummy text to show the text will warp this is just dummy text to show the text will warp this is just dummy text to show the text will warp this is just dummy text to show the text will warp this is just dummy text to show the text will warp this is just dummy text to show the text will warp
</label>
</td>
</tr>
<tr>
<td>
<input id="ctl16_{A}_1" type="checkbox" name="ctl16${A}$1" />
<label for="ctl16_{A}_1">
ITEM2
</label>
</td>
</tr>
<tr>
<td>
<input id="ctl16_{A}_2" type="checkbox" name="ctl16${A}$2" />
<label for="ctl16_{A}_2">
ITEM3
</label>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
#sfjedi
I've created a class and assigned the css values to it.
.radioA{
vertical-align: middle;
}
It is working and you can check it in the below link.
http://jsfiddle.net/gNVsC/
Hope it was useful.
input[type="radio"], input[type="checkbox"] {
vertical-align: middle;
margin-top: -1;
}