简体   繁体   中英

How to style individual (or all, each) options/items in Html.ListBoxFor?

In HTML, when I have a <select> , I populate it with <option> . Each <option> can accept styles and classes .

With my current project, I'm using Razor Pages with an Html.ListBoxFor . I can use this syntax:

@Html.ListBoxFor(m => m.service,
 new MultiSelectList((List<SelectListItem>)ViewData["services"], "Value", "Text"),
 new { style = "display:block; width:600px; overflow-y:auto", id = "ServiceSelect", size = "3" })

and stylize my ListBox. However, I can't seem to find a way to stylize each individual option; for example, I would really like to add some padding, as the items are very small.

How do I stylize the options inside an Html.ListBox?

One of the best choice and the simplest one is using jQuery Nice Select library. It's simple to set up and easy to use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM