You cannot differentiate between one column and three column directly inside the SPFx web parts.
However, you can determine the rendered size of web part inside the SPFx which you can use to optimize the content and CSS of your web part based on the rendered size.
The width
property on the web part class returns the current rendered width of the web part as a number.
Example:
public render(): void {
this.domElement.innerHTML = `
<div class="${ styles.helloWorld }">
<div class="${ styles.container }">
<div class="${ styles.row }">
<div class="${ styles.column }">
<p class="${ styles.description }">Web Part width: ${this.width}</p>
</div>
</div>
</div>
</div>`;
}
You can also detect when the web part width changes by overriding onAfterResize
method like:
protected onAfterResize(newWidth: number) {
console.log(`the new width of the web part is ${newWidth}`);
}
Documentation: Determine the rendered web part size
Additional:
Also, check below Microsoft documentations which might help you with your development going forward:
- Supporting section backgrounds
- Use web parts with the full-width column