Creating custom checkbox without after element












0















I am trying to make custom checkbox using pure CSS, without required label element, i know there is a lot of answer but i didn't manage to make it as i need to.
Only problem is i have when checkbox is checked, there i do not know how to add checked sign, here is what I have for now






.checkbox-custom {
&:after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}
&:checked:after {
width: 15px;
height: 15px;
color: grey;
}
}

<input type="checkbox" class="checkbox-custom">












share|improve this question

























  • You can use both :before and :after. Check out this one I made a few years ago codepen.io/phiter/pen/KvVPBr

    – Phiter
    Nov 13 '18 at 12:46











  • I need to be stylled like chekcbox, only problem as i sais i have with the checked styling

    – Miomir Dancevic
    Nov 13 '18 at 12:48











  • If you read trough my CSS you'll understand what you can work with. You can use the before for the base and after for the checked element.

    – Phiter
    Nov 13 '18 at 12:50











  • Note that the <input> tag does not use or need a closing slash and never has in HTML.

    – Rob
    Nov 13 '18 at 12:52











  • if you only need a checkmark you could use &:checked:after { content:'2713'; } or search any other entity

    – Dirk
    Nov 13 '18 at 12:52


















0















I am trying to make custom checkbox using pure CSS, without required label element, i know there is a lot of answer but i didn't manage to make it as i need to.
Only problem is i have when checkbox is checked, there i do not know how to add checked sign, here is what I have for now






.checkbox-custom {
&:after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}
&:checked:after {
width: 15px;
height: 15px;
color: grey;
}
}

<input type="checkbox" class="checkbox-custom">












share|improve this question

























  • You can use both :before and :after. Check out this one I made a few years ago codepen.io/phiter/pen/KvVPBr

    – Phiter
    Nov 13 '18 at 12:46











  • I need to be stylled like chekcbox, only problem as i sais i have with the checked styling

    – Miomir Dancevic
    Nov 13 '18 at 12:48











  • If you read trough my CSS you'll understand what you can work with. You can use the before for the base and after for the checked element.

    – Phiter
    Nov 13 '18 at 12:50











  • Note that the <input> tag does not use or need a closing slash and never has in HTML.

    – Rob
    Nov 13 '18 at 12:52











  • if you only need a checkmark you could use &:checked:after { content:'2713'; } or search any other entity

    – Dirk
    Nov 13 '18 at 12:52
















0












0








0








I am trying to make custom checkbox using pure CSS, without required label element, i know there is a lot of answer but i didn't manage to make it as i need to.
Only problem is i have when checkbox is checked, there i do not know how to add checked sign, here is what I have for now






.checkbox-custom {
&:after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}
&:checked:after {
width: 15px;
height: 15px;
color: grey;
}
}

<input type="checkbox" class="checkbox-custom">












share|improve this question
















I am trying to make custom checkbox using pure CSS, without required label element, i know there is a lot of answer but i didn't manage to make it as i need to.
Only problem is i have when checkbox is checked, there i do not know how to add checked sign, here is what I have for now






.checkbox-custom {
&:after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}
&:checked:after {
width: 15px;
height: 15px;
color: grey;
}
}

<input type="checkbox" class="checkbox-custom">








.checkbox-custom {
&:after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}
&:checked:after {
width: 15px;
height: 15px;
color: grey;
}
}

<input type="checkbox" class="checkbox-custom">





.checkbox-custom {
&:after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}
&:checked:after {
width: 15px;
height: 15px;
color: grey;
}
}

<input type="checkbox" class="checkbox-custom">






css css3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 12:52







Miomir Dancevic

















asked Nov 13 '18 at 12:44









Miomir DancevicMiomir Dancevic

3,75183569




