Please don't suggest I stop using <input type="submit"> I need to support non javascript-enabled users.
I have a submit button, and on :hover I apply a border to it. However I have noticed that in Firefox 15 and IE7 the border gets applied to the inside of the element. This appears to be because I have set a fixed width and a height to the element and behaves normally once I remove them. However due to browser inconsistencies I need the width and height to ensure the submit button is the same size in all browsers.
Does anyone know how to prevent the border from being drawn inside the element?
Relevant CSS:
#searchform .submit {
vertical-align: middle;
float: right;
height: 31px;
width: 31px;
position: relative;
left: -4px;
margin-right: -4px;
background-image: url(library/images/search-icon.png);
background-position: center center;
background-repeat: no-repeat;
background-color: #ffffff;
border: none;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-topright: 5px;
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
}
#searchform .submit:hover {
margin: -2px -6px 0px 0px;
border: 2px solid #000;
}
Relevant HTML:
<input type="submit" value="" class="submit btn" />
Wonder if there is a box-sizing property being applied to this input. box-sizing: border-box would cause border & padding to occur within width and height. I wonder if you're using a CSS template that uses the * { box-sizing: border-box; } technique. Try
#searchform .submit { box-sizing: content-box; }
try to remove the margin when hover to the button?
#searchform .submit:hover {
border: 2px solid #000;
}
Why don't you use this:
border: 2px solid #3393B5;
Or:
border: 2px solid #fff;
Instead of:
border: 2px solid #000;
Related
This is what my form/submit button currently looks like:
I would like, of course, for the "Go" button to be better integrated into the rest of the form so that it appears as a seamless extension. This would mean that the right side would have a border-radius, while the left side would remain straight. In addition, the top and bottom of the button would have to line up perfectly with the top and bottom of the form.
Any help with this? I've been fiddling around, and this is what I've come up with so far in terms of code:
input {
display: inline;
}
input.button {
margin-left: -9px;
border: none;
background-color:#FA8801;
border-radius-right: 2px !important;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family: Open Sans !important;
font-weight: 100 !important;
font-size:17px;
padding:7px 5px;
text-decoration:none !important;
font-family: inherit;
}
/*This is the styling for the form, not the button from here and on... */
input[type=email] {
padding: 5px !important;
border: 2px solid #FFFFFF;
-webkit-border-radius: 2px !important;
border-radius: 5px !important;
font-family: inherit;
font-weight: 100 !important;
}
input[type=email]:focus {
border: 2px solid #FA8801;
outline: none;
}
input[type=email]:focus::-webkit-input-placeholder {
color:transparent;
}
And the JSFiddle: http://jsfiddle.net/wfhLnsez/
Use border-top-right-radius and border-bottom-right-radius to target individual corners.
I would suggest putting a line-height on your input box which gives you the height you'll need for your "Go" submit button. Then you'll need to pad the left and right of these elements only seeing as you already have the height.
input.button {
border-top-right-radius: 5px; /* to match border-radius on input box */
border-bottom-right-radius: 5px;
height: 30px; /* to match height of input box */
padding: 0 5px;
}
input[type=email] {
line-height: 30px; /* height of input box */
padding: 0 5px; /* nothing on top and bottom, 5px on left and right */
}
I've noticed you have !important on conflicting properties on your input[type=email].
-webkit-border-radius: 2px !important;
border-radius: 5px !important;
For starters, do your utmost to avoid using !important as well-written CSS shouldn't need them. You have 2 different values for the same property 2px and 5px. They should both be the same. Also, while you're at it, you should add the third prefix for these types of styles, so it should be:
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
I think this is closer to what you want:
jsfiddle
Some highlights:
the border radius, you need to use all the browser's CSS for this:
-webkit-border-top-right-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-moz-border-radius-topright: 5px;
-moz-border-radius-bottomright: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
I also change the padding to get the height of the button closer to made that of the input:
padding-left:4px;
padding-right:4px;
padding-top: 1px;
padding-bottom: 6px;
Finally, I moved the button over one pixel to cover the rest of the input's border radius:
margin-left: -10px;
Hopefully this helps!
this is my first post here. I don't know how to explain my problem because I don't really know what is causing my CSS code to break. It would be easier to show you in a photo.
So I have a div tag and input and div child elements inslide. One of the div is static 32px x 32px and I am calculating its width with calc(100% - 32px), but when scaling some pixels aren't filled with the input.
Here's a photo of the problem: http://imgur.com/TkRFLde
This occurs when the zoom is not divisible by 100. For example it breaks on 110%, 150% and 175%. But it is right when the zoom is 100%, 200%, 300%...
Heres my code:
<div class="search">
<input type="text" value="Search" class="search-text" />
<div class="search-icon" ></div>
</div>
CSS:
.search {
height: 32px;
width: 250px;
}
.search-text{
float:left;
width: calc(100% - 55px) !important;
display: inline-block !important;
border-top-right-radius: 0 !important;
border-bottom-right-radius: 0 !important;
margin: 0;width: 196px;
}
.search-icon{
display: inline-block !important;
background-color: #ACB6BE;
height: 30px;
width: 31px;
float:right;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
cursor: pointer;
border: 1px solid #acb6be;
}
input[type=text] {
border-radius: 5px;
border: 1px solid #acb6be;
min-width: 180px;
color: #acb6be;
padding: 0 10px;
height: 30px;
background-color: #fff;
font-weight: 600;
}
Or jsfiddle: http://jsfiddle.net/39VDR/1/
The problem happens because when you zoom, your values will not be integer anymore. This means that rounding will take place and the outer container (.search) will be 1px larger than you would expect.
You can remove the float:right on the .search-icon and it will work ok.
You can see it here:
http://jsfiddle.net/39VDR/4/
.search-icon{
display: inline-block;
background-color: #ACB6BE;
height: 30px;
width: 31px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
cursor: pointer;
border: 1px solid #acb6be;
font-size:12px;
vertical-align: top;
}
Still, as mentioned, you can remove the !important if you just add more specificity to your selectors.
I'm experimenting with css and I'm trying to add a dynamic pseudo-class in my selector. Here is the HTML-markup snippet.
<div id="child">
<input type="text" id="text"/>
</div>
and it's corresponding css-style
input[type="text"]{
width: 150px;
height: 25px;
}
input[type="text"]:hover, input[type="text"]:focus{
border: 1px solid grey;
}
#child{
padding: 5px;
border: 20px solid;
background: aqua;
height: 50px;
margin: 10px;
}
Here is the JSFIDDLE example. So when the mouse hovers over the text element the size of the text element is reduced as follows:
Would anyone know why this reduction in size is occurring?
Now in your code what is happening is that you have set the input fields width and height to 150px and 25px respectively.Now when you add 1px border to it it will reduce the inside(white) portion of the input field to maintain the width and height as mentioned(150px and 25px). To solve this you can add 2px to both width and height on hover.Fiddle :
http://jsfiddle.net/z78BN/6
input[type="text"]:hover, input[type="text"]:focus{
width: 152px;
height: 27px;
border: 1px solid grey;
}
That is because of two things outline and pseudo 3d default border of input.
Add
input[type="text"]{
border: 1px solid aqua;
}
input[type="text"]:focus{
outline:none;
}
i'm trying to customize a text input with css, i want the text inside it to have a margin of 10px to the left so i use:
#text{
text-indent: 10px;
border: 1px solid #333;
outline: none;
padding: 0;
margin: 0;
width: 168px;
height: 20px;
border-radius: 4px;
}
It works in all browsers except for IE10 which seems to ignore the text-indent property, how can i fix it?
<input type="text" id="text" />
you can use padding-left, it works on all browsers:
#text {
padding: 0 0 0 10px;
border: 1px solid #333;
outline: none;
margin: 0;
width: 158px; //decrease width with the same padding vale so that the width would stay the same
height: 20px;
border-radius: 4px;
}
If you want to use a special rule for IE, adding display: inline-block and a line-height, along with the text-indent rule, will fix this as well. This is an old trick for both IE7-9 as well.
input.special {
text-indent: 150px;
display:inline-block;
line-height: 18px;
}
Does the trick.
This is good if you are using liquid or responsive widths and you don't want to have to adjust your input's width on account of the padding.
I am using Fx 9 and my following code breaks in it while it works in all other browsers including IE9.
EDIT
Please note that I just want to know about this particular code breaking not interested in how to actually get work done because I am learning CSS not doing work for any client.
HTML
<form id="sform" action="index.htm">
<input class="sfield" type="text" value="Search..." />
<input class="sbutton" type="button" value="Go" />
</form>
CSS
#sform {
display:inline-block;
border: solid 1px #d2d2d2;
padding: 10px 10px;
border-radius: 2em;
box-shadow: 0 1px 0px rgba(0,0,0,.1);
background: #f1f1f1;
letter-spacing: -4px;
}
:not(#sform){
letter-spacing: -4px;
}
.sfield {
padding: 6px 35px 6px 8px;
border: solid 1px #bcbbbb;
width: 202px;
border-radius: 2em;
box-shadow: inset 0 1px 2px rgba(0,0,0,.2);
}
.sbutton {
color: #fff;
background: #5f5f5f;
margin-left: -52px;
border: solid 1px #494949;
height: 27px;
width: 27px;
border-radius: 2em;
}
http://jsfiddle.net/UfK6K/8/
The behavior of your testcase will depend on the precise font size the user has set and the font that gets used. It will also depend on how the UA decides to handle negative letter spacing; the spec allows it to be capped or ignored altogether. From http://www.w3.org/TR/CSS21/text.html#spacing-props :
This value indicates inter-character space in addition to the default space between characters. Values may be negative, but there may be implementation-specific limits.
Add position: absolute; to .sbutton.
Is that the desired outcome?
Why use letter-spacing there anyway? I don't see the logic behind this decision.
I think you may have to rework that code, try with something like this, it's cleaner and it should work in all browsers, IE8+ just fine. Adjust to your needs:
html
<form id="sform" action="index.htm">
<input class="sfield" type="text" value="Search..." />
<input class="sbutton" type="button" value="Go" />
</form>
css
#sform, .sfield, .sbutton {
border-radius: 100px;
padding: 10px;
}
#sform {
position: relative;
display: inline-block;
background: #999;
border-radius: 100px;
}
.sfield {
border: 1px solid #999;
width: 300px;
}
.sbutton {
position: absolute;
right: 10px;
border: 0;
background: black;
color: white;
}
explanation:
Letter spacing increases or decreases the space between characters in a text and it seems you're using it to add padding.
Then, an absolute position element is positioned relative to the first parent element that has a position other than static.
Try removing all your letter-spacing and you'll see that the changes in the layout are minimal.
Take a look at my example and by logic you'll figure it out why it works.
example:
http://jsfiddle.net/elclanrs/7KGkJ/1/