Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
callum
Helper II
Helper II

Referring to the visual's iframe element from CSS

Hi,

 

Is it possible to do this? For example to set the background of my visual, I've tried the following:

#sandbox-host{
background:black;
}

but it has no effect.

 

Strangely enough, in the visual's TypeScript I can set it with d3 like 

d3.select(this.host).style("background", "black");

so it is possible to style it, just not via pure CSS it seems.

 

Am I doing something wrong?

1 ACCEPTED SOLUTION
v-viig
Community Champion
Community Champion

This issue is related to the fact that PBIVIZ tools encapsulate CSS by including GUID of the visual as a prefix for all of selectors.

Our recommendation is to include an extra DOM element and apply styles to this element.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

View solution in original post

4 REPLIES 4
mehul2010
Frequent Visitor

inside constructor make one HTML element as below:

 

let svg = this.svg = d3.select(options.element).append('svg').classed("svg-content",true);

 

 

inside visual.less file add,

 

.svg-content {
background-color: black;
 
}
callum
Helper II
Helper II

I've just discovered that it's even possible to set it via d3 with 

d3.select("#sandbox-host").style("background", "black");

so it can't be an issue with the syntax or spelling of the selector I'm using...

You can create one svg element or any div element as below:
 
inside constructor:
 
let svg = this.svg = d3.select(options.element).append('svg').classed("svg-content",true);
 
inside visual.less file:
 
.svg-content {
background-color: black;
 
}
 
 
v-viig
Community Champion
Community Champion

This issue is related to the fact that PBIVIZ tools encapsulate CSS by including GUID of the visual as a prefix for all of selectors.

Our recommendation is to include an extra DOM element and apply styles to this element.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.