How add Image as background | Community
Skip to main content
sumit5290
New Participant
October 16, 2015
Solved

How add Image as background

  • October 16, 2015
  • 3 replies
  • 3902 views

In the complex component, how to make the image as background image and the text as center align on the background image??

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Lokesh_Shivalingaiah

It should be taken care in your CSS making image as background and text as center aligned for that div

3 replies

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
New Participant
October 16, 2015

It should be taken care in your CSS making image as background and text as center aligned for that div

sumit5290
sumit5290Author
New Participant
October 16, 2015

bsloki wrote...

It should be taken care in your CSS making image as background and text as center aligned for that div

 

<%@include file="/libs/foundation/global.jsp"%>
<%@ page import="com.day.cq.wcm.foundation.Image" %>
<%

    Image image = new Image(resource, "image");

    image.setSelector(".img");

    String text = properties.get("text", "TEXT NA");


%>

    <%= text %>
<%
    image.draw(out);

%>
<%
   image.getDescription().length();
%>

 

 

i m using this code...how to have the css inside it

New Participant
October 16, 2015

The image object has a getSrc() property.  You can switch your code up to utilize it:

<%

    Image image = new Image(resource, "image");

    image.setSelector(".img");

    String text = properties.get("text", "TEXT NA");


%>

    <%= text %>

<div style="background-image: url(<%=image.getSrc() %>);"></div>