Style and appearance in EJ2 JavaScript List box control
2 May 20234 minutes to read
To modify the ListBox appearance, you need to override the default CSS of ListBox component. Please find the list of CSS classes and its corresponding section in ListBox component. Also, you have an option to create your own custom theme for the controls using our Theme Studio
.
CSS Class | Purpose of Class | |
---|---|---|
.e-listbox-wrapper | To customize the listbox wrapper | |
.e-list-parent .e-list-item | To customize the listbox list items | |
.e-list-parent .e-list-item:hover | To customize the listbox list items on hover | |
.e-list-parent .e-list-item.e-selected | To customize the listbox selected list item | |
.e-listboxtool-wrapper .e-listbox-tool | To customize the listbox toolbar | |
.e-listboxtool-wrapper .e-listbox-tool .e-btn | To customize the listbox toolbar button | |
.e-listboxtool-wrapper .e-listbox-tool .e-btn .e-btn-icon.e-icons::before | To customize the listbox toolbar icon |
Horizontal ListBox
You can use cssClass property to display the Listbox horizontally.
var data = [
{ text: 'Hennessey Venom', id: 'list-01' },
{ text: 'Bugatti Chiron', id: 'list-02' },
{ text: 'Bugatti Veyron Super Sport', id: 'list-03' },
{ text: 'SSC Ultimate Aero', id: 'list-04' },
{ text: 'Koenigsegg CCR', id: 'list-05' },
{ text: 'McLaren F1', id: 'list-06' },
{ text: 'Aston Martin One- 77', id: 'list-07' },
{ text: 'Jaguar XJ220', id: 'list-08' },
{ text: 'McLaren P1', id: 'list-09' },
{ text: 'Ferrari LaFerrari', id: 'list-10' },
];
// initialize ListBox component
var listObj = new ej.dropdowns.ListBox({
dataSource: data,
cssClass: 'e-horizontal-listbox'
});
listObj.appendTo('#listbox');
<!DOCTYPE html><html lang="en"><head>
<title>Essential JS 2 ListBox</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="styles.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-inputs/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-dropdowns/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-buttons/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container" style="margin:0 auto; width:250px;">
<h4>Select your favorite car:</h4>
<input id="listbox">
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>