3,75183569













  • You can use both :before and :after. Check out this one I made a few years ago codepen.io/phiter/pen/KvVPBr

    – Phiter
    Nov 13 '18 at 12:46











  • I need to be stylled like chekcbox, only problem as i sais i have with the checked styling

    – Miomir Dancevic
    Nov 13 '18 at 12:48











  • If you read trough my CSS you'll understand what you can work with. You can use the before for the base and after for the checked element.

    – Phiter
    Nov 13 '18 at 12:50











  • Note that the <input> tag does not use or need a closing slash and never has in HTML.

    – Rob
    Nov 13 '18 at 12:52











  • if you only need a checkmark you could use &:checked:after { content:'2713'; } or search any other entity

    – Dirk
    Nov 13 '18 at 12:52





















  • You can use both :before and :after. Check out this one I made a few years ago codepen.io/phiter/pen/KvVPBr

    – Phiter
    Nov 13 '18 at 12:46











  • I need to be stylled like chekcbox, only problem as i sais i have with the checked styling

    – Miomir Dancevic
    Nov 13 '18 at 12:48











  • If you read trough my CSS you'll understand what you can work with. You can use the before for the base and after for the checked element.

    – Phiter
    Nov 13 '18 at 12:50











  • Note that the <input> tag does not use or need a closing slash and never has in HTML.

    – Rob
    Nov 13 '18 at 12:52











  • if you only need a checkmark you could use &:checked:after { content:'2713'; } or search any other entity

    – Dirk
    Nov 13 '18 at 12:52



















You can use both :before and :after. Check out this one I made a few years ago codepen.io/phiter/pen/KvVPBr

– Phiter
Nov 13 '18 at 12:46





You can use both :before and :after. Check out this one I made a few years ago codepen.io/phiter/pen/KvVPBr

– Phiter
Nov 13 '18 at 12:46













I need to be stylled like chekcbox, only problem as i sais i have with the checked styling

– Miomir Dancevic
Nov 13 '18 at 12:48





I need to be stylled like chekcbox, only problem as i sais i have with the checked styling

– Miomir Dancevic
Nov 13 '18 at 12:48













If you read trough my CSS you'll understand what you can work with. You can use the before for the base and after for the checked element.

– Phiter
Nov 13 '18 at 12:50





If you read trough my CSS you'll understand what you can work with. You can use the before for the base and after for the checked element.

– Phiter
Nov 13 '18 at 12:50













Note that the <input> tag does not use or need a closing slash and never has in HTML.

– Rob
Nov 13 '18 at 12:52





Note that the <input> tag does not use or need a closing slash and never has in HTML.

– Rob
Nov 13 '18 at 12:52













if you only need a checkmark you could use &:checked:after { content:'2713'; } or search any other entity

– Dirk
Nov 13 '18 at 12:52







if you only need a checkmark you could use &:checked:after { content:'2713'; } or search any other entity

– Dirk
Nov 13 '18 at 12:52














1 Answer
1






active

oldest

votes


















1














if your are looking to add a checkmark to the after, use contentwith a html entity (css encoded)






.checkbox-custom::after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}

.checkbox-custom:checked::after {
content:'2713';
font-size: 20px;
line-height: 1em;
width: 18px;
height: 18px;
color: grey;
text-align:center;
}

<input type="checkbox" class="checkbox-custom">








