This question already has answers here:
How to display image in place of checkbox?
(8 answers)
Closed 8 years ago.
I'm involved in making bus booking sites project. I need to use the seats to book.
So, can we replace checkbox with the image. If Possible, please tell me.
Or, if there is any other possibility, please furnish me with ideas.
Thnku.
offer a simple solution to css DEMO
HTML
<input type="checkbox" id="checkbox-id" /> <label for="checkbox-id">Some label</label>
CSS
input[type="checkbox"] {
position: absolute;
left: -9999px;
}
input[type="checkbox"] + label {
background: url(http://xandeadx.ru/examples/styling-checkbox/checkbox-sprite.gif) 0 0 no-repeat;
padding-left: 20px;
}
input[type="checkbox"]:checked + label {
background-position: 0 -32px;
}
Related
This question already has answers here:
What’s the point of the ::before and ::after pseudo-element selectors in CSS?
(5 answers)
How to style a checkbox using CSS
(43 answers)
Closed 10 months ago.
The company I work for has an in-house extension of bootstrap classes. I'm having difficulty using the checkbox they provide, so I have to dive into their code. I'm starting with this HTML snippet:
<div class="checkbox XXXbs-checkbox">
<label for="checkbox-id">Some Text</label>
<input class="form-control" id="checkbox-id" name="checkbox-name" role="checkbox" type="checkbox" value="y">
</div>
Their checkbox css contains this ("XXX" is in place of a string that would identify the company I work for):
.XXXbs-checkbox input[type=checkbox] {
opacity: 0;
margin-left: 4px;
cursor: pointer;
z-index: 1;
width: 100%;
}
Opacity is 0, making the actual checkbox from the above HTML invisible. Meanwhile, they also have this:
.XXXbs-checkbox>label::before {
font-family: XXX-icon;
content: "\e903";
font-size: 32px;
position: absolute;
top: -15px;
left: 0;
}
to place an empty checkbox before the label, and this:
.XXXbs-checkbox>input[type=checkbox]:checked+label::before {
content: "\e904";
color: #000
}
to render a box with a check mark in it.
My question is, why would you use this approach? Why would you draw a fake checkbox in front of the label instead of just styling the actual checkbox?
Why would you draw a fake checkbox in front of the label instead of just styling the actual checkbox?
Because the amount of styling you can apply to a checkbox itself is very, very limited.
This question already has answers here:
How to set placeholder value using CSS?
(12 answers)
Closed 1 year ago.
I have a search input and I need to change the content of placeholder which is currently no, but only with css. I have tried but I can't get it...
<input id="search-input" type="search" class="search-field" placeholder="no" value="" name="s" title="Search:">
Here my wrong css:
.seach-field::placeholder{
display: none;
}
.seach-field::placeholder::after {
content: "yes";
}
pd: this is my first time on Stackoverflow, I am sorry if I didn't put it right or if I didn't post it where it should be :(
You can do it whith a some tricks, but is not the correct way to do that, because the placeholder text you write with css is wrote over the text when you write in it.
However I explain how to do it with CSS:
You can use the ::before selector to add some text before any block element.
.wrapper {
position: relative;
}
.wrapper:before {
position: absolute;
content: 'Name';
left: 10px;
top: 2px;
color: #ccc;
}
<p class="wrapper">
<input id="name" type="text">
</p>
I hope I've helped you.
This question already has answers here:
Add a text suffix to <input type="number">
(4 answers)
Closed 3 years ago.
I have an html input that looks like this:
<input type="number" min="4" max="100" step="1" name="myInput" value="33">
I am populating the value from a cookie/storage that is getting set from a previous screen. The previous screen is asking for a party size.
From a UX perspective, it i not clear what 33 means in this screen. Since I am populating the input, I cannot use placeholder text. This is why I am wondering if there is a way to inject "People" after the value somehow.
I really like how clean the UI looks without visible form labels, so if possible, I'd like to stay away from adding them.
Here is what I have now:
This is what I am trying to accomplish (the red text):
Perhaps it is as "simple" as a background image, but I'd like to keep the spacing nice and sharp. Thank you for any suggestions!
Try something like this, perhaps this will help you point you in the right direction:
HTML:
<label data-placeholder="people">
<input type="number" min="4" max="100" step="1" name="myInput" value="33">
</label>
SCSS:
LABEL {
position: relative;
&:after {
content: attr(data-placeholder);
position: absolute;
color: red;
z-index: 1;
top: 1em;
right: 1em;
}
INPUT {
width: 200px;
box-sizing: border-box;
padding-right: 5em;
}
}
This question already has answers here:
Can I have an onclick effect in CSS?
(14 answers)
Closed 5 years ago.
I am building a store website and I have problem with variations of the products. So I have the main product. I have 3 boxes with variations on color and when I hover them it changes the color, but the update of the site requires from me to change it from hoverable to clickable. It works when I change the CSS from
img:hover
to
img:active
but after the click the color returns to previous one. So can after click of the color to remain there instead of going back to previous color. And can it be done without JAVASCRIPT
.box {
position: relative;
width: 100px;
height: 100px;
background-color: #F4F4F4;
}
.box label {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.box input {
visibility: hidden;
}
.box input:checked + label {
background-color: red;
}
<div class="box">
<input type="checkbox" id="test">
<label class="color" for="test"></label>
</div>
:active means "while being clicked on", not "has been clicked on in the past". It is designed for such things as creating a 3D button depresses when you click on it effect.
CSS has no means to track state.
You might be able to hack something using :focus, but that is designed to indicate what you will activate if you were to press Enter, so is almost never a good choice for this sort of thing. It also only allows you to have one thing focused at a time.
If you want to track state for interactive things: use JavaScript.
CSS is not designed for that.
This question already has answers here:
Why do the :before and :after pseudo-elements require a 'content' property?
(5 answers)
Closed 7 years ago.
I have a button and on a :hover I would like an after element to show. But I can't see it. Is it possible to have an :after element on a button?
.button {
cursor: pointer;
height: 30px;
}
.button-primary {
border: none;
}
.button-primary:hover:after {
display: block;
position: relative;
top: 3px;
right: 3px;
width: 100px;
height: 5px;
}
<button class="button button-primary">My button</button>
This should now work on all up to date browsers.
To get it to work, you need to add content:""; in your after.
Yes you can use it – as long as you as don't need to support some very old browsers, e.g. MS IE 7 or lower. I don't know of any other browser that doesn't understand pseudo elements on empty HTML tags. In fact I already used it in several production sites without any problems.