Custom styled radio buttons? [closed] - html

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hello I'm a student that is building a site for a friends business and I have learned online how to make radio buttons styled with custom images but i am trying to make a small, medium , large option to make the user able to choose the size. I know java but not much Jquery. I understand if it is not possible and I am open to other ways of accomplishing the task as long as i can make code that can check which option is selected to make it direct them to the right page/shopping-cart product.
---HERE'S AN EXAMPLE OF WHAT I HAVE SO FAR: http://squidsquadgang.com/radiobuttons.html
any help would be much appreciated!
Thank you,
Stephen T.

You have quite a bit of JavaScript doing the work on the radio buttons. The javaScript you are using is actually creating dynamic <span> elements and completely hiding the radiobuttons. While this may support old browsers better, a much more "future-proof" (one might even say "correct") way to do this is through pure CSS. It's simpler, gives you more options and customization, and it will load much faster than that giant JavaScript file.
So, while this may not be exactly what you came here looking for, I encourage you to at least give this a try.
Example: Here's what I've done.
Give it a try: go into your image editor and remove the text. Now, the text displayed on your buttons is in your HTML code. much easier to edit than images, and faster too.
The code explained: Making custom CSS radio buttons
input[type=radio] {
display:none;
}
This selects all the radio buttons on the page and gives them a display:none property. It hides the radio buttons, since you don't want to see those ugly things anymore.
input[type=radio] + label { ... }
This selects all of the radio button labels. In our HTML, we've created labels for each of the <input> elements. It's a built in feature in HTML: when labels are clicked, the radio button is automatically selected. We don't need any javascript here! Don't reinvent the wheel.
Here, we define both the background image and the style of the text to be displayed over the background image (if any). In this case, it's "XS", "S", and "M". I've used display:table-cell to display the buttons side-by-side (like in your link) and make use of the vertical-align property. If there is no text, simply change it do display:inline-block and adjust from there.
input[type=radio]:checked + label { ... }
Finally, we specify the styling for the selected option. In your case, I've moved the background image down 42px (background-position:0 -42px;). Again, you are going to want to remove the text from your image. You can look up other styling you can do - you could make the text "glow" by adding something like:
text-shadow:2px 2px 10px #FF00FF;
You can play around with the details. Even though it's not going to display the images IE8 and before, this will still nicely fall back to whatever text you have in <label>. It will just go to regular old radio buttons. People smart enough to use Chrome or keep IE updated, well, they'll get the extra eye-candy.

I guess you are asking something like this:
http://jsfiddle.net/vybEf/1/
$('.styled').click(function(){
var idS=$(this).attr('id');
var s=idS.substring(5,7);
$('#txt').css({'font-size':''+s+'px'});
$('#txt').html(''+s+'px');
});

Related

Can I format HTML or CSS is a way that makes it easy for users to copy a block of text on mobile

