function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Paul BerglundPaul Berglund 

CSS class does not work inside of an apex:component

I added a CSS class to an apex:component

<head>
    <style>
     .myclass {
      font-size: large;
     }
    </style>
</head>

And then accessed it

<apex:outputText styleClass="myclass" value="some text" />

And nothing happens.  If I use the style tag, it works.  If I put the definition in the apex:page calling the component, it works.  Very strange!
Shashi PatowaryShashi Patowary
Hi Paul,

I was able to make use of CSS in Vf component if I have understood your issue completely -
I created one component (TestComponent ) -
<apex:component>
  <head>
    <style>
     .myclass {
      font-size: 28px;
     }
    </style>
</head>
<apex:outputText styleClass="myclass" value="some text" />
</apex:component>

and then accesed it in a VF page -

<apex:page >
<c:TestComponent />
</apex:page>

The string 'some text' is displayed withh CSS update (28px)

Please let me know if it helps.

Thanks,
Shashi
Shashi PatowaryShashi Patowary
Even this code is working as expected in my dev org -

<apex:page >
<c:TestComponent />
<br/>
<apex:outputText styleClass="myclass" value="test text" />

</apex:page>

Regards,
Shashi
Purnima JothikrishnanPurnima Jothikrishnan

I know its too late to reply now. But it will be helpful for someone who is looking for a solution. 
Please add  layout="none" to your apex component , like this

<apex:component controller="test" layout="none">

Generally the apex component is produced with HTML span tags. So the <style> is no more inside head tag but a span tag, thats the reason it doesnt work. But when you say layout="none" ; this will generate the component without html tags - thus the style tags will be visible and applied on the content.
VIVEK KUMAR 105VIVEK KUMAR 105
layout is not an attribute of component so this doesn't work Purnima Jothikrishnan