जवाबों:
अगर किसी भी ब्राउज़र में कुछ होता है तो मुझे आश्चर्य होगा। यह उन उत्कृष्ट फॉर्म एलिमेंट्स में से एक है, जो ब्राउज़र आपको बहुत स्टाइल करने नहीं देते हैं, और यह कि लोग आमतौर पर जावास्क्रिप्ट के साथ बदलने की कोशिश करते हैं ताकि वे चेकबॉक्स की तरह दिखने और कार्य करने के लिए कुछ शैली / कोड कर सकें।
मैं "सीमा" के बजाय "रूपरेखा" का उपयोग करने का सुझाव देता हूं। उदाहरण के लिए outline: 1px solid #1e5180:।
!importantरूपरेखा का उपयोग करते समय आपको अपने सीएसएस में जोड़ने की आवश्यकता हो सकती है । मैं 12.0 फ़ायरफ़ॉक्स में यह परीक्षण कर रहा था और महत्वपूर्ण बिना रूपरेखा के गायब हो जाएगा जब तक मैं चेकबॉक्स पर क्लिक कर रहा था।
आपको उपयोग करना चाहिए
-moz-appearance:none;
-webkit-appearance:none;
-o-appearance:none;
तब आप डिफ़ॉल्ट चेकबॉक्स छवि / शैली से छुटकारा पा लेते हैं और इसे स्टाइल कर सकते हैं। वैसे भी एक सीमा अभी भी फ़ायरफ़ॉक्स में होगी
बॉर्डर नकली करने के लिए आप बॉक्स छाया का उपयोग कर सकते हैं:
-webkit-box-shadow: 0px 0px 0px 1px rgba(255,0,0,1);
-moz-box-shadow: 0px 0px 0px 1px rgba(255,0,0,1);
box-shadow: 0px 0px 0px 1px rgba(255,0,0,1);
यहां CSS3 लिंक के साथ मार्टिन के कस्टम चेकबॉक्स और रेडियो बटन पर आधारित शुद्ध CSS (कोई चित्र नहीं) क्रॉस-ब्राउज़र समाधान है: http://martinivanov.net/2012/12/12/21/imageless-custom-checkboxes-and-radio-buttons -साथ-css3-दोबारा गौर /
यहाँ एक jsField है: http://jsfiddle.net/DJRavine/od26wL6n/
मैंने निम्न ब्राउज़रों पर इसका परीक्षण किया है:
label,
input[type="radio"] + span,
input[type="radio"] + span::before,
label,
input[type="checkbox"] + span,
input[type="checkbox"] + span::before
{
display: inline-block;
vertical-align: middle;
}
label *,
label *
{
cursor: pointer;
}
input[type="radio"],
input[type="checkbox"]
{
opacity: 0;
position: absolute;
}
input[type="radio"] + span,
input[type="checkbox"] + span
{
font: normal 11px/14px Arial, Sans-serif;
color: #333;
}
label:hover span::before,
label:hover span::before
{
-moz-box-shadow: 0 0 2px #ccc;
-webkit-box-shadow: 0 0 2px #ccc;
box-shadow: 0 0 2px #ccc;
}
label:hover span,
label:hover span
{
color: #000;
}
input[type="radio"] + span::before,
input[type="checkbox"] + span::before
{
content: "";
width: 12px;
height: 12px;
margin: 0 4px 0 0;
border: solid 1px #a8a8a8;
line-height: 14px;
text-align: center;
-moz-border-radius: 100%;
-webkit-border-radius: 100%;
border-radius: 100%;
background: #f6f6f6;
background: -moz-radial-gradient(#f6f6f6, #dfdfdf);
background: -webkit-radial-gradient(#f6f6f6, #dfdfdf);
background: -ms-radial-gradient(#f6f6f6, #dfdfdf);
background: -o-radial-gradient(#f6f6f6, #dfdfdf);
background: radial-gradient(#f6f6f6, #dfdfdf);
}
input[type="radio"]:checked + span::before,
input[type="checkbox"]:checked + span::before
{
color: #666;
}
input[type="radio"]:disabled + span,
input[type="checkbox"]:disabled + span
{
cursor: default;
-moz-opacity: .4;
-webkit-opacity: .4;
opacity: .4;
}
input[type="checkbox"] + span::before
{
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
}
input[type="radio"]:checked + span::before
{
content: "\2022";
font-size: 30px;
margin-top: -1px;
}
input[type="checkbox"]:checked + span::before
{
content: "\2714";
font-size: 12px;
}
input[class="blue"] + span::before
{
border: solid 1px blue;
background: #B2DBFF;
background: -moz-radial-gradient(#B2DBFF, #dfdfdf);
background: -webkit-radial-gradient(#B2DBFF, #dfdfdf);
background: -ms-radial-gradient(#B2DBFF, #dfdfdf);
background: -o-radial-gradient(#B2DBFF, #dfdfdf);
background: radial-gradient(#B2DBFF, #dfdfdf);
}
input[class="blue"]:checked + span::before
{
color: darkblue;
}
input[class="red"] + span::before
{
border: solid 1px red;
background: #FF9593;
background: -moz-radial-gradient(#FF9593, #dfdfdf);
background: -webkit-radial-gradient(#FF9593, #dfdfdf);
background: -ms-radial-gradient(#FF9593, #dfdfdf);
background: -o-radial-gradient(#FF9593, #dfdfdf);
background: radial-gradient(#FF9593, #dfdfdf);
}
input[class="red"]:checked + span::before
{
color: darkred;
}
<label><input type="radio" checked="checked" name="radios-01" /><span>checked radio button</span></label>
<label><input type="radio" name="radios-01" /><span>unchecked radio button</span></label>
<label><input type="radio" name="radios-01" disabled="disabled" /><span>disabled radio button</span></label>
<br/>
<label><input type="radio" checked="checked" name="radios-02" class="blue" /><span>checked radio button</span></label>
<label><input type="radio" name="radios-02" class="blue" /><span>unchecked radio button</span></label>
<label><input type="radio" name="radios-02" disabled="disabled" class="blue" /><span>disabled radio button</span></label>
<br/>
<label><input type="radio" checked="checked" name="radios-03" class="red" /><span>checked radio button</span></label>
<label><input type="radio" name="radios-03" class="red" /><span>unchecked radio button</span></label>
<label><input type="radio" name="radios-03" disabled="disabled" class="red" /><span>disabled radio button</span></label>
<br/>
<label><input type="checkbox" checked="checked" name="checkbox-01" /><span>selected checkbox</span></label>
<label><input type="checkbox" name="checkbox-02" /><span>unselected checkbox</span></label>
<label><input type="checkbox" name="checkbox-03" disabled="disabled" /><span>disabled checkbox</span></label>
<br/>
<label><input type="checkbox" checked="checked" name="checkbox-01" class="blue" /><span>selected checkbox</span></label>
<label><input type="checkbox" name="checkbox-02" class="blue" /><span>unselected checkbox</span></label>
<label><input type="checkbox" name="checkbox-03" disabled="disabled" class="blue" /><span>disabled checkbox</span></label>
<br/>
<label><input type="checkbox" checked="checked" name="checkbox-01" class="red" /><span>selected checkbox</span></label>
<label><input type="checkbox" name="checkbox-02" class="red" /><span>unselected checkbox</span></label>
<label><input type="checkbox" name="checkbox-03" disabled="disabled" class="red" /><span>disabled checkbox</span></label>
मुझे पता है कि मैं बूढ़ा हो गया हूं .. लेकिन एक लेबल टैग के अंदर अपना चेकबॉक्स डालने के लिए थोड़ा वर्कअराउंड होगा, फिर एक बॉर्डर के साथ लेबल को स्टाइल करें:
<label class='hasborder'><input type='checkbox' /></label>
तब लेबल शैली:
.hasborder { border:1px solid #F00; }
label { position: relative; overflow: hidden; width: 16px; height: 16px; border: 1px solid #0f0; }और फिर label > input[type=checkbox] { position: absolute; left: -999px; }यह आपको कस्टम स्टाइल को अपना चेकबॉक्स देगा और मूल चेकबॉक्स अभी भी चेक / अनचेक किया जाएगा, लेकिन उपयोगकर्ता इसे नहीं देखेगा। वे केवल आपका कस्टम चेकबॉक्स देखेंगे।
:hoverऔर :checkedस्टाइल करने के लिए चयनकर्ताओं का उपयोग कर सकते हैं ।
यहाँ मेरा संस्करण है जो चेकबॉक्स टिकर के लिए FontAwesome का उपयोग करता है, मुझे लगता है कि FontAwesome का उपयोग लगभग हर कोई करता है इसलिए यह मान लेना सुरक्षित है कि आपके पास भी है। आईई / एज में परीक्षण नहीं किया गया है और मुझे नहीं लगता कि किसी को परवाह है।
input[type=checkbox] {
-moz-appearance:none;
-webkit-appearance:none;
-o-appearance:none;
outline: none;
content: none;
}
input[type=checkbox]:before {
font-family: "FontAwesome";
content: "\f00c";
font-size: 15px;
color: transparent !important;
background: #fef2e0;
display: block;
width: 15px;
height: 15px;
border: 1px solid black;
margin-right: 7px;
}
input[type=checkbox]:checked:before {
color: black !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<input type="checkbox">
के लिए फ़ायरफ़ॉक्स , क्रोम और सफारी , कुछ नहीं होता।
के लिए आईई सीमा चेकबॉक्स (नहीं चेकबॉक्स का हिस्सा है) के बाहर लागू किया जाता है, और "कल्पना" छायांकन चेकबॉक्स में प्रभाव चला गया (एक oldfashioned चेकबॉक्स के रूप में प्रदर्शित) है।
के लिए ओपेरा बॉर्डर शैली वास्तव में चेकबॉक्स तत्व पर सीमा लागू कर रहा है।
ओपेरा भी अन्य ब्राउज़रों की तुलना में चेकबॉक्स पर अन्य स्टाइलिंग को संभालता है: रंग को टिक के रंग के रूप में लागू किया जाता है, पृष्ठभूमि-रंग को चेकबॉक्स के अंदर पृष्ठभूमि रंग के रूप में लागू किया जाता है (आईई पृष्ठभूमि को लागू करता है जैसे कि चेकबॉक्स <div>पृष्ठभूमि के साथ अंदर था ) ।
सबसे आसान उपाय यह है <div>कि दूसरों की तरह सुझाए गए चेकबॉक्स को लपेटें ।
यदि आप उपस्थिति को पूरी तरह से नियंत्रित करना चाहते हैं, तो आपको उन्नत छवि / जावास्क्रिप्ट दृष्टिकोण के साथ जाना होगा, अन्य लोगों द्वारा भी इसका मतलब है।
स्टाइलिंग चेकबॉक्स (और उस मैटर के लिए कई अन्य इनपुट तत्व) शुद्ध सीएसएस के साथ वास्तव में संभव नहीं है यदि आप दृश्य उपस्थिति को काफी बदलना चाहते हैं।
आपका सबसे अच्छा दांव कुछ ऐसा लागू करना है जैसे कि jqTransform करता है जो वास्तव में आपको छवियों के साथ इनपुट की जगह देता है और एक चेकबॉक्स (या उस मामले के लिए अन्य तत्व) की नकल करने के लिए उस पर जावास्क्रिप्ट व्यवहार लागू करता है
नहीं, आप अभी भी चेकबॉक्स को स्टाइल नहीं कर सकते हैं, लेकिन मैंने (अंत में) यह पता लगाया कि चेकबॉक्स पर क्लिक करने की कार्यक्षमता को बनाए रखते हुए भ्रम को कैसे स्टाइल किया जाए । इसका मतलब है कि आप इसे टॉगल कर सकते हैं, भले ही कर्सर पूरी तरह से अभी भी बिना टेक्स्ट का चयन किए या ड्रैग-एंड-ड्रॉप को ट्रिगर किए बिना न हो!
उदाहरण एक स्पैन "बटन" के साथ-साथ एक लेबल में कुछ पाठ का उपयोग कर रहा है, लेकिन यह आपको यह विचार देता है कि आप चेकबॉक्स को कैसे अदृश्य बना सकते हैं और इसके पीछे कुछ भी आकर्षित कर सकते हैं।
यह समाधान शायद रेडियो बटन भी फिट बैठता है।
IE9, FF30.0 और Chrome 40.0.2214.91 में निम्नलिखित कार्य करता है और यह केवल एक मूल उदाहरण है। आप इसे अभी भी पृष्ठभूमि छवियों और छद्म तत्वों के संयोजन में उपयोग कर सकते हैं।
http://jsfiddle.net/o0xo13yL/1/
label {
display: inline-block;
position: relative; /* needed for checkbox absolute positioning */
background-color: #eee;
padding: .5rem;
border: 1px solid #000;
border-radius: .375rem;
font-family: "Courier New";
font-size: 1rem;
line-height: 1rem;
}
label > input[type="checkbox"] {
display: block;
position: absolute; /* remove it from the flow */
width: 100%;
height: 100%;
margin: -.5rem; /* negative the padding of label to cover the "button" */
cursor: pointer;
opacity: 0; /* make it transparent */
z-index: 666; /* place it on top of everything else */
}
label > input[type="checkbox"] + span {
display: inline-block;
width: 1rem;
height: 1rem;
border: 1px solid #000;
margin-right: .5rem;
}
label > input[type="checkbox"]:checked + span {
background-color: #666;
}
<label>
<input type="checkbox" />
<span> </span>Label text
</label>
यहाँ एक सरल तरीका है (छद्म तत्वों / वर्गों से पहले या बाद में उपयोग करने के लिए):
input[type=checkbox] {
position: relative;
}
input[type=checkbox]:after {
position: absolute;
top: 0;
left: 0;
/* Above three lines allow the checkbox:after position at checkbox's position */
content: '';
width: 32px;
height: 32px;
z-index: 1; /* This allows the after overlap the checkbox */
/* Anything you want */
}
<!DOCTYPE html>
<html>
<head>
<style>
.abc123
{
-webkit-appearance:none;
width: 14px;
height: 14px;
display: inline-block;
background: #FFFFFF;
border: 1px solid rgba(220,220,225,1);
}
.abc123:after {
content: "";
display: inline-block;
position: relative;
top: -3px;
left: 4px;
width: 3px;
height: 5px;
border-bottom: 1px solid #fff;
border-right: 1px solid #fff;
-webkit-transform: rotate(45deg);
}
input[type=checkbox]:checked {
background: #327DFF;
outline: none;
border: 1px solid rgba(50,125,255,1);
}
input:focus,input:active {
outline: none;
}
input:hover {
border: 1px solid rgba(50,125,255,1);
}
</style>
</head>
<body>
<input class="abc123" type="checkbox"></input>
</body>
</html>
इसे एक div में रखें और div में बॉर्डर जोड़ें