HTML <Select> width not equal to other controls - html

I have a Select field that I want to take up as much space as every other field in my form, and they go down vertically.
When I set the width of my controls to 70% all controls assume this width, except Select.
HTML
<div>
<ul class="flex-container">
<li class="flex-item">
<input type="date" id="dateField" />
</li>
<li class="flex-item">
<select type="text" id="areaField">
<option value=""> Choose</option>
<option value=" 1"> 1</option>
<option value=" 2"> 2</option>
<option value=" 3"> 3</option>
<option value=" 4"> 4</option>
</select>
</li>
</ul>
</div>
CSS:
#dateField, #areaField{
width: 70%;
}
.flex-container {
list-style: none;
}
You can see a JSFiddle Demo of what I mean here.
Does anyone know what to do about that :)?

You'll want to invoke the box-sizing property and set it to border-box.
There are some good discussions about this issue on a previous thread. The suggested answer of content-box doesn't work unless you have a border surrounding the input/select, so border-box will work better for you in this situation.
#dateField, #areaField{
width: 70%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.flex-container {
list-style: none;
}
<div>
<ul class="flex-container">
<li class="flex-item">
<input type="date" id="dateField" />
</li>
<li class="flex-item">
<select type="text" id="areaField">
<option value=""> Choose</option>
<option value=" 1">1</option>
<option value=" 2">2</option>
<option value=" 3">3</option>
<option value=" 4">4</option>
</select>
</li>
</ul>
</div>

Related

Make an element float to the right inside a div

On my product page, there are a number of attributes depending on how many were added to that specific product. It can be from 1 up to 4. The attributes share a common fieldset class name and this is where it gets tricky for me. Basically I'm trying to position 2 of the fieldsets side by side and the rest below them (also side by side). However, I also want them separated and stick to their respective sides within the container. I've managed to make parts of what I said above happen but I have an issue with making the right fieldsets stick to the right side completely. Here's an image description:
Here's the code so far:
https://jsfiddle.net/26za63sh/
HTML:
<div class="container">
<div class="product_attributes clearfix">
<div id="attributes">
<div class="clearfix"></div>
<fieldset class="attribute_fieldset">
<label class="attribute_label" for="group_2">Choose</label>
<div class="attribute_list">
<select name="group_2" id="group_2" class="form-control attribute_select no-print">
<option value="81" selected="selected" title="Option #1">Option #1</option>
<option value="150" title="Option #2">Option #2</option>
</select>
</div>
</fieldset>
<fieldset class="attribute_fieldset">
<label class="attribute_label" for="group_6">Choose</label>
<div class="attribute_list">
<select name="group_6" id="group_6" class="form-control attribute_select no-print">
<option value="31" selected="selected" title="Option #1">Option #1</option>
<option value="56" title="Option #2">Option #2</option>
</select>
</div>
</fieldset>
<fieldset class="attribute_fieldset">
<label class="attribute_label" for="group_5">Choose</label>
<div class="attribute_list">
<select name="group_5" id="group_5" class="form-control attribute_select no-print">
<option value="80" selected="selected" title="Option #1">Option #1</option>
<option value="151" title="Option #2">Option #2</option>
</select>
</div>
</fieldset>
</div>
</div>
</div>
CSS:
.container {
width: 400px;
height: 200px;
background-color: gray;
border: 1px solid #dddddd;
}
fieldset {
padding: 0;
margin: 0;
border: 0;
}
#attributes .attribute_list {
width: 90%;
}
#attributes fieldset {
float: left;
width: 50%;
padding-bottom: 5px;
}
#attributes fieldset:last-child {
float: left;
padding-bottom: 0px;
}
I understand that if I set .attribute_list's width to 100% it will accomplish what I'm trying to do but then the two fieldsets will have no space in the middle. If I instead set a fixed width instead of percentage, then I'll have issues in mobile/tablet view. Any suggestions?
Try this. If you want align items in line and float right.
.attribute-container{display:inline-block;}
.attribute_fieldset:nth-child(odd) .attribute-container{float:right;}
.container {
width: 400px;
height: 200px;
background-color: gray;
border: 1px solid #dddddd;
}
fieldset {
padding: 0;
margin: 0;
border: 0;
}
#attributes .attribute_list {
width: 90%;
}
#attributes fieldset {
float: left;
width: 50%;
padding-bottom: 5px;
}
#attributes fieldset:last-child {
float: left;
padding-bottom: 0px;
}
<div class="container">
<div class="product_attributes clearfix">
<div id="attributes">
<div class="clearfix"></div>
<fieldset class="attribute_fieldset">
<div class="attribute-container">
<label class="attribute_label" for="group_2">Choose 1</label>
<div class="attribute_list">
<select name="group_2" id="group_2" class="form-control attribute_select no-print">
<option value="81" selected="selected" title="Option #1">Option #1</option>
<option value="150" title="Option #2">Option #2</option>
</select>
</div>
</div>
</fieldset>
<fieldset class="attribute_fieldset">
<div class="attribute-container">
<label class="attribute_label" for="group_6">Choose 2</label>
<div class="attribute_list">
<select name="group_6" id="group_6" class="form-control attribute_select no-print">
<option value="31" selected="selected" title="Option #1">Option #1</option>
<option value="56" title="Option #2">Option #2</option>
</select>
</div>
</div>
</fieldset>
<fieldset class="attribute_fieldset">
<div class="attribute-container">
<label class="attribute_label" for="group_5">Choose 3</label>
<div class="attribute_list">
<select name="group_5" id="group_5" class="form-control attribute_select no-print">
<option value="80" selected="selected" title="Option #1">Option #1</option>
<option value="151" title="Option #2">Option #2</option>
</select>
</div>
</div>
</fieldset>
</div>
</div>
</div>
The problem is the elements in fieldset all float to left.
Add this to float the inner elements of odd fieldsets to right:
#attributes fieldset:nth-child(odd) * {
float: right;
}
JSFiddle: https://jsfiddle.net/er_han/Lprh9zqf/

