I have a buch of multiple select boxes and I wanted to line them up in a line across the page. I thought I could do this with the help of divs, but for some reason I am running into trouble. Each select is being stretched across the entire width of the page even though I specified in the css that I didn't want that. Why is this happening?
Also, I am giving each select a title by just putting text on top of it. Is there a better way to make a title?
HTML
<div class='bold'>
<div id="parameters">
<div class="section">Program<br> <select multiple="multiple" name="program">
<option value="SGS">SGS</option>
</select>
</div>
<div class="section">School <br><select multiple="multiple" name="school">
<option value="FLH">FLH</option>
<option value="MID">MID</option>
<option value="SUN">SUN</option>
<option value="MNC">MNC</option>
</select>
</div>
<div class="section">Term <br><select multiple="multiple" name="term">
<option value="Fall 2011">Fall 2011</option>
<option value="Late Fall 2011">Late Fall 2011</option>
</select>
</div>
<div class="section">Extension<br> <select multiple="multiple" name="ext">
<option>Something...</option>
</select>
</div>
</div>
</div>
CSS
#parameters{width:100%
height:150px;
border-style:solid;
border-width:2px;
border-color:grey;}
.section{width:50px;}
Divs are block elements so will stack on top of each other by default. If you want them to sit next to each other you will need to float them.
.section{
float: left;
}
JSFiddle
You can try:
.section {
width: 50px;
display: inline-block
}
This is an alternative to float to a degree. It may suit your needs better, but it's difficult to say. display: inline-block comes with rendering drawbacks, as does float of course.
I prefer it sometimes - A lot of people jump at float like it's the only choice, but it can be a real pain too.
JSFiddle sample using display rather than float
As you can see, it preserves your border without using a clearfix, whereas float breaks the border.
edit: If you choose to use float, a good method of making the border wrap around the contained elements is to add overflow: auto to #parameters, as shown in the fiddle below:
Float fiddle with clearfix
I changed your html code a bit in order to use labels in the "tittle" of each select tag.
You can view here: http://jsfiddle.net/SmRzL/4/
In regards to how to align, your elements you need to float each section:
.section{
float: left;
padding: 10px;
}
In regards, to adding a title to each section personally I would do something along the lines of this:
<span class="title">Term </span>
.title {
display:block;
font: bold 1em "Arial Narrow", "Franklin Gothic Medium", Arial;
}
See this fiddle for reference: http://jsfiddle.net/8rQXD/
Related
I use select element with fixed width. However, when I have option element nested in select, which has quite long text, then, when this option is being selected, it does not get full background-width (I want the background to be 100%) and also the text is hidden.
Here is the example with the last option being hidden.
.x {
width: 200px;
overflow-x: auto;
}
<select class="x" size="4">
<option class="y" selected>xyz</option>
<option class="y" selected>xyz</option>
<option class="y" selected>xyz</option>
<option class="y" selected>xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz</option>
</select>
You can see the full width using a single css property . Please add a class to solve the issue :
.y{
width: fit-content;
}
Using this style, you could see that the background color gets filled to the full width.
I want to change the arrow position of a select element to the left side because now it's covering the string, as this is RTL writing system.
I did a lot of things by CSS and HTML5 but it's still not working very well.
.spec {
direction: "rtl";
}
<label for="">التخصص</label><br />
<select dir="rtl" name="" class="spec">
<option dir="rtl" value="nursing"> تمريض </option>
<option dir="rtl" value="lab">مختبر</option>
<option dir="rtl" value="pharm">صيدلة</option>
</select>
You don't have to move it if you don't want. Just add
select{
padding-left: 15px; /*exact width of default arrow down*/
box-sizing: border-box; /*optional if you also want to play with width property*/
}
Also please add the browser where you encounter this issue.. in Chrome, Firefox and IE (all last versions works good without any extra CSS)
I've got an issue that I'd love to solve by using CSS without resorting to statically sizing my labels (but perhaps it isn't possible).
I have two labels per line, one for displaying a "title" and the other for displaying the associated "value". Here's how I'd like it to look:
This is similar to Align labels in form next to input but I'm wanting the second element per line left-aligned instead of the first one to be right-aligned. I tried modifying the accepted answer from that question and set the width of the "title" label, but that has no effect on my output. As I mentioned above, I'd rather not hard-code a width anyways, but I was hoping to get something working before trying to find a good, long-term solution that can account for larger "title" values.
Here's my current CSS (the classes should be self-explanatory):
.propertyTitle {
text-transform: uppercase;
width: 300px;/*Why doesn't this have any effect?*/
}
.propertyValue {
text-align: left;
}
And my current HTML:
<div>
<div>
<label class="propertyTitle">Hello:</label>
<label class="propertyValue">World</label>
</div>
<div>
<label class="propertyTitle">Goodbye:</label>
<label class="propertyValue">To All of the People in the World</label>
</div>
<div>
<label class="propertyTitle">I Want:</label>
<label class="propertyValue">These labels to line up</label>
</div>
</div>
The HTML can be modified as well, if that'd make it easier. To conform with best practices, I'd rather not use tables to make this work.
Here's a jsFiddle showing what I have now, what am I missing? Ideally this solution would work for IE8+ and Firefox, so unfortunately HTML5 and CSS3 elements are discouraged.
EDIT
To reiterate after the first two answers came in (that both solve my issue), is there a way to do this without hard-coding a width for my "title" labels?
grouping your divs and labels like so:
<div>
<div class="titleWrap">
<label class="propertyTitle">Hello:</label>
<label class="propertyTitle">Goodbye:</label>
<label class="propertyTitle">I Want:</label>
</div>
<div class="valueWrap">
<label class="propertyValue">World</label>
<label class="propertyValue">To All of the People in the World</label>
<label class="propertyValue">These labels to line up</label>
</div>
</div>
with the following CSS:
.propertyTitle {
display:block;
text-transform: uppercase;
width: auto;
}
.titleWrap{
display:inline-block;
}
.propertyValue {
display:block;
width:auto;
}
.valueWrap {
display:inline-block;
}
should give you the desired result without having to specify the widths
Check out this jsFiddle
try using display:inline-block on your labels
.propertyTitle {
text-transform: uppercase;
width: 300px;/*Why doesn't this have any effect?*/
display: inline-block;
}
by default label is an inline element. that's why width property doesn't apply to label.
to apply the width you have to convert the label into a block level element by using display:block.
I hope it clarify the answer.
so you have to use this CSS property in your code.
.propertyTitle {
text-transform: uppercase;
display:inline-block; /*this will make the label a block level element*/
width: 300px;/*Why doesn't this have any effect?*/
}
More modern version is display: inline-flex;
I'm trying to align a section of text boxes but allowing labels in between them. Unfortunately they are being pushed aside. I'm sure it might be a css field type I'm unaware of that will handle this but maybe someone could help.
<div id="boxalign2">
<p>
<label>Contact Info</label><br>
<label>Email:</label> <input type="text"/>
<label>Office #:</label> <input type="text"/>
<label>Other:</label> <input type="text"/>
<label>Preferred method of contact</label>
<select id = "myList">
<option value = "1">Email</option>
<option value = "2">Phone</option>
</select>
</p>
css
#boxalign2 p label{
display: inline-block;
float: left;
clear: left;
width: 100px;
text-align: right;
}
If the above doesn't show my problem, here is the whole:http://jsfiddle.net/HLLVt/
Hi you don't need the float property in your #boxalign2 p label, also you need to manage the width of the labels and the container depends of what you want.
Chek this fiddle http://jsfiddle.net/HLLVt/4/
Remove the float and clear styles and the <p> tags around each label/input pair and they will all line up on one line. See http://jsfiddle.net/HLLVt/7/
How do I get the contents of my DIV to all stay on one line?
I've seen other posts, but I can figure out what I'm doing wrong?
here is a link to the page with an issue:
http://www.heatx.org/productcart/pc/viewCategories.asp?idCategory=2
Given your link start by adding float: left; to #pcIconBarRight img and #pcIconBar a. This should address your question.
EDIT:
Then change this:
And this:
EDIT2:
To display two divs in one row you could do this:
<div style="float: left; width: 200px;">
<div style="float: left; clear: none;">Total: </div>
<div style="float: left; clear: none;">159 USD</div>
</div>
Note: the width: 200px; you should set the width big enough for the inner div's to fit, otherwise it will break the second div to the next line.
I believe the issue is due to the images inside the div. Set display:inline to those images.
Please add this into your bottom of css file
table{
margin: 0 auto;
}
to align your site in center
your menu is not appeared !
A little bit late for answering OP's question. This will be useful for other people having the same problem.
So to get all the elements to appear on a single line the easiest way is:
Set white-space: nowrap;overflow-x: auto; on the parent element.
Set display: inline-block on all child elements.
Result:
Fiddle
<div style="width:100%;white-space:nowrap;overflow-x:auto;border: 1px solid red; border-radius: 10px;padding: 3px;">
<label style="display: inline-block">Some label </label>
<select style="display: inline-block">
<option value="0">aaaaa</option>
<option value="1">bbbbbb</option>
<option value="2">ccccccccc</option>
</select>
<label style="display: inline-block">Another label: </label>
<input type="text" style="display: inline-block;width:200px;" />
<span style="display: inline-block">NOTE: some other text</span>
</div>