I have an <input> and an <input type="image"> displayed as table-cell.
I cannot figure out why the image is on a new line in WebKit-powered browsers.
This is my HTML:
<div id="search">
<div id="search_input_wrapper">
<input type="text" name="Search" id="search_input" />
<input type="image" name="Submit" id="search_submit" alt="Search" />
</div>
</div>
And this is my CSS:
div#search {
display:table;
width:100%;
table-layout:fixed;
}
div#search_input_wrapper {
display:table-row;
}
input {
display:table-cell;
margin:0;
padding:0;
border:0;
}
And here's a jsFiddle
This is an interesting problem that only pertains to -webkit browsers.
If you take a look at this (example), you will clearly see the problem. An input element with the property display:table-cell should normally appear on the same line, as inline elements do. You will notice that this is true if type="submit". However, if type="image", then the input elements act as block level elements, appearing on a new line.
The root of the problem lies with the property -webkit-appearance. If you were to apply -webkit-appearance:none to both input elements, you will notice they now both act the same! (example)
The default property of an input element with type="submit" is -webkit-appearance:push-button therefore we can solve the problem by applying the same property to the type="image" elements, as they normally have the property -webkit-appearance:none by default.
Problem solved, (example).
input[type="image"] {
-webkit-appearance:push-button;
}
Here is an updated example, fixing your initial problem.
I also added a src to input[type="image"], as that is the purpose of type="image".
Again, all these pertains to -webkit browsers, if you are using IE, FF or Opera, none of these example will mean anything to you, as they don't demonstrate the issue.
Related
Is it possible to style the default HTML5 input type="number" to look something like this:
Or do I have to use additional elements for the 'arrows'? Couldn't find the CSS selectors for them.
JsFiddle
HTML:
<input class="qnt amount" name="qnt" min="1" max="100" type="number" value="1">
CSS:
input{
display:block;
margin-top:12px;
text-align:center;
width:125px;
height:30px;
outline:1px solid black;
border:none;
}
You can't. Form fields are drawn by the underliyng chrome (meaning browser/OS combination). They don't have CSS selectors.
If you like to have your style. you have to make some new element in front of the original input (or hide the input and put that new element in place). This element will work in some way with JavaScript and always updates the value of the input field.
I have a simple HTML form with only two elements -- a text box and a submit button -- that need to be horizontally aligned.
The button has a background image, and I would like to set its value="".
In Safari and Firefox, the alignment is maintained if I set the line-height on the elements.
In Chrome, however, this is not enough. I have to set the value=" " (note the space), or give it another text value. Otherwise, the elements shift.
This is the HTML and css
<form>
<input type="text" id="email" class="textBox" />
<input type="submit" id="submitSubscribe" class="submitButton" value="" />
</form>
.submitButton{
width:30px;
line-height:30px;
background:url('');
}
.textBox{
line-height:30px;
}
#email{
width:146px;
}
Here is my jsfiddle:
http://jsfiddle.net/EmCQJ/5/
Does anybody know why Chrome calculates the alignment differently with the text in the value attribute than when the value is blank? Leaving that space in the value feels like a hack solution to me, but I've tried all the obvious css fixes and still can't get it working. Any input is greatly appreciated. Thanks!
This should do it: http://jsfiddle.net/EmCQJ/38/
The key here was
vertical-align: text-top;
It seems the input-text and input-image elements have different baselines (the default setting for vertical-align) but the same text-top line.
You should manually set the margin, padding, and border of the input-text element because different browsers have different defaults. When doing this, remember height is the size of the element less the margin, padding, and border so if you want a total height of 30px make sure to subtract 1px from the top and 1px from the bottom giving you a CSS height of 28px.
I only have this problem in chrome. How remove the border around the image? please see the fiddle in chrome.
<form>
<input type="image" class="searchbox_submit search_btn" value="">
</form>
form input[type=text]:focus, form input[type=password]:focus, textarea:focus {
outline: none;
}
.search_btn {
background: url("http://static.ak.fbcdn.net/rsrc.php/v1/yu/r/yo348KDuskF.png") no-repeat scroll 0px -200px transparent;
height: 25px;
width: 30px;
outline: none;
border: none;
outline-width: 0;
-webkit-appearance: none;
}
Demo: http://jsfiddle.net/TXYg6/
You're using <input type="image" />, so a src attribute is expected. You haven't specified one, so Chrome shows a grey border, in the same way it does for an img with no src attribute.
If you want to stick to using <input type="image" /> and using a CSS sprite, you're going to have to specify something as the src, such as a 1x1 transparent "blank.gif".
http://jsfiddle.net/thirtydot/TXYg6/14/
However, that just seems horrible. Instead, I recommend switching to <input type="submit" />, which solves the problem.
replace it like that with submit type
<input type="submit" class="searchbox_submit search_btn" value="">
correct your css height and width
Give it a blank image as a src using a data: URI. Since you're only concerned with Chrome, there's no problem:
<input type="image" class="searchbox_submit search_btn" value="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAA1JREFUGFdj+P//PwMACPwC/ohfBuAAAAAASUVORK5CYII=">
http://jsfiddle.net/TXYg6/23/
Chrome gives a border/outline thingo to any image without a src, you could set the input type to 'submit' and this will go away.
Alternatively, use an with a src and trigger the submit from this, but you may as well just use a type="submit"
unwanted chrome borders
Do you really need that att type="image"? Because that's the thing causing the problem...
Semantically I'd say use a button since you don't actually have an associated input value, and as such it's not an input:
<button type="submit" class="searchbox_submit search_btn"></button>
From the docs:
Buttons created with the BUTTON element function just like buttons
created with the INPUT element, but they offer richer rendering
possibilities: the BUTTON element may have content. For example, a
BUTTON element that contains an image functions like and may resemble
an INPUT element whose type is set to "image", but the BUTTON element
type allows content.
Cheers
I see plenty of IE 7 workarounds for other CSS float problems, but I have yet to find one for this issue: when an element has both clear and float properties, the clearing doesn't work correctly.
This jsFiddle illustrates the problem. I'm trying to solve a very basic problem. I have a form with label/form item pairs. The labels should be on the left, and the form item should be to the right of the label. The next label should display on the next line. With this simple HTML:
<fieldset>
<label>Label 1:</label>
<input type="text" />
<label>Label 2:</label>
<input type="text" />
</fieldset>
This CSS should be sufficient:
label {
width: 200px;
text-align: right;
clear: both;
float: left;
}
input {
float: left;
}
However, what's happening instead is that although the second label clears the float and is rendered on the next line, the adjacent input is still shown on the first line.
Is there any workaround for this problem beyond adding more markup?
If you enclose the groups in a seperate div, the problem is solved. Of course you don't even need the clear then at all.
http://jsfiddle.net/Qh87k/1/
For part of a site I'm working on, I am constructing a price list... Since it is to be interactive, I am using checkbox type inputs and labels to make this; you check which services you want and the webpage gives you the total cost of these services. Easy enough.
My problem is a stylistic one; I am using a span with the float property set to right to distinguish between the price and the service description(the price gets right aligned within a div, the description gets left aligned next to the check box). The entire label is positioned with relative positioning. When I set the hover pseudo class to change the color of the label, the color change doesn't seem to work properly on chrome. Below is a small code sample that replicates the issue...
<html>
<head>
<style type="text/css">
div#leftcolumn
{
width:500px;
}
span.right
{
float:right;
}
input, label
{
position:relative;
left:50px;
}
label:hover
{
color:#FF0000;
}
</style>
</head>
<body>
<div id="leftcolumn">
<input id="option1" type="checkbox" /><label for="option1">This is a label... span class="right">and this is the same label</span></label><br/>
<input id="option2" type="checkbox" /><label for="option2">A new label!<span class="right">Y U NO COLOR RIGHT</span></label>
</div>
</body>
If you try this example on Chrome, I believe you should notice very odd hover behavior... However, this seems to work fine in Firefox and Internet explorer. Is this a bug with chrome? Is this poor coding on my part? My actual page validates.... I would appreciate it if someone who understands this problem would explain what is going on. I know I can make a work-around by moving the relative positioning into a div and placing all my inputs and labels in that div instead of positioning the labels and inputs directly, but I feel as though this SHOULD work....
As always, thank you for your time.
Your problem is not with label position:relative;
It seems your problem with float:right
I recommend you to replace span.right with this style
span.right
{
padding-left:100px;
}
another way to solve this issue is to add clear:right; to label:hover style
label:hover
{
color:#FF0000; clear:right;
}
Change the following:
span.right
{
position:relative;
left:150px;
}
I believe this is the effect you are looking for.