gpt4 book ai didi

css - 单页加载css

转载 作者:行者123 更新时间:2023-11-28 02:28:59 25 4
gpt4 key购买 nike

是否可以通过单页加载来加载 CSS?

我正在为我的 Web 应用程序使用带有 JSF/Primefaces 的单页方法。当我更改单个页面时,我无法加载 CSS。

你有什么想法吗?

编辑:我有一个 index.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<f:view />
<h:head>
<f:facet name="first">
xxx
</f:facet>
</h:head>

<h:body>
<f:facet name="last">
<h:outputStylesheet name="/ressources/css/default.css" />
</f:facet>

<!-- ...etc -->

<p:layout fullPage="true">
<p:layoutUnit position="center">
<h:form id="contentForm">
<ui:include id="spa_content" src="ressources/fragments/#{myBean.currentPage.fragment()}.xhtml" />
</h:form>
</p:layoutUnit>
</p:layout>
</h:body>
</html>

可以看到include for update my single page。 “最后”方面使用我的 default.css

默认.css:

.ui-button-text {
background-color: green;
color : blue;
}

我有一个托管 bean:

@ManagedBean(name = "xxx")
@SessionScoped
public class MyBean extends AbstractSessionBean implements Serializable {

public MyBean() {}

@PostConstruct
private void init() {}

//...etc

}

最后,我有 mySinglePage.css 和一个片段 mySinglePage.xhtml :

我的单页.xhtml :

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<f:facet name="last">
<h:outputStylesheet name="/ressources/css/mySinglePage.css" />
</f:facet>

<p:commandButton value="#{xxx}" action="#{xxx}" update="xxx"/>

</ui:composition>

为了使用 mySinglePage.css,您可以最后看到分面,但它不起作用...

我的单页.css:

.ui-button-text {
background-color: red;
color : yellow;
}

我不知道如何使用 mySinglePage.css

编辑 2:

如果我有这个,它可以工作,但我的同事说它不是单页的:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<f:view />
<h:head>
<f:facet name="first">
xxx
</f:facet>
</h:head>

<h:body>
<f:facet name="last">
<h:outputStylesheet name="/ressources/css/default.css" />
</f:facet>

<!-- ...etc -->

<p:layout fullPage="true">
<p:layoutUnit position="center">
<ui:insert name="contenu">
<ui:include src="/ressources/fragments/mySinglePage.xhtml"
/>
</ui:insert>
</p:layoutUnit>
</p:layout>
</h:body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<h:html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<ui:composition template="../../index.xhtml">
<ui:define name="contenu">

<f:facet name="last">
<h:outputStylesheet name="/ressources/css/mySinglePage.css"
/>
</f:facet>

<p:commandButton value="BLOP"/>

</ui:define>
</ui:composition>
</h:body>
</h:html>

你知道这是不是一个好方法吗?

谢谢。

最佳答案

这更像是一个检查建议,而不是提供解决方案。

我注意到您代码的这一部分以不同的方式拼写资源。

<h:outputStylesheet name="/ressources/css/default.css" />

您的文件夹名为资源吗?这可能是一个非常微妙的变化,但我认为对资源文件夹使用正确的语法可能会解决问题?

关于css - 单页加载css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47798569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com