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/
Related
I have an input element that has a height that is 2px greater than expected.
Below is the css
.input {
font-size: 16px;
padding: 15px;
border: 1px solid black;
border-radius: 3px;
width: 400px;
}
<input class="input">
I would have expected the content height of the input to be 16px due to the font size. For some reason Chrome says my content box is 18px rather than 16px. I even tried to set line-height: 1 but did not work. Can someone explain this? I'd rather not hard code the height as a solution.
You can set box-sizing: content-box and set height: 16px
.input {
font-size: 16px;
padding: 15px;
border: 1px solid black;
border-radius: 3px;
width: 400px;
box-sizing: content-box;
height: 16px;
}
<input class="input">
It says this because of 1px border but to resolve this add box-sizing: border-box; to it.
It will surely solve your issue but if it doesn't let me know in the comments, I will try my best to help you.
I want to have an input textbox with following requirements.
With fixed size.
Only bottom dashed border with number of dashes equal to the size.
I tried:
<div>
input text: <input size="5" maxlength="5"/>
</div>
here is the fiddle that I tried.
is it possible to have number of dashes equalto the size attribute of the textbox?
If yes, How can I do it?
First of all it's not possible. Every browser renders dashed borders differently.
You could use a workaround. In the following example I have added a ul which simulates the number of characters which can be used
input{
border:none;
border: 0px dashed;
letter-spacing: 2px;
}
input:focus{
outline:0
}
div{
border: 2px solid #CCC;
padding: 50px;
}
ul {
position: relative;
top: -35px;
right: -30px;
height: 1px;
}
li {
display: inline;
margin: 0 2px;
list-style-type: none;
font-size: 8px;
}
<div>
input text: <input size="5" maxlength="5"/>
<ul><li>_</li><li>_</li><li>_</li><li>_</li><li>_</li></ul>
</div>
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.
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;
Evening,
HTML:
<input type="text" class="search" value="Search"><input type="button" class="searchimg" value="Search" />
CSS:
input.search {
font-size: 1em;
color: #383838;
margin: 7px 0 0 7px;
padding: 3px;
border: 1px solid #969696!important;
background: #FEFEFE!important;
height: 16px;
width: 250px;
}
input.searchimg {
text-indent: -99999px;
width: 24px;
height: 24px;
display: inline;
background: url(../images/search.jpg) 0 0 no-repeat;
border: 0px;
margin: 7px 0 0 0;
}
(search.jpg dimentions: 24x24px, 1px border is part of image, not CSS! http://img267.imageshack.us/img267/6779/searchr.png)
Top version shows how it's supposed to render, the bottom picture is showing how it is actually rendering, in all broswers. It is 2px higher than it's supposed to be. I'm not really sure why it's doing this.
Thanks.
Try removing the line margin: 7px 0 0 7px;
Try vertical-align:top on input.search { ... } this should work because your input is affected by (previous?) inline styles.
For the future: it's easier to operate on elements styled with display:inline-block and it's well supported in browsers (IE 7 needs an small hack, IE 6 should be dead already).