您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

用HTML内联外部CSS

用HTML内联外部CSS

您可以尝试CSSBox。只需查看软件包中包含的 ComputeStyles 演示(有关运行该演示的信息,请参阅分发软件包中的 doc / examples / README 文件)。它计算所有样式,并使用相应的内联样式定义创建一个新的HTML文档(以DOM表示)。

来源在 src / org / fit / css@R_295_2419@ / demo / ComputeStyles.java中 ,非常简短。实际上,它使用jStyleParser来完成主要工作,CSS@R_295_2419@为此提供了一个更好的接口。

        //Open the network connection 
        DocumentSource docSource = new DefaultDocumentSource(args[0]);

        //Parse the input document
        DOMSource parser = new DefaultDOMSource(docSource);
        Document doc = parser.parse();

        //Create the CSS analyzer
        DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
        da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
        da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
        da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
        da.getStyleSheets(); //load the author style sheets

        //Compute the styles
        System.err.println("Computing style...");
        da.stylesToDomInherited();

        //Save the output
        PrintStream os = new PrintStream(new FileOutputStream(args[1]));
        Output out = new NormalOutput(doc);
        out.dumpTo(os);
        os.close();

        docSource.close();
CSS 2022/1/1 18:31:11 有466人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