How can I style code listings using CSS?

后端 未结 6 1787
生来不讨喜
生来不讨喜 2021-01-29 23:56

I\'d like to display snippets of programming language code, and also HTML code, inside an HTML document using CSS. I want it to be indented and in fixed-width font... I\'m think

6条回答
  •  逝去的感伤
    2021-01-30 00:34

    Sharing an example I use in website, I do use following pre in my stylesheet:

    pre {
        background: #f4f4f4;
        border: 1px solid #ffffd;
        border-left: 3px solid #f36d33;
        color: #666;
        page-break-inside: avoid;
        font-family: monospace;
        font-size: 15px;
        line-height: 1.6;
        margin-bottom: 1.6em;
        max-width: 100%;
        overflow: auto;
        padding: 1em 1.5em;
        display: block;
        word-wrap: break-word;
    }
    

    This gives the following results:

    Disclaimer: In my leisure time, I have spend few hours to update this CSS with a bit extra features like code lines and code Copy button using CSS with JavaScript to my personal use that I like to share. Please use as you like github source code.

提交回复
热议问题