I have a button on a form;
<button type="button" class="button" onclick="validate_form_newsletter_wide( form )"><img src="index_htm_files/btn_newsletter_wide.png" alt="Send"></button>
It styled using;
<style>
button::-moz-focus-inner,
input[type="button"]::-moz-focus-inner,
input[type="submit"]::-moz-focus-inner,
input[type="reset"]::-moz-focus-inner {
padding: 0 !important;
border: 0 none !important;
}
#form_newsletter_wide .button {
position:relative;
float: right;
cursor:pointer;
border: 0px;
padding: 0px;
margin: 0px;
margin-top: -1px;
z-index:100;
}
</style>
When clicked in Firefox nothing about the button changes, in Chrome I get a highlight border around the button which I can live with but in IE it's more of a pressed effect where the button almost seems to move down and right. Is there anyway to prevent this?
It's a browser behaviour, a simple solution is to use a link tag instead of button (since you're calling a javascript function).
<img src="myimg"/>
If you still want to use the , I've found that there are some characteristics on each browser (in a simple debug):
Chrome adds outline and padding
Firefox adds a whole lot of stuff with the standart button border
IE messes with the inner text position
So to fix them, you have to manipulate the pseudo selectors for the button behaviour. And for IE, a good solution is to envolve your text on a element, and make it relative positioned. Like so:
<button type="button" class="button"><span>Buttom or Image</span></button>
<style>
button,
button:focus,
button:active{
border:1px solid black;
background:none;
outline:none;
padding:0;
}
button span{
position: relative;
}
</style>
Pen
My problem is the following:
I have a contact form with multiple input fields. The input fields are on a normal page round about half of the div that they are in. Now when observing my webpage through an browser the problem occurs. The page itself can get smaller than the input fields.
What I would like is the following:
That it resizes to fit in the div instead of overlapping/overflowing outside of the div.
I've tried searching it here on SOF and on google but either I'm searching for the wrong thing or I just can't find it.
HTML:
<div id="contact-formulier">
<form method="post" action="contact.php">
<label>Naam*</label>
<input name="naam" placeholder="Graham Neal" required>
</form>
</div>
CSS:
input, textarea {
width:439px;
height:27px;
background:#efefef;
border:1px solid #dedede;
padding:10px;
margin-top:3px;
font-size:0.9em;
color:#3a3a3a;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
textarea {
height:213px;
}
input:focus, textarea:focus {
border:1px solid #97d6eb;
}
Set the form width to 100% then the input and textarea width to around 90%. I hope this is the result you are seeking for. Just like that:
form {
width: 100%;
float: left;
}
/* Style the text boxes */
input, textarea {
width:90%;
height:27px;
background:#efefef;
border:1px solid #dedede;
padding:10px;
...
}
With the width fixed as you put in the css, it's not going to happen.
You could use percentage to obtain this but they don't work perfectly every time in my experience, especially if you do something a little more complex than the simple exercise of your fiddle or if you embed the example into something else.
Best way is using jquery to force the width:
$(document).ready(function() {
$(window).resize(function() {
$('input').width( $('#contact-formulier').width() - 22);
});
});
See: http://jsfiddle.net/Lnnxsrwj/2/
I am trying to style radio buttons using this approach. Here you can find a DEMO of what I`m trying to accomplish:
http://jsfiddle.net/sbef2so3/2/
CSS:
/*works*/
input[type="radio"] {
display:none; /*doesn`t work here*/
visibility:hidden;
}
/*doesn't work*/
input[type="radio"] + label span {
display:inline-block;
width:19px;
height:19px;
margin:-1px 4px 0 0;
vertical-align:middle;
background:url(http://csscheckbox.com/checkboxes/u/csscheckbox_ef32e9f2ed5c57aba4c2206a981ba7a4.png) 0px top no-repeat;
cursor:pointer;
}
/*doesn't work*/
input[type="radio"]:checked {
background:url(http://csscheckbox.com/checkboxes/u/csscheckbox_ef32e9f2ed5c57aba4c2206a981ba7a4.png) 0px bottom no-repeat;
}
The problem is, that
input[type="radio"]:checked
doesn't work for me. Nothing happens when I click the button. Although pseudo-classes :hover and :active work fine.
I have this HTML code:
<td class="AFContentCell" valign="top" nowrap="">
<div id="pt1:r1:0:sor2::content" class="af_selectOneRadio_content" name="pt1:r1:0:sor2">
<fieldset style="border:none; margin:0px; padding:0px;">
<legend class="p_OraHiddenLabel">Please choose something:</legend>
<div>
<span class="af_selectOneRadio_content-input">
<input id="rad1" class="af_selectOneRadio_native-input" type="radio" value="0" name="pt1:r1:0:sor2">
</span>
<label class="af_selectOneRadio_item-text" for="rad1">Yes</label>
</div>
<div>
<span class="af_selectOneRadio_content-input">
<input id="rad2" class="af_selectOneRadio_native-input" type="radio" value="1" name="pt1:r1:0:sor2">
</span>
<label class="af_selectOneRadio_item-text" for="rad2">No</label>
</div>
</fieldset>
</div>
</td>
This HTML is generated by ADF and I can't add or change something. As far as I understand, the problem is with that input element being in span element and label being outside of the span element. Can someone help me out with that?
Important: I can't change HTML file. I need to figure out, how to get this to work using CSS. Without JavaScript or jQuery.
UPDATE:
Answer to Zack: I am using type="radio" and type="checkbox" together. Thank you for noticing my misprinting. Still this doesn't solve the issue for me.
Answer to Diodeus: What? You can find a bunch of tutorials explaining how to do it. Here is step-by-step video tutorial: https://www.youtube.com/watch?v=FQl_bcF4jOk
And this is cross-browser compatible.
Answer to bigal: Thank you very much for your detailed answer. Now everything works fine for me and I understand what I was doing wrong.
The problem first is that you have the image of the button on your span and radio button while the radio button (the thing you want the user to click on) is hidden.
Remove the background image on the span tag but keep the background image on the radio button and reveal your radio button again.
Then disable wekbit/moz appearance (so the default radio button goes away) and increase the width and height of the button to 21px (because 19px is too little).
The final CSS I have:
input[type="radio"] {
display:inline-block;
width:21px;
height:21px;
margin:-1px 4px 0 0;
vertical-align:middle; background:url(http://csscheckbox.com/checkboxes/u/csscheckbox_ef32e9f2ed5c57aba4c2206a981ba7a4.png) 0px top no-repeat;
cursor:pointer;
appearance:none;
-moz-appearance:none; /* Firefox */
-webkit-appearance:none; /* Safari and Chrome */
}
input[type="radio"]:checked {
background:url(http://csscheckbox.com/checkboxes/u/csscheckbox_ef32e9f2ed5c57aba4c2206a981ba7a4.png) 0px bottom no-repeat;
}
.af_selectOneRadio_item-text {
color: Green;
}
Here is the link to what I've spoken about: http://jsfiddle.net/sbef2so3/16/
I facing issues with the alignment inside a column. I am not sure what I am going wrong. Different browser shows different result. Chrome and IE reacts similarly. So as Safari and Firefox. I am designing a popup. Inside the popup there are three main DIVs. Header, body and footer. The body has three DIVs as three columns. Everything else is aligned perfectly, except the middle column in the body. The popup width is 810px. The middle column is 32% of it. The issues I am facing.
The first box in the middle column is email address box, for some reason, the width is way lesser in chrome and IE.
Second box is Red Sumbit box - not aligned with email address box of anything else in the column
Third is text - We will never share your email address - BR - Why we ask - Privacy policy. For some reason, when I use BR to separate these two lines, the second line "Why we ask - Privacy Policy" is aligned to the center. I would like to have it aligned left.
the last box - Already member? Login - same here the box is not aligned left properly.
Everything in the columnn is not aligned to left. I am not able to assign anything to margin-left, since it throws off my third column image. I am attaching the HTML and CSS for the middle column. Thanks
input [type=text] {
padding:1px;
border:1px;
-webkit-border-radius: 13px;
width:236px;
font-size:11px;
font-family: Lucida Grande;
font-weight: regular;
margin-left: 2px;
margin-top:10px;
}
input[type=submit] {
background: #9B1C1F;
font-family: Lucida Grande;
color: #ffffff;
font-weight: bold;
font-size:14px;
text-align:left;
width: 241px;
margin-top:10px;
padding:5px 15px;
border:0 none;
cursor:pointer;
-webkit-border-radius: 2px;
}
#already {
float:left;
padding: 5px 5px 5px;
width:236px;
background: #A2CD39;
font-family: Lucida Grande;
font-size:18px;
margin-left:0px;
margin-top:30px;
color: #ffffff;
display: inline-block;
}
#whyweask {
float: left;
font-size:12px;
margin-left:0px;
margin-top:7px;
}
#middlecolumn {
float: left;
width:32%;
margin-top:36px;
}
<div>
<div id="middlecolumn">
<form name="MailingList" method="post" action="Config_FullStoreURLMailingList_subscribe.asp">
<span style="margin-left:1px;">
<input type="text" name="emailaddress" placeholder="Email Address" maxlength="100" size="30px">
<br>
<onclick="javascript:location.href='www.thankyou.html'">
<input type="submit" value="SUBMIT">
</form>
<div id="whyweask">We will never share your email address.</br>
Why we ask - <u>Privacy Policy</u>
</div>
<div>
<span id="already">
Already Member?
<b><u> Login </u></b> </span>
</div>
</div>
</div>
You have a space in your input [type=text], remove it to make it input[type=text].
All of your elements (input[type=text], input[type=submit], #already) have widths defined (width:236px;, width: 241px;, width:236px;) respectively. You need to change these to be the same widths or preferably width: 100%; to fit within your #middlecolumn element container.
Your text, in the #whyweask element, doesn't have a width defined. Go ahead and add width: 100%; to this as well.
Everything should now fit within your #middlecolumn element and be perfectly aligned.
Pro tip: You can always put a border around your container (in this case, it's #middlecolumn) like #middlecolumn { border: 1px solid red; } so that you can visually see how your elements fit inside to debug. I would typically do this inside of my web inspector tool to test quickly without having to save it into my CSS.
I have a website design that includes text input fields that look like this:
Input Field http://img401.imageshack.us/img401/4453/picture1ts2.png
I'm wondering what the best solution for creating this input field is.
One idea I have is to always have a div around the input with a background image and all the borders disabled on the input field and specified width in pixels, such as:
<div class="borderedInput"><input type="text" /></div>
I have tried to discourage them from using this format, but they won't be discouraged, so it looks like I'm going to have to do it.
Is this best or is there another way?
--
Trial:
I tried the following:
<style type="text/css">
input.custom {
background-color: #fff;
background:url(/images/input-bkg-w173.gif) no-repeat;
width:173px;
height:28px;
padding:8px 5px 4px 5px;
border:none;
font-size:10px;
}
</style>
<input type="text" class="custom" size="12" />
but in IE (6 & 7) it does the following when you type more than the width:
Over Length http://img240.imageshack.us/img240/1417/picture2kp8.png
I'd do it this way:
<style type="text/css">
div.custom {
background:url(/images/input-bkg-w173.gif) no-repeat;
padding:8px 5px 4px 5px;
}
div.custom input {
background-color: #fff;
border:none;
font-size:10px;
}
</style>
<div class="custom"><input type="text" class="custom" size="12" /></div>
You just have to adjust the padding values so everything fits correctly.
It is - in my eyes- definitely the best solution since in any other case you're working with a whole input field. And the whole input field is - by definition - a box where users can enter text.
If you can rely on JavaScript you could wrap such div-Elements around your input fields programatically.
Edit:
With jQuery you could do it this way:
$( 'input.custom' ).wrap( '<div class="custom"></div>' );
CSS:
div.custom {
background:url(/images/input-bkg-w173.gif) no-repeat;
padding:8px 5px 4px 5px;
}
input.custom {
background-color: #fff;
border:none;
font-size:10px;
}
And your HTML:
<input class="custom" ... />
You don't need the div element, you can assign a background to the input directly.
Edit: Here is the working code. I tested it, but you'll have to adjust it for your needs. As far as I can tell, everything here is needed.
input {
background: #FFF url(test.png) no-repeat bottom right;
width: 120px;
height: 20px;
line-height:20px;
padding:0;
text-indent:3px;
margin:0;
border: none;
overflow:hidden;
}
Edit2: I'm not quite sure why I'm getting downvoted, but this method should work unless you need an image bigger than the input element itself. In that case, you should use the extra div element. However, if the image is the same size as the input, there is no need for the extra markup.
Edit3: Ok, after bobince pointed out a problem, I'm getting a little closer. This will be work in IE6&7 and it's close in FF, but I'm still working on that part.
input {
background: #FFF url(test.png) no-repeat 0px 0px;
background-attachment:fixed;
width: 120px;
height: 20px;
line-height:20px;
padding:0px;
text-indent:3px;
margin:0;
border: none;
}
body>input {
background-position:13px 16px;
}
Edit4: Ok, I think I got it this time, but it requires use of a CSS3 selector, so it won't validate as CSS 2.1.
input {
background: #FFF url(test.png) no-repeat 0px 0px;
background-attachment:fixed;
width: 120px;
height: 20px;
line-height:20px;
padding:0px;
text-indent:3px;
margin:0;
border: none;
}
body>input {
background-position:13px 16px;
}
body>input:enabled {
background-position:9px 10px;
}
body>input will target everything except for IE6, body>input:enabled will target any form elements that aren't disabled for all browsers except for IE 6, 7, & 8. However, because :enabled is a CSS3 selector, it doesn't validate as CSS2.1. I wasn't able to find an appropriate CSS2 selector that would allow me to separate IE7 from the other browsers. If not validating (yet, until the validator switches to CSS3) is a problem for you, then I think your only option is the extra div element.
Have you evaluated using background image like this:
<style type="text/css">
input{
background-color: #AAAAAA;
background-image: url('http://mysite.com/input.gif');
border: 0px;
font-family: verdana;
font-size: 10px;
color: #0000FF;
}
I have done this a few times. I have the background image inside a div and use css to position the input field accordingly.
Have a peek at the following site I created that used this technique and use the code: http://www.ukoffer.com/ (Right hand side Newsletter)
AFAIK, the background scrolling problem can be solved either in Firefox and friends, OR Internet Exploder; but not make everyone happy at once.
I would normally have said to style the input directly, but now that I think of it that div example doesn't sound too bad and should take care of your background image scrolling problem.
In that case you'd set a div as position:relative, and put the input inside it with proper padding and width (or 100% width if padding is 0), background transparent, and put an image on the div.
okoman has gotten the CSS aspect correct. May I suggest using a <label> to improve the semantic structure of the markup?
<label id="for-field-name" for="field-name">
<span class="label-title">Field Name <em class="required">*</em></span>
<input id="field-name" name="field-name" type="text" class="text-input" />
</label>
<style type="text/css">
label, span.label-title { display: block; }
</style>
Not only is this more accessible, but it provides numerous hooks that you can use for any type of DOM manipulation, validation or field-specific styling in the future.
Edit: If you don't want the label title displayed for some reason, you can give it a class of 'accessibility' and set the class to display: none; in the CSS. This will allow screen readers to understand the input but hide it from regular users.
The easiest way to get rid of the overflow without JavaScript is simple:
Create a 3 spans, and set their heights to the height of the
image.
Cut the image into 3 parts, ensuring you cut the image such that
the left and right round parts will be on the 1st and 3rd images
respectively.
Set the background of the 1st span to the image
with the left border, and set it to no-repeat.
Set the background
of the third span to the image with the right border and set it to
no-repeat.
Put the input inside the middle span, remembering to
set its height to the height of the spans, and its background to the
2nd image, and repeat-x only.
That will ensure that the input
will seem to expand horizontally once the input is being filled. No
overlapping, and no JS needed.
HTML
Assuming the image height is 60px, the width of the first and third span is 30px,
<span id="first">nbsp;</span><br />
<span id="second"><input type="text" /></span><br />
<span id="third">nbsp;</span>
CSS
span#first{background:url('firstimage') no-repeat; height:60px; width:30px;}
span#third{background:url('thirdimage') no-repeat; height:60px; width:30px;}
span#second input{background:url('second image') repeat-x; height:60px;}
That should resolve your issue.