I am looking for a way to format a section of my page so users can easily copy a small block of text while on a mobile device.
Are there any classes in Bootstrap, some HTML, or a way to format my CSS to make this easier. I know browsers except IE don't like javascript copying text to the clipboard.
Since your question is specific to HTML & CSS for mobile, here are some thoughts.
I find that having large hit areas available on the elements you want the user to interact can help to start with. E.g. paddings on <p>s for example. So when a user starts tap-holding to initiate text selection, it'll more likely fall on the hit area of the paragraph. (A nifty trick is replacing margins with paddings!)
Try to make sure your content that is selectable follow a natural content flow box model. No weird floats or absolutely positioned content or otherwise content that might confuse the selection widget. Make it as document-like as possible!
Read up on the ways that you can control selection, e.g. user-select CSS property - https://developer.mozilla.org/en-US/docs/Web/CSS/user-select
You might want to disable text selection on elements that don't make sense, to help make text selection cleaner on the parts that matter.
Large font sizes are obvious, but maybe not so obvious is very large line-heights is fantastic for making text-selection a little less awkward! It can improve readability greatly on the side as well, my favourite for body text is line-height: 1.6;.
If you use viewport meta tag, make sure they can zoom in to fill the text/paragraph edge-to-edge comfortably when they want to. This can help a lot to get up close, to do the text selection and get tactile with your content.
However, if you do want to try JS, then I would recommend clipboard.js: https://clipboardjs.com/
Think also about what your users want to copy ahead of time, you might be able to do some analytics and allow users to highlight common text. This is done on Medium by the way to lead as a good example.
You could make it so that when they click on the element, all the text is selected automatically, so all they had to do, assuming they're using a modern mobile device, is long-tap and press copy to clipboard.
document.getElementById("TextParent").onclick(function(){
fnSelect("TextParent");
});
So your html would look something like the following:
<div id="TextParent">
Click anywhere in this div to select this text!
</div>
Adding to this, Nexii Malthus has a good point in regards to the hit areas on mobile phones, so maybe try to add some extra padding to the div.
You should definitely try https://clipboardjs.com/.
<!-- Target -->
<div id="bar">Mussum ipsum cacilds...</div>
<!-- Trigger -->
<button class="btn" data-clipboard-action="copy" data-clipboard-target="#bar">
Copy to clipboard
</button>
and activate it using following javascript new Clipboard('.btn')
Look created sample https://jsfiddle.net/gevorgha/fbeof421/
Note
There are some compatibility issues with iOS devices that do not copy target on trigger action, but it selects target and allows user to copy it manually.

How to align a label vertically in apps script?

I'm trying to align text vertically in a label.
This doesn't work :
.setStyleAttribute("verticalAlign","bottom")
Does anyone know how to do that?
You should be using vertical-align instead of verticalAlign as setStyleAttribute() uses CSS to display.
However, it doesn't seem to work despite that. Labels have a setHorizontalAlignment() method but no setVerticalAlignment() method.
The above two facts makes me think that vertical alignment is not allowed in widgets such as a Label or it might be a bug. It is probably worth opening an issue in the issue tracker
I assume you are confusing the Label with the Panel, if so then what you are trying to do is to align the label in the panel. Do so like this:
panel.setHeight(100)
.setVerticalAlignment(UiApp.VerticalAlignment.BOTTOM).add(label);
To clarify (in a flow-layout) the size of the label is automatically the same size as the text, so it would not usually make sense to align the text inside of the label unless you had already re-sized the label. The flow-layout is what is used in VerticalPanel and HorizontalPanel.
The CSS "label.setStyleAttribute('vertical-align','bottom');" that I've tried did NOT work, so I'm guessing we would need to dig into the GWT for a more literal solution to this question. I would be interested to see one. For more info checkout the objects in the GAS API or GWT Panels, or let me know if I missed something relevant.

Center text vertically in select

image
question
Is there any way I can shift the "Vancouver, BC" text down a little bit so it aligns better with "CITIES" and "CHANGE"?
I know input elements are finicky to style across browsers; it doesn't have to be perfect but if it could work in at least some browsers, that would be great.
fiddle
Customizing a browser's default rendering of some form elements--especially dropdown select lists--is generally not recommended for a few reasons:
Your customization options are naturally limited
It's extremely difficult to get the form element to look the way you want--as you noted, they're finicky
Even if you can get the input to look the way you want in one browser, its almost impossible to do it cross-browser (I realize you said that's not a concern, but still, it's worth knowing)
From a usability perspective, customizing the default rendering of a form element almost always reduces the usability of the form somewhat
NOW, all of that being said, if you want more control over the visual styles of your form elements, I'd recommend using a jQuery plugin. Typically these work by hiding the form elements and replacing them with easily-customizable CSS--usually regular ol' unordered-lists--and then sending the user interactions with the unordered lists to the hidden forms. Here's one you could check out to get started.
I would adjust the font-size or the height to fix the alignment issue:
#city_picker {
height: 26px;
font: 19px Arial,Helvetica,sans-serif;
}
That would make the text about the same size as the select box, and force it to appear aligned. Otherwise it seems rather difficult if not impossible to adjust styles of the option elements across browsers.