share|improve this answer


























  • Txanks it is closed, but not check in the middle :(

    – Miomir Dancevic
    Nov 13 '18 at 13:03











  • i know, you could use ::beforewith content to position it better maybe

    – Dirk
    Nov 13 '18 at 13:05











  • O mete, but i dont know how to do that :(

    – Miomir Dancevic
    Nov 13 '18 at 13:05











  • just add text-align: center; to the after, i edited my answer

    – Dirk
    Nov 13 '18 at 13:08











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281304%2fcreating-custom-checkbox-without-after-element%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














if your are looking to add a checkmark to the after, use contentwith a html entity (css encoded)






.checkbox-custom::after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}

.checkbox-custom:checked::after {
content:'2713';
font-size: 20px;
line-height: 1em;
width: 18px;
height: 18px;
color: grey;
text-align:center;
}

<input type="checkbox" class="checkbox-custom">








share|improve this answer


























  • Txanks it is closed, but not check in the middle :(

    – Miomir Dancevic
    Nov 13 '18 at 13:03











  • i know, you could use ::beforewith content to position it better maybe

    – Dirk
    Nov 13 '18 at 13:05











  • O mete, but i dont know how to do that :(

    – Miomir Dancevic
    Nov 13 '18 at 13:05











  • just add text-align: center; to the after, i edited my answer

    – Dirk
    Nov 13 '18 at 13:08
















1














if your are looking to add a checkmark to the after, use contentwith a html entity (css encoded)






.checkbox-custom::after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}

.checkbox-custom:checked::after {
content:'2713';
font-size: 20px;
line-height: 1em;
width: 18px;
height: 18px;
color: grey;
text-align:center;
}

<input type="checkbox" class="checkbox-custom">








share|improve this answer


























  • Txanks it is closed, but not check in the middle :(

    – Miomir Dancevic
    Nov 13 '18 at 13:03











  • i know, you could use ::beforewith content to position it better maybe

    – Dirk
    Nov 13 '18 at 13:05











  • O mete, but i dont know how to do that :(

    – Miomir Dancevic
    Nov 13 '18 at 13:05











  • just add text-align: center; to the after, i edited my answer

    – Dirk
    Nov 13 '18 at 13:08














1












1








1







if your are looking to add a checkmark to the after, use contentwith a html entity (css encoded)






.checkbox-custom::after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}

.checkbox-custom:checked::after {
content:'2713';
font-size: 20px;
line-height: 1em;
width: 18px;
height: 18px;
color: grey;
text-align:center;
}

<input type="checkbox" class="checkbox-custom">








share|improve this answer















if your are looking to add a checkmark to the after, use contentwith a html entity (css encoded)






.checkbox-custom::after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}

.checkbox-custom:checked::after {
content:'2713';
font-size: 20px;
line-height: 1em;
width: 18px;
height: 18px;
color: grey;
text-align:center;
}

<input type="checkbox" class="checkbox-custom">








.checkbox-custom::after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}

.checkbox-custom:checked::after {
content:'2713';
font-size: 20px;
line-height: 1em;
width: 18px;
height: 18px;
color: grey;
text-align:center;
}

<input type="checkbox" class="checkbox-custom">





.checkbox-custom::after {
line-height: 1.5em;
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-top: -4px;
margin-left: -4px;
border: 1px solid grey;
border-radius: 0;
background-color: white;
}

.checkbox-custom:checked::after {
content:'2713';
font-size: 20px;
line-height: 1em;
width: 18px;
height: 18px;
color: grey;
text-align:center;
}

<input type="checkbox" class="checkbox-custom">






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 13:07

























answered Nov 13 '18 at 13:00









DirkDirk

704212




704212













  • Txanks it is closed, but not check in the middle :(

    – Miomir Dancevic
    Nov 13 '18 at 13:03











  • i know, you could use ::beforewith content to position it better maybe

    – Dirk
    Nov 13 '18 at 13:05











  • O mete, but i dont know how to do that :(

    – Miomir Dancevic
    Nov 13 '18 at 13:05











  • just add text-align: center; to the after, i edited my answer

    – Dirk
    Nov 13 '18 at 13:08



















  • Txanks it is closed, but not check in the middle :(

    – Miomir Dancevic
    Nov 13 '18 at 13:03











  • i know, you could use ::beforewith content to position it better maybe

    – Dirk
    Nov 13 '18 at 13:05











  • O mete, but i dont know how to do that :(

    – Miomir Dancevic
    Nov 13 '18 at 13:05











  • just add text-align: center; to the after, i edited my answer

    – Dirk
    Nov 13 '18 at 13:08

















Txanks it is closed, but not check in the middle :(

– Miomir Dancevic
Nov 13 '18 at 13:03





Txanks it is closed, but not check in the middle :(

– Miomir Dancevic
Nov 13 '18 at 13:03













i know, you could use ::beforewith content to position it better maybe

– Dirk
Nov 13 '18 at 13:05





i know, you could use ::beforewith content to position it better maybe

– Dirk
Nov 13 '18 at 13:05













O mete, but i dont know how to do that :(

– Miomir Dancevic
Nov 13 '18 at 13:05





O mete, but i dont know how to do that :(

– Miomir Dancevic
Nov 13 '18 at 13:05













just add text-align: center; to the after, i edited my answer

– Dirk
Nov 13 '18 at 13:08





just add text-align: center; to the after, i edited my answer

– Dirk
Nov 13 '18 at 13:08


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281304%2fcreating-custom-checkbox-without-after-element%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Jo Brand