Div with external stylesheet?

后端 未结 8 1791
灰色年华
灰色年华 2020-12-10 13:19

I have been given an external stylesheet (.css file) that may not altered in any way whatsoever. However I need to apply this stylesheet to a single div and therefore the co

相关标签:
8条回答
  • 2020-12-10 14:14

    If you have access to server-side scripting (eg: PHP), you could create a script that loads the external stylesheet, and appends a class name in front of every entry. Then apply this class to your DIV tag. So, if the CSS includes:

    p { font-size: 12px; }
    

    You'd modify that to:

    .mydiv p { font-size: 12px; }
    

    And format your DIV as

    <div class="mydiv">...</div>
    

    You would then load the script as a stylesheet, rather than the external stylesheet directly.

    <link rel="stylesheet" href="path/to/internal/script.php" />
    
    0 讨论(0)
  • 2020-12-10 14:17

    The IFRAME solution works like this:

    In your main HTML file, you'll have your DIV:

    <div id="myspecialdiv">
        <iframe width="100%" height="100%" frameborder="0" src="divcontent.html"></iframe>
    </div>
    

    Style that as you need it. The divcontent.html file should be a complete HTML file, including the content of the DIV tag, and a LINK using your external stylesheet:

    <html>
        <head>
            <link rel="stylesheet" href="path/to/external/stylesheet.css" />
        </head>
        <body>
            <!-- The contents of your DIV -->
        </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题