I have a visualforce pdf page, and I render different visualforce components depending on a value in my Apex controller:
<apex:page renderAs="pdf" controller="PresupuestoPDFController" showHeader="false" applyHtmlTag="false" applyBodyTag="false" standardStyleSheets="false">
<head>
<style type="text/css">
@page{
background-image:url('{!URLFOR($Resource.fondosPDF, 'Fondo_presupuesto_atelier_2_900x1150.jpg')}');
size: A4;
}
body{
font-family: sans-serif;
}
tr.border-bottom{
height:25px;
font-size:x-small;
}
tr.border-bottom td{
border-bottom:2px solid #867770;
}
.imag{
width: 14%;
text-align: center;
}
.note-line{
border-color:#CFC3BC;
border-width:2px;
}
#price {
color:#CFC3CB
font-weight:600;
}
#detalle-unidad{
/* background-color: #CFC3CB */
}
</style>
</head>
<c:presupuestoPDFTorreIII rendered="{!data.isLeParc3}"/>
<c:presupuestoPDFTorreIV rendered="{!data.isLeParc4}"/>
<c:presupuestoPDFAtelier rendered="{!data.isAtelier}"/>
</apex:page>
You can see, in the @page selector I'm adding a background image. the thing is, I want to add that image only for one of the components, but if I add the styling directly on the component, it doesnt work (adding the style tag and adding the background image). My question is, can I add a condition in my css at the page level? something like
@page{
{!IF(condition, 'background-image:url(imageUrl)', '')};
}
Meaning, if condition is true, set background-image, or if condition is false, add nothing.
data-id
or style classes to the relevant component(s) then use more specific CSS selectors so you only set the background on the required components/HTML elements?