Search results

Customized CheckBox in ASP.NET Core CheckBox control

20 Apr 2021 / 2 minutes to read

Customize CheckBox Appearance

You can customize the appearance of the CheckBox component using the CSS rules. Define own CSS rules according to your requirement and assign the class name to the cssClass property.

The background and border color of the CheckBox is customized through the custom classes to create primary, success, warning, and danger info type of checkbox.

tagHelper
custom.cs
Copied to clipboard
<ul>
    <li>
        <ejs-checkbox id="primary" checked="true" label="Primary" cssClass="e-primary"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="success" checked="true" label="Success" cssClass="e-success"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="info" checked="true" label="Info" cssClass="e-info"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="warning" checked="true" label="Warning" cssClass="e-warning"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="danger" checked="true" label="Danger" cssClass="e-danger"></ejs-checkbox>
    </li>
</ul>
<style>

    .e-checkbox-wrapper {
        margin-top: 18px;
    }

    li {
        list-style: none;
    }

    .e-checkbox-wrapper.e-primary:hover .e-frame.e-check { /* csslint allow: adjoining-classes */
        background-color: #e03872;
    }

    .e-checkbox-wrapper.e-success .e-frame.e-check,
    .e-checkbox-wrapper.e-success .e-checkbox:focus + .e-frame.e-check { /* csslint allow: adjoining-classes */
        background-color: #689f38;
    }

    .e-checkbox-wrapper.e-success:hover .e-frame.e-check { /* csslint allow: adjoining-classes */
        background-color: #449d44;
    }

    .e-checkbox-wrapper.e-info .e-frame.e-check,
    .e-checkbox-wrapper.e-info .e-checkbox:focus + .e-frame.e-check { /* csslint allow: adjoining-classes */
        background-color: #2196f3;
    }

    .e-checkbox-wrapper.e-info:hover .e-frame.e-check { /* csslint allow: adjoining-classes */
        background-color: #0b7dda;
    }

    .e-checkbox-wrapper.e-warning .e-frame.e-check,
    .e-checkbox-wrapper.e-warning .e-checkbox:focus + .e-frame.e-check { /* csslint allow: adjoining-classes */
        background-color: #ef6c00;
    }

    .e-checkbox-wrapper.e-warning:hover .e-frame.e-check { /* csslint allow: adjoining-classes */
        background-color: #cc5c00;
    }

    .e-checkbox-wrapper.e-danger .e-frame.e-check,
    .e-checkbox-wrapper.e-danger .e-checkbox:focus + .e-frame.e-check { /* csslint allow: adjoining-classes */
        background-color: #d84315;
    }

    .e-checkbox-wrapper.e-danger:hover .e-frame.e-check { /* csslint allow: adjoining-classes */
        background-color: #ba3912;
    }
</style>
Copied to clipboard
public ActionResult Custom()
{
    return View();
}

Customize width and height

The height and width of the CheckBox component can be customized by setting height and width property.

The following section explains about how to customize the height and width of the CheckBox component.

tagHelper
customheight.cs
Copied to clipboard
<ejs-checkbox id="customsize" cssClass="e-customsize" label="Default"></ejs-checkbox>

<style>

.e-checkbox-wrapper {
  margin-top: 30px;
}

.e-customsize.e-checkbox-wrapper .e-frame {
  height: 30px;
  width: 30px;
  padding: 8px 0;
}

.e-customsize.e-checkbox-wrapper .e-check {
    font-size: 20px;
}

.e-customsize.e-checkbox-wrapper .e-ripple-container {
    height: 52px;
    top: -11px;
    width: 47px;
}

.e-customsize.e-checkbox-wrapper .e-label {
    line-height: 30px;
    font-size: 20px;
}

</style>
Copied to clipboard
public ActionResult CustomHeight()
{
    return View();
}

Custom Frame

CheckBox frame can be customized as per the requirement by adding CSS rules.

In the following example, to-do list is displayed with round checkbox by changing border-radius as 100% by adding e-custom class.

tagHelper
customsize.cs
Copied to clipboard
<ul>
    <li>
        <ejs-checkbox id="cbox2" label="Buy Groceries" checked="true" cssClass="e-custom"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="cbox3" label="Pay Rent" checked="true" cssClass="e-custom"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="cbox4" label="Make Dinner" cssClass="e-custom"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="cbox1" label="Finish To-do List Article" cssClass="e-custom"></ejs-checkbox>
    </li>
</ul>

<style>

li {
  list-style: none;
}

.e-checkbox-wrapper {
  margin-top: 18px;
}

.e-custom .e-frame {
  border-radius: 100%;
}

.e-checkicon.e-checkbox-wrapper .e-frame.e-check::before {
    content: '\e77d';
}

.e-checkicon.e-checkbox-wrapper .e-check {
    font-size: 8.5px;
}

.e-checkicon.e-checkbox-wrapper .e-frame.e-check {
    background-color: white;
    border-color: grey;
    color: grey;
}

.e-checkicon.e-checkbox-wrapper:hover .e-frame.e-check {
    background-color: white;
    border-color: grey;
    color: grey;
}

.e-checkicon.e-checkbox-wrapper .e-checkbox:focus + .e-frame.e-check {
    background-color: white;
    border-color: grey;
    box-shadow: none;
    color: grey;
}

</style>
Copied to clipboard
public ActionResult CustomSize()
{
    return View();
}

Custom Check Icon

CheckBox check icon can be customized as per the requirement by adding CSS rules.

In the following example, the check icon can be customized by changing check icon content, background and border color in focus and hovered states by adding e-checkicon class.

tagHelper
customicon.cs
Copied to clipboard
<ul>
    <li>
        <ejs-checkbox id="cbox2" label="Buy Groceries" checked="true" cssClass="e-checkicon"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="cbox3" label="Pay Rent" checked="true" cssClass="e-checkicon"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="cbox4" label="Make Dinner" cssClass="e-checkicon"></ejs-checkbox>
    </li>
    <li>
        <ejs-checkbox id="cbox1" label="Finish To-do List Article" cssClass="e-checkicon"></ejs-checkbox>
    </li>
</ul>

<style>

li {
  list-style: none;
}

.e-checkbox-wrapper {
  margin-top: 18px;
}

.e-checkicon.e-checkbox-wrapper .e-frame.e-check::before {
    content: '\e77d';
}

.e-checkicon.e-checkbox-wrapper .e-check {
    font-size: 8px;
}

.e-checkicon.e-checkbox-wrapper .e-frame.e-check {
    background-color: white;
    border-color: grey;
    color: grey;
}

.e-checkicon.e-checkbox-wrapper:hover .e-frame.e-check {
    background-color: white;
    border-color: grey;
    color: grey;
}

.e-checkicon.e-checkbox-wrapper .e-checkbox:focus + .e-frame.e-check {
    background-color: white;
    border-color: grey;
    box-shadow: none;
    color: grey;
}

.e-checkicon.e-checkbox-wrapper .e-ripple-element {
    background: grey;
}

</style>
Copied to clipboard
public ActionResult CustomIcon()
{
    return View();
}