So I've come across an issue with my input box going out of bounds and I have no idea how to fix it. My select box and input box have the exact same CSS code. I've tried using max-width and vertical-align but both didn't work. Also tried using display: inline-block.
The difference between the 2 are exactly 4px even though both are set to 80% width
HTML
<form class="container_filterSelection">
<label>Product Category</label>
<select class="categorySelect">
<option value="0"></option>
<option value="1">Drills</option>
<option value="2">More Drills</option>
<option value="3">Give me them drills</option>
</select><br>
<label>Address</label>
<input type="text" class="locationSelect">
<button class="submit">Submit</button>
</form>
</html>
CSS
form {
width: 75%;
margin: auto;
background: white;
}
/* Category Dropdown */
.categorySelect {
width: 80%;
margin: 16px 10%;
padding: 16px 0;
}
/* Location Input */
.locationSelect {
width: 80%;
margin: 0 10% 16px 10%;
padding: 16px 0;
}
Try like this:
form {
width: 75%;
margin: auto;
background: white;
}
/* Category Dropdown */
.categorySelect {
width: 80%;
margin: 16px 10% 16px 10%;
padding: 16px 0;
}
/* Location Input */
.locationSelect {
width: 80%;
margin: 0 10% 16px 10%;
padding: 16px 0;
box-sizing: border-box;
}
<form class="container_filterSelection">
<label>Product Category</label>
<select class="categorySelect">
<option value="0"></option>
<option value="1">Drills</option>
<option value="2">More Drills</option>
<option value="3">Give me them drills</option>
</select><br>
<label>Address</label>
<input type="text" class="locationSelect">
<button class="submit">Submit</button>
</form>
Adding box-sizing: border-box; to .locationSelect appears to fix it. The browser's user agent stylesheet appears to be adding this property to select elements but not to input, so to make them look the same, you need to correct for that.
Related
For the code below, I have two problems:
The background image cereal.jpeg was working, now for some reason, it's disappeared and I can't figure why. Because it used to work, I know the file name and location are correct.
My controls refuse to remain sticky!
div.container {
border-style: solid;
border-width: thin;
border-color: grey;
box-shadow: 10px 15px 8px black;
height: 1500px;
width: 700px;
}
div.container::before {
background-image: url("cereal.jpeg");
background-repeat: repeat;
opacity: 0.05;
}
div.controls {
float: left;
width: 140px;
border: 1px solid lightgrey;
position: -webkit-sticky; // Safari
position: sticky;
top: 0;
}
div.thePlots {
float: left;
border: 1px solid lightgrey;
width: 400px;
height: 1400px;
}
<div id=container class=container>
<div class=controls id=controls>
<label id="brand">Brand:</label>
<br>
<select size=7 id="brandOptions" multiple>
<option value=0 selected>All</option>
<option value=1>Kellog</option>
<option value=2>Post</option>
<option value=3>Quaker</option>
<option value=4>General Mills</option>
<option value=5>Tree House</option>
<option value=6>CPW</option>
</select>
<br><br><br>
<label id="barsLabel">Error Bars:</label>
<input id=barsPresent type=checkbox value="Error Bars" checked>
<br><br><br>
<label id="label">Elasticity<br>Means:</label>
<br>
<select id="plotY">
<option value="efm" selected="selected">efm</option>
<option value="enm">enm</option>
</select>
<br><br><br>
</div>
<div class=thePlots id=thePlots>
The Plots<br>
<div class="tooltip" id="tooltip"></div>
<div id="plotshare" class="plotshare"></div>
<div id="plotprice" class="plotprice"></div>
<div id="plotsugar" class="plotsugar"></div>
<div id="plotmushy" class="plotmushy"></div>
</div>
</div>
opacity is too low.
Remove float:left;
Your div.controls element is sticking just fine, but it's sticking to the top of your container element. If you put it outside out your container element you will see it stick to the top of the page as desired.
Also, you will need to remove the // safari from your css. The correct syntax for commenting in css is /* comment */
For the background issue, there is no content for your background to display behind. You will need to add something to the before in order for the background to show.
Check this working fiddle which solves both problems
: https://jsfiddle.net/c5vrhf7t/1/
I have a very simple form. The usual: a label and an input. The goal is to create a simple and responsive form. Everything works ok, except when the form contains a select input that is too large. For some reason, the select input does not shrink when the browser is resized. The other inputs (input, textarea) do shrink as the browser is resized.
I've tried using max-width: 100% on the select input, as other people suggested here, with no success.
I've created a jsfiddle that explains everything:
https://jsfiddle.net/ampr41po/3/
Here's the HTML
<div class="form-main">
<form action method>
<div class="controlUnit">
<div class="label">
<label for="firstname">First name</label>
</div>
<div class="control">
<input id="firstname" name="firstname" type="text" autofocus value="">
</div>
</div>
<div class="controlUnit">
<div class="label">
<label for="name">Name</label>
</div>
<div class="control">
<select id="name" name="name">
<option value="1">Name goes here</option>
<option value="2">Name</option>
<option value="3">This is a very very very very very long name. The name is mwpekng erter erter erter 4et erter 4ertye rwe 45y 43 rt rty rty rt rty rty </option>
<option value="4">Another name</option>
</select>
<span class="icon-item"></span>
<span class="icon-item"></span>
<span class="icon-item"></span>
</div>
</div>
</form>
</div>
CSS:
* {
box-sizing: border-box;
}
.form-main {
background-color: red;
max-width: 500px;
margin: 0 auto;
padding: 20px 15px;
}
.controlUnit {
display: flex;
}
.controlUnit .label {
flex: 0 0 100px;
text-align: right;
padding-right: 10px;
}
.controlUnit .control {
flex: 1 1 auto;
display: flex;
}
select {
max-width: 100%;
}
input#firstname {
width: 100%;
}
.icon-item {
width: 20px;
height: 20px;
background-color: yellow;
margin-left: 10px;
}
.icon-item ~ .icon-item {
margin-left: 5px;
}
Try using width: 100%, instead of max-width: 100% for select in your CSS code in order to have a responsive select element at all screen sizes.
Your approach to set max-width: 100% is wrong, because select elements are form control elements and thus have to follow some implicit rules. For instance, the width of a select element cannot be made narrower than its widest option when using max-width. That's made that way by the browser and there's nothing you can do to change it. So, unless you set the width explicitly, there is no other way to achieve a responsive design.
Check out the updated jsfiddle here.
I am creating an app the requires me to use 3 <select> tags that are stacked on top of each other. I need said tags to be flush with each other and also not leap over the background div's boundaries. I am making this work out fine in Google Chrome, but when I check it out Firefox, everything goes haywire. The select tags are nearly over the boundaries of the background div in unacceptable ways.
A visual example of my problem (Firefox on left Google Chrome on right)...
Here is my HTML...
<div id='wr-main-wrap'>
<div id='wr-wrapper'>
<div id='wr-opaq-background'></div>
<div id='input-wrapper'>
<div>
<h3 class='label-text'>work day length:</h3>
<select ng-model='ratioControl.workday'>
<option value='1'>1 Hour</option>
</select>
</div>
<div>
<h3 class='label-text'>break frequency:</h3>
<select ng-model='ratioControl.breakspan'>
<option value='.5'>30 Minutes</option>
</select>
</div>
<div>
<h3 class='label-text'>break lengths:</h3>
<select ng-model='ratioControl.breaklength'>
<option value='5'>5 Minutes</option>
</select>
</div>
</div>
</div>
</div>
Here is my CSS...
#wr-main-wrap{
width: 19em;
margin: 0 auto;
}
#wr-wrapper{
width: 17em;
margin: 3.5em auto;
}
#wr-opaq-background{
position: absolute;
width: 17em;
height: 7em;
background-color: white;
z-index: -1;
opacity: .7;
border-radius: .25em;
}
#input-wrapper{
margin: 5em 0;
padding: .85em 0 0 .6em;
}
.label-text{
font-family: 'Bebas Neue';
margin-bottom: .8em;
word-spacing: .1em;
display: inline-block;vertical-align: top;
width: 9em;
}
select{
width: 6em;
margin: 0 0 1.1em 0;
background-color: white;
border: black solid .1em;
}
I have check on stack overflow and the internets quite a bit, and have not found anything to answer my question. It is worth nothing that I am using Angular in case that may have something to do with it.
Try the following CSS:
#wr-wrapper{
position: relative;
}
The <input> tags themselves needed a height and width, otherwise, they would just adjust to the browser's default settings. This is completely unpredictable. I used % as a unit of measurement.
I want to create an error box for a form like the one below.
I already themed the input box and am using jQuery validation to display errors. However I can't get that error box right. I think I'll need to put that together with three tags, but I don't know what tags to use (jQuery validation uses a label tag to display the error).
My current code for the error is:
<label for="email">
<span>Email:</span>
<input type="text" id="email" name="email" class="error">
<label for="email" class="error" style="">Az e-mail címet kötelező megadni</label>
</label>
I must make this IE7 compatible.
I made the following changes:
<div class="dataline">
<div class="label">Label:</div>
<div class="field"><input type="text" id="name" name="name" /></div>
<div class="arrow"></div>
<label class="error">Error text</label>
<div class="ender"></div>
</div>
I set the arrowhead as an image for the class arrow so now it looks perfect. Basicly I used 4 left floated block elements (label, input, arrowhead and bubble body). Now I only have two problems: the arrowhead is displayed even when there's no error. How can I hide it when the label is not after it? My other problem is that the container div is 800px wide and if the error text is long, it wraps around to the next line. How can I avoid it?
My css is:
div.dataline {
margin: 10px 0 0 0;
white-space: nowrap;
width: 3000px;
owerflow: visible;
height: 60px;
}
div.field {
float: left;
}
div.label {
float: left;
width: 120px;
margin: 20px 0 0 0;
}
div.arrow {
background-image: url('gfx/redarrow.png');
margin: 7px 0 0 10px;
background-repeat: no-repeat;
width: 20px;
height: 45px;
float: left;
}
div.ender {
background-image: url('gfx/bubbleend.png');
margin: 7px 0 0 0px;
background-repeat: no-repeat;
width: 3px;
height: 45px;
float: left;
}
label.error {
height: 27px;
background-image: url('gfx/bubblemiddle.png');
float: left;
padding: 9px;
margin: 7px 0 0 0;
}
the following fiddle is a good start for your implementation:
http://jsbin.com/aReQUgay/1/edit
#email.error
{
border-color: red;
}
#email.error + label
{
background-color: red;
}
Responsible form is created using code below.
If window is resized, it resizes itself automatically, captions and input elements stay aligned.
It contains fixed values 210px, 75px, 100px, 120 px is css below.
Is it reasonable and if yes, how to remove/replace those fixed values with something other
like percents or em's ?
input, select elements and jquery-ui autocomplete with dropdown button are used.
<form class='ui-widget-content form-document'>
<div class='form-field'>
<label class='form-label' for='nimi'>Customer name</label>
<span class='form-fullwidth'>
<input class='ui-widget-content ui-corner-all form-autocomplete' name='nimi' value='Karu Org AS' ></input>
<button type='button' class='form-combobutton' tabindex=-1 ></button>
</span>
</div>
<div class='form-field'>
<label class='form-label' for='Number'>Number</label>
<input class='ui-widget-content ui-corner-all form-fullwidth' name='Number' />
</div>
<div class='form-field'>
<label class='form-label' for='payterm'>Pay term</label>
<span id='span_Maksetin1_tingimus' class='form-fullwidth'>
<select class='ui-widget-content ui-corner-all form-fullwidth' name='payterm'>
<option value='' selected='selected'></option>
<option value='0'>0 days</option>
</select>
</span>
</div>
... lot of similar form-field divs
</form>
css:
.form-document
{
padding: 0.5%;
}
.form-field
{
display: inline-block;
margin: 2px;
width: 210px; /* label width + input field width */
}
.form-label
{
padding-left: 5px;
padding-right: 5px;
font-family: Arial, Helvetica, sans-serif;
font-size: smaller;
display: inline-block;
text-align: right;
width: 75px; /* determine by max caption width */
}
.form-fullwidth
{
width: 120px; /* 210-5-75 */
}
.form-autocomplete
{
width: 100px; /* 210-5-75-combobutton width*/
}
.form-combobutton
{
height: 1.09em;
margin: 0 0 0px;
padding: 0;
margin-left: -6px;
vertical-align: middle;
width: 1em !important;
}
Looks ok to me though I personally use ems in most cases.
You could also consider using a preprocessor like LESS if you want to use variables to avoid repetition. You can get LESS or SASS via nuget and there are zillions of tutorials out there.