How to make select inputs look the same in all browsers on all platforms?

i'm solving a problem to make select inputs look the same in all browsers (Chrome and Safari on Mac renders them differently) how to do that ?
The ONLY way to make them look the same right now would be to hide the original inputs, and replace them with appropriately styled html equivalents (of god forbig Flash objects), which would act as proxies, passing the functionality over to the hidden inputs.
That may be automated with JavaScript. But that would be WRONG. You are not supposed to force a different look on to OS styled elements of the webpage. It conflicts with a lot of usability and accessibility practices.
So, the only way is to make your design flexible enough to support differently looking control elements on a web page, and also use different stylesets for different browsers, to ease the adjustment of the styles (at the moment there are no inputs that would look and act the same on all browsers with the same style rules applied).
Unfortunately, life just kinda sucks on this one. Just wait till you need to style a file input...now that's some fun!
if you dont mind using js you can simply design your own look (a jpg img it can even be the same img as the original select element or if you wish you can model parts of it in css)
Then place a div on top of that image that div will contain the text which select element would usually contain
<div id="selectTxt" >
then set another div on top of that with the select element inside it.
<div id="transparentSelect" class="transparent">
<select id="selectCar" name="selectCar">
<option>Volvo</option>
<option>Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</select>
</div>
Now the trick is to set the select element opacity to zero
you can do this by adding by adding a class transparent
and then applying the class to the div
.transparent
{
filter:alpha(opacity=0);
-moz-opacity: 0;
opacity: 0;
}
now the element is hidden but when you click on it the list will still show up.
So the list will always look like the default list in the browser
now use js to extract the select value every time you click on the select
and set the inner html of selectTxt div to its value.
This way you get the text of the select on top of an image you want
you can make the image animated with the hover effect in css or with js
I also make a select that looks the same in all browsers but it doesnt work when you click directly on the arrow...
so its an inferior version but if you wish to look at it here it is
http://jsfiddle.net/fiddlerOnDaRoof/LM73V/
it also lacks the arrow image but you can print screen that from your browser
good luck
You should apply a CSS to reset the styles (not just for the inputs, this is a highly recommended practice for all element so that your page looks almost the same in all browsers) there are many, just google a little, for example this one, and then apply your desired styles (border color and width, background, etc...) take a look at this tutorial on how to style form elements

What Html markup for a focusable TD?

I want to practive, and even best-practice, with Html+JS+CSS.
I use a one page client-only Sudoku page.
My Sudoku markup is basically a <table>, with <td>.
(I'm open to suggestions to improve this).
My requirements :
Have a cell under focus (the keyboard notion of focus) (highlighed with css to a yellow background)
Navigate through cells with arrow keys (plus Home etc).
type-in an integer value sets that value to the currently focused cell
I use an input button inside each cell.
The Javascript works fine.
My only problem is with the display.
When a cell has the focus, it's highlighted display doesn't cover the whole TD, rather only the visual space included in the input button. I have some space around the button that isn't 'yellow'.
I don't think I could go up in the CSS selection, to select the parent of the input, could I ? Such as :
input:focus '?? how to go up ??' td { background-color:yellow;
I tried a few tricks, like having always 5 characters in each button display (5 spaces when empty, changing the middle character when set), but nothing is visually satisfying.
Even worse, it is clearly against best-practices to alter the content for the sake of visualizing. That's what the MVC distinction between Html/Css/Js is for !
I already searched this site for answer, I found close but distinct questions and answer.
I'm hoping someone could help improve my page ... and my markup skill :-)
It is not possible to construct a css selector which matches a parent node dependent on a (pseudo-)class of child node.
Basically you have two options to choose from:
Try to fill the td with the input completely using height and width rules in your css.
Set 'focused' and 'unfocused' class on your tds with javascript using the onfocus and onblur events of the inputs.
Could you not use a dash of jQuery to set a .focused class and then apply some style to it?