Placing DIV in form, can't set minimum width and height

I have the following html snippet:
<form name="foo">
<fieldset>
<legend>Legend Here</legend>
<label for="the_date">Date: </label><input type="text" name="the_date" id="the_date">
<select class="show_when_needed" id="event_state">
<option value="-1" selected="selected">N/A</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</select>
<div class="foobar" style="display: inline; border: 1px black; min-width: 20px; min-height: 15px; background: blue;"></div>
<button type="button" name="go_next" id="go_next">Go!</button>
</fieldset>
<hr />
<button type="button" id="save_object">Save Object</button>
</form>
I am trying to have the div show inline, and set a minimum width (to force it to show on screen).
The HTML above is not achieving that goal. How do I correct it so that the div appears alongside the select option control?
[[Additional Info]]
I have tried this on the latest versions of FF and Chrome - both fail to display correctly.
You need to give the element a display: inline-block, you can't set width or height of an inline element because it behaves just like a <span> or a <strong> would, taking only the space it needs.
Take a look at this updated snippet with display: inline-block
change from display: inline; to display: block;.
<form name="foo">
<fieldset>
<legend>Legend Here</legend>
<label for="the_date">Date: </label><input type="text" name="the_date" id="the_date">
<select class="show_when_needed" id="event_state">
<option value="-1" selected="selected">N/A</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</select>
<div class="foobar" style="display: block; border: 1px black; min-width: 20px; min-height: 15px; background: blue;"></div>
<button type="button" name="go_next" id="go_next">Go!</button>
</fieldset>
<hr />
<button type="button" id="save_object">Save Object</button>
</form>

How do I make this search form appear correctly on IE6 - IE8?

I'm working on an app and part of the project requirements is that the entire site be compatible with IE6 - IE8. So far, the rest of the website looks good on older browsers except for this search form I created.
This is what it looks like on modern browsers, and is what it's supposed to look like in general: ,
...but this is what it looks like on IE6: .
Does anyone have some experience with trying to make table-less layouts work on older browsers, or has run into a similar issue in the past? Basically I have containers holding each label / input, and need them to display next to each other in three's per row, with the label and input next to each other ass seen on the first image.
Below is the code regarding these elements.
EDIT: I added a few more things to both the html and css for easier deployment on your own computers.
Thanks for any help you can provide!
HTML
<div class="mid">
<h2>Search and filter by:</h2>
<!-- 1st Row Starts -->
<form action="" method="post" id="main-search-form"> <!-- containing form for search -->
<div id="search-container" align="center">
<div class="search" align="center">
<form>
<label>Keywords</label>
<input type="text" name="keywords" value="" id="keywords" placeholder="enter search terms here...">
</form>
</div>
<div class="search" align="center">
<label>Category</label>
<select>
<option value="" disabled selected>Select Category</option>
<option value="">Category 1</option>
<option value="">Category 2</option>
<option value="">Category 3</option>
<option value="">Category 4</option>
<option value="">Category 5</option>
</select>
</div>
<div class="search" align="center">
<label>Service</label>
<select>
<option value="" disabled selected>Select Service</option>
<option value="food">Food and Nutrition Support</option>
<option value="shelter">Shelter and Care</option>
<option value="protection">Protection</option>
<option value="healthcare">Healthcare</option>
<option value="pyschosocial">Psychosocial Support Services</option>
<option value="education">Formal and informal education</option>
<option value="legal">Legal Services</option>
<option value="other">Other Services</option>
</select>
</div>
</div> <!-- //.search-container -->
<!-- // 1st Row -->
<!-- 2nd Row Starts -->
<div id="search-container" align="center">
<div class="search" align="center">
<label>Age</label>
<select>
<option value="" disabled selected>Select Age</option>
<option value="">Age 1-3</option>
<option value="">Age 4-10</option>
<option value="">Age 11-14</option>
<option value="">Age 15-18</option>
</select>
</div>
<div class="search" align="center">
<label>Gender</label>
<select>
<option value="" disabled selected>Select Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="search" align="center">
<label>Region</label>
<select>
<option value="" disabled selected>Select Region</option>
<option value="">Category 1</option>
<option value="">Category 2</option>
<option value="">Category 3</option>
<option value="">Category 4</option>
<option value="">Category 5</option>
</select>
</div>
</div><!-- //.search-container -->
<!-- // 2nd Row -->
<!-- 3rd Row Starts Here -->
<div class="search-container" align="center">
<div class="search" align="center">
<form class="checkbox">
<label>Day</label>
<input type="checkbox" name="monday" value="Monday">M
<input type="checkbox" name="tuesday" value="Tuesday">T
<input type="checkbox" name="wednesday" value="Wednesday">W
<input type="checkbox" name="thursday" value="Thursday">R
<input type="checkbox" name="friday" value="Friday">F
<input type="checkbox" name="saturday" value="Saturday" >Sa
<input type="checkbox" name="sunday" value="Tuesday">Su
</form>
</div>
</div>
</form>
</div>
CSS
.mid {background: #258db1; color: #fff; padding: 20px 0 30px 0;}
.mid h2 {color: #fff; text-align: center;}
.mid h2, .mid h3, .mid p, .footnote p {color:#fff;}
/* SEARCH */
#main-search-form {width: 100%;}
.search {min-width: 250px; display: inline; margin:0; position:relative;}
.search select {background: #fff; height: 40px; width: 150px; margin-bottom: 30px; margin-right: 30px; position:relative; display: inline;}
.search option, {padding: 10px; position:relative; display: inline;}
.search, .search label {display: inline;}
.search input#keywords {display: inline; position: relative; min-width: 250px; background: #fff; margin-right: 20px;}
.search .checkbox input {display: inline; position: relative; width: 15px!important; height: 15px!important; margin-left: 10px!important; margin-right: 2px!important;}
.search .checkbox label {display: inline; position: relative; margin-right: 10px;}
#media (max-width: 959px) {
.search {disply: block; clear:both;}
.search input, .search select, .search input#keywords {display:block; margin-bottom: 20px; margin-top: 8px; width: 60%!important; margin-left:30px;}
.search, .search label, .search input#keywords {display: block; clear:both;}
}
Remove align='center' attribute in #search

Hide text after div using css

Here is my Div:
<div id="show" class="dataTables_length">
Show
<select size="1" name="show_length">
<option value="10" selected="selected">10</option>
<option value="20">25</option>
<option value="30">50</option>
<option value="40">100</option>
</select>
entries
</div>
I want to hide this show and entries text how should I hide this using css? Not using javascript or jquery.
.someClass {
display: none;
}
Tried this? I am sure this would do it!
Where it would be this:
<span class="someClass">Show</span>
<!-- select statement here -->
<span class="someClass">Enteries</span>
I thought you wanted to hide whole of it!
Try this:
<div id="show" class="dataTables_length">
<span class="hidden">Show</span>
<select size="1" name="show_length">
<option value="10" selected="selected">10</option>
<option value="20">25</option>
<option value="30">50</option>
<option value="40">100</option>
</select>
<span class="hidden">entries</span>
</div>
With CSS:
span.hidden {
display: none;
}
Despite so many answers and comments, you don't seem to be ready to accept the fact that the text needs to be wrapped in span. And that too using only css!
So, you can do a faux hide like this: http://jsfiddle.net/abhitalks/R7Yt4/1/
CSS:
div#show {
background-color: #ccc;
color: #ccc;
}
div#show::selection {
color: #ccc;
}
div#show > select {
color: #fff;
}
You can warp a span around the items you want to hide, and the hide this.
For example
<span class="hide">Show</span>
and css:
.hide{display:none;}
Your full html will look like this:
<div id="show" class="dataTables_length">
<span class="hide">Show</span>
<select size="1" name="show_length">
<option value="10" selected="selected">10</option>
<option value="20">25</option>
<option value="30">50</option>
<option value="40">100</option>
</select>
<span class="hide">entries</span>
</div>
<div id="show" class="dataTables_length">
<span style="visibility:hidden">Show </span>
<select size="1" name="show_length">
<option value="10" selected="selected">10</option>
<option value="20">25</option>
<option value="30">50</option>
<option value="40">100</option>
</select>
<span style="visibility:hidden"> entries </span>
</div>

How can I align two divs horizontally? [duplicate]

This question already has answers here:
Align <div> elements side by side
(4 answers)
Closed 4 years ago.
I need to align two divs next to each other, so that each contains a title and a list of items, similar to:
<div>
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div>
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
It's remarkably easy to do with tables, but I don't want to use tables. How can I achieve this?
Float the divs in a parent container, and style it like so:
.aParent div {
float: left;
clear: none;
}
<div class="aParent">
<div>
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div>
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
</div>
Nowadays, we could use some flexbox to align those divs.
.container {
display: flex;
}
<div class="container">
<div>
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div>
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
</div>
<div>
<div style="float:left;width:45%;" >
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div style="float:right;width:45%;">
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div style="clear:both; font-size:1px;"></div>
</div>
Clear must be used so as to prevent the float bug (height warping of outer Div).
style="clear:both; font-size:1px;
You need to float the divs in required direction eg left or right.
Wrap them both in a container like so:
.container{
float:left;
width:100%;
}
.container div{
float:left;
}
<div class='container'>
<div>
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div>
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
</div>
Add a class to each of the divs:
.source, .destination {
float: left;
width: 48%;
margin: 0;
padding: 0;
}
.source {
margin-right: 4%;
}
<div class="source">
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div class="destination">
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
That's a generic percentages solution - using pixel-based widths is usually much more reliable. You'll probably want to change the various margin/padding sizes too.
You can also optionally wrap the HTML in a container div, and use this CSS:
.container {
overflow: hidden;
}
This will ensure subsequent content does not wrap around the floated elements.
float is obsolete, better use display: flex;:
example :
.parent-div{ display: flex; }
indicate the direction by flex-direction: row/column;.
go down if no space by flex-wrap: wrap/nowrap;
more properties here.
if you have two divs, you can use this to align the divs next to each other in the same row:
#keyword {
float:left;
margin-left:250px;
position:absolute;
}
#bar {
text-align:center;
}
<div id="keyword">
Keywords:
</div>
<div id="bar">
<input type = textbox name ="keywords" value="" onSubmit="search()" maxlength=40>
<input type = button name="go" Value="Go ahead and find" onClick="search()">
</div>
<html>
<head>
<style type="text/css">
#floatingDivs{float:left;}
</style>
</head>
<body>
<div id="floatingDivs">
<span>source list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
<div id="floatingDivs">
<span>destination list</span>
<select size="10">
<option />
<option />
<option />
</select>
</div>
</body>
</html>
For your purpose, I'd prefer using position instead of floating:
http://jsfiddle.net/aas7w0tw/1/
Use a parent with relative position:
position: relative;
And children in absolute position:
position: absolute;
In bonus, you can better drive the dimensions of your components.