html - Styling individual list items using inline style? -
i'm new html , css, please bear me.
i want change color of individual list item in ordered list, don't want list number change style. need within 1 html-document -- no separate css.
<!doctype html> <html> <head> <meta charset="utf-8"> <title> test-page </title> </head> <body> <h1> html-file </h1> <ol> <li> item 1 </li> <li style="color:blue"> item 2 </li> <li> item 3 </li> </ol> </body> </html>
the thing can think of solve using inline styling, is:
<ol> <li> item 1 </li> <li><p style="color:blue"> item 2 </li> <li> item 3 </li> </ol>
but list items appear separate paragraphs. don't want use font-tag, , want use html5. want short possible, in 1 file, therefore inline styling.
any css rule set on li
element applies list item marker (bullet, number). inconvenient, , css still lacks way style list marker separately.
so approach of using <li><p style="color:blue"> item 2 </li>
workaround need use, when selecting added inner element, need consider consequences. p
element has default top , bottom margin, using it, need remove them here:
<li><p style="color:blue; margin:0"> item 2 </li>
a simpler way use div
instead of p
, since div
semantically emply block-level container element, causes no change in default rendering except content starts on fresh line , content after starts on fresh line, happens here anyway due list markup. so:
<li><div style="color:blue"> item 2</div></li>
instead of div
, can use span
, if there inline (phrase-level) content. div
more flexible, allows elements inner lists, tables, etc.
Comments
Post a Comment