Although I'm using the same CSS for both <input> and <select>, text in <select> gets cut off, while the text in input is perfect. Why is this happening and how to fix it?
input,
select {
box-sizing: content-box;
width: 90%;
height: 23px;
padding: 10px;
font-family: TheBoldFont;
font-size: 27px;
color: #f26e7c;
border: 4px solid black;
border-radius: 12px;
}
<input type="text" value="xxxxxxx">
<select>
<option selected value="xxxxxxxxx">xxxxxxxx</option>
</select>
This is the result:
And this is what show up on hover in Developer tools of Google Chrome:
Firstly remove the height: 23px; declaration.
Notice the the text is not cut anymore, however the elements have a greater height than what was needed.
To fix this, just change the padding to padding: 6px 10px;
FIDDLE
input,
select {
box-sizing: content-box;
width: 90%;
padding: 6px 10px;
font-family: TheBoldFont;
font-size: 27px;
color: #f26e7c;
border: 4px solid black;
border-radius: 12px;
}
<input type="text" value="xxxxxxx">
<select>
<option selected value="xxxxxxxxx">xxxxxxxx</option>
</select>
Increase the line-height of the select by a few pixels.
This worked for me.
Changed this:
select {
line-height: 15px;
}
To:
select {
line-height: 17px !important;
}
It happens because of the padding. Consider only using padding left and right, combined with min-height.
You could increase the height of the select item:
select{
height: 40px;
}
Related
input[type="number"] field does not showing the placeholder text in latest firefox for certain font family like font-family: 'Open Sans';. The current version is Firefox Quantum 57.0.2 (64-bit)
Still don't know some font family have no such issue
Please check on the demo link https://codepen.io/anon/pen/zpqzEB
body {
padding: 2rem;
}
input {
display: block;
box-sizing: border-box;
width: 100%;
height: 40px;
padding: 0 10px;
line-height: 40px;
background: #fafafa;
border: 1px solid tomato;
padding: .5rem 1rem;
font-family: 'Open Sans';
background-clip: content-box;
background-color: deepskyblue;
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<input type="text" placeholder="Text field" />
<hr>
<input type="number" placeholder="Number field" />
It's your border-box property.
I'm not sure why it's happening on CodePen because it looks fine on JSBin and here on StackOverflow in the snippet you posted. Maybe it's CodePen not working great with Quantum.
Anyway, here's what's happening:
The border-box property will make it so the padding and border are included in total width and height of the element (w3schools.com).
Your input height is set to 40px. That 40px has to include the border, padding-top, padding-bottom, and the height of the element itself. Your line-height is also set to 40px. Your padding styles (you have two rules set, so it picks up the second one) is padding: .5rem 1rem;.
There isn't enough room for the input text in these 40 allocated pixels with.
Issue: 40px line height + top padding + bottom padding > 40px
As for a fix, I'm assuming you want to keep your padding and have your inputs the same size. You may need to make your font size smaller or make your inputs larger. 40px isn't enough for the padding and a 40px line height. Or you can remove that border-box property.
It kinda looks to me that the difference between this property on Chrome and on Firefox is that Chrome is ignoring the line-height. In this screenshot on Chrome, the height of the input is 22px, even though your line-height is 22px.
The root cause of the issue is that font-size is in excess of the number input controls.
Your example can be fixed preciesely by using:
padding: 0.46rem 1rem;
EXPLAINED
When padding is applied to a number type input the padding is applied to the boundaries of the box in the normal way however in some browsers cropping occurs relative to the amount of padding applied.
The cropping effect is calculated from the inside boundaries of the input arrow controls.
The cropping only affects placeholders because they are behind the input layer and become hidden when the interior boundaries of the input field are moved to cover it.
https://codepen.io/anon/pen/qpZPKd
There are various ways to avoid this however my recommendation is to avoid padding on input elements and to use alternate methods to create the desired effect.
Be an illusionist
Personally I don't see any reason to use vertical padding inside input fields. Line-height does a better job.
If you can't make the browsers do what you want make the user think the browser is doing what you want!
body {
padding: 2rem;
}
.Wrap{
box-sizing: border-box;
height: 40px;
border: 1px solid tomato;
padding: .5rem 1rem;
}
.Wrap input {
width: 100%;
height: 100%;
line-height: 40px;
border: none;
font-family: 'Open Sans';
background-color: deepskyblue;
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<div class="Wrap"><input type="text" placeholder="Text field" /></div>
<hr>
<div class="Wrap"><input type="number" placeholder="Number field" /></div>
Codepen example
https://codepen.io/anon/pen/QaNOdo
For some reason, when I change to height of your input field to anything above 40px it seems to work. Try this:
input {
display: block;
box-sizing: border-box;
width: 100%;
height: 41px;
padding: 0 10px;
line-height: 40px;
background: #fafafa;
border: 1px solid tomato;
padding: .5rem 1rem;
font-family: 'Open Sans';
background-clip:content-box;
background-color: deepskyblue;
}
I can't see why this fixes it though.
EDIT
You use two times PADDING in your css input declaration...
Just remove the first one : padding: 0 10px;
And keep : padding: .5rem 1rem;
body{
padding: 2rem;
}
input {
display: block;
box-sizing: border-box;
width: 100%;
height: 40px;
line-height: 40px;
background: #fafafa;
border: 1px solid tomato;
padding: .5rem 1rem;
font-family: 'Open Sans';
background-clip:content-box;
background-color: deepskyblue;
}
input[type="number"] {
// line-height: 1.5;
}
<input type="text" placeholder="Text field" />
<hr>
<input type="number" placeholder="Number field" />
I am running a site inside of an application viewer. This viewer will render the website in IE8 compatibility mode which I have no control over and can't change.
I have an input with top/bottom padding of 6px and left/right padding of 12px, but for some weird reason the bottom padding is ignored and the padding is incorrect.
Here is a screenshot of what I'm seeing:
Here is the CSS I'm using to style the input field:
input[type="text"] {
line-height: 1.42857143;
vertical-align: middle;
font-size: 14px;
font-weight: normal;
padding: 6px 12px 6px 12px;
*padding: 6px 12px 6px 12px;
}
I have Googled around for a while now and can't seem to be able to find a solution to my problem. Many tips I found suggest to use various line-height adjustments, while some suggest to use *padding: 6px 12px 6px 12px;. None of these tips work and the issue still exists.
How can I force the input to have equal top and bottom padding in IE8?
Note: I CANNOT use the http-equiv meta tag as it will cause other problems with the viewer.
You cannot :(
you may style a regular tag instead :
span {
float: left;
border: inset gray 2px;
background: white;
line-height: 2em;
height: 2em;
}
span input {
border: none;
}
.submit,
.submit input {
background-color: #337AB7;
border: solid #337AB7 2px;
width: 3em;
color: white;
text-align: center;
}
p {
display: inline-block;
box-shadow: 0 0 3px white;
}
body {
background: tomato;
}
<p>
<span>
<input type="text" value="(800) 123-456789" />
</span>
<span class="submit">
<input type="submit" value="Dial"/><!-- unless this a link , styles to be applied here & span can be skipped -->
</span>
</p>
Ive used the CSS :after selector to create an arrow for my links. This works fine but now I want to do the same thing to form inputs.
If I use the same class on the submit button then the :after is ignored, im assuming because the element cant contain other other elements.
If I apply the class to a div containing the submit button then it looks fine, but the arrow and padding outside of the actual submit button isnt clickable.
Is there a solution to this?
http://jsfiddle.net/jn7Vj/5/
.button-style {
background: -moz-linear-gradient(top, #02AD85, #019975);
background: -webkit-linear-gradient(top, #02AD85, #019975);
background: linear-gradient(top, #02AD85, #019975);
padding: 0.7em;
border-radius: 0.5em;
border-bottom: 4px solid #003E30;
box-shadow: 0 2px 0px #252D42;
font-size: 15px; //findme
margin-top: 15px;
display: inline-block;
margin-top: 10px; //findme
border-top: none;
border-right: none;
border-left: none;
color: white;
font-size: 12px;
}
.button-style:after {
content: '';
display: inline-block;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0.4em 0 0.4em 0.7em;
border-color: transparent transparent transparent #FFF;
margin-left: 0.75em;
}
.button-style input {
background: none;
border: none;
color: white;
font-size: 12px;
margin: 0;
padding: 0;
}
Here is a link
<form class="webform-client-form" enctype="multipart/form-data" action="/cchetwood/4/contact" method="post" id="webform-client-form-4" accept-charset="UTF-8"><div><div class="form-item webform-component webform-component-textfield" id="webform-component-full-name">
<input type="text" id="edit-submitted-preferred-times-to-contact-optional" name="submitted[preferred_times_to_contact_optional]" value="" size="60" maxlength="128" class="form-text">
<input type="submit" class="button-style" value="Submit">
<div class="button-style">
<input type="submit" value="Submit">
</div>
</form>
The CSS after pseudo element doesn't work on input fields (https://stackoverflow.com/questions/9840768/css-after-input-does-not-seem-to-work). Unfortunately your only solution here is to add the triangle as a background image on the input field or surround the field with something like a div or a span and add the after selector to that element.
As for your button, I would suggest changing it from an input element to a button, you can then apply the after selector to that.
EDIT
After reading your question again, I'm not sure if you want to add the triangle to your text input but here is a jsFiddle with the style added only to the buttons: http://jsfiddle.net/jn7Vj/9/
add for .button-style position:relative; padding: 0;
add for .button-style input padding: 0.7em 2em 0.7em 1em; --> you can change this sizes, main idea is move padding from .button-style to .button-style input
add next css-rules for .button-style:after
position:absolute;
top:50%;
right:10%;
margin: -0.2em 0 0 0;
I'm using Firefox and cannot seem to get rid of the outline around a selected option.
My code
HTML
<div class="drop-select">
<select name="date" id="date">
<option value="01">01</option>
<option value="02">02</option>
</select>
</div>
Pretty straightforward.
CSS
.drop-select {
display: block;
border: 1px solid #000;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font: 12px/14px arial, helvetica, verdana, sans-serif;
width: 80px;
height:25px;
-webkit-appearance: none;
overflow: hidden;
background: url('http://www.adcentre.com.au/media/1326/bg-down-arrow.gif')no-repeat right #fff;
float: left;
margin-right: 5px;
margin-top: 6px;
margin-bottom: 6px;
}
.drop-select select {
background: transparent;
width: 125px;
height: 25px;
border: none;
padding: 5px 0 0 5px;
color: #000;
outline:0;
}
Even with me setting the outline to 0 and border to none, it still displays it?
Example in JSFiddle:
http://bit.ly/SpQGC4
The problem here is that the dropdown's parent, div.drop-select, has a black border. Remove that, and the black border will disappear.
Don't confuse outline with border; in many browsers, outline defines the glow that, for example, a text input field gets on focus (as I write this answer in Safari, the text box has a blue outline with a slight blur). Border refers to something much like an outline, but generally used on things other than form elements, and generally present in all element states, rather than just focus.
It's also worth mentioning that, in some browsers, both on Windows and Mac OS (not sure about Linux distros), the outline of form elements can be styled.
How to decrease offset between text and top border in button. I'm trying to set line-height, but it's not working in Firefox: Fiddle
CSS:
input[type="button"]
{
border-color: #D2D2D3 #79797A #4D4D4E #C0C0C1;
border-style: solid;
border-width: 1px;
height: 16px;
line-height: 7px;
padding: 1px;
width: 16px;
background: #d8dadb;
}
HTML:
<input type="button" value="+" />
Your setting a hard width and height. Take those out or set them to auto and your button will respond to padding adjustments.
input[type="button"]
{
border-color: #D2D2D3 #79797A #4D4D4E #C0C0C1;
border-style: solid;
border-width: 1px;
line-height: 7px;
padding: 1px;
background: #d8dadb;
}
Firefox bug (feature)
http://www.cssnewbie.com/input-button-line-height-bug/
This could help a little:
button::-moz-focus-inner {border: 0; padding: 0;}