SVG as pseudo background image in React Material UI - css

I use the React Material UI with JSS. I have the following structure:
<footer>
<div className={classes.ContainerWrapper}>
<div className={classes.Container}>
<div>
<div className={classes.Text}>Text</div>
</div>
<Box marginLeft={6} className={classes.ButtonContainer}>
<Button className={classes.Button} variant="contained">
<Link to={...}>Link text</Link>
</Button>
</Box>
</div>
</div>
</footer>
The problem is that I want an SVG absolutely positioned compared to ContainerWrapper, partly behind the Container. My trials till now were:
Using z-index (did not work because of the absolute position)
Using negative z-index (did not work because the whole footer cannot have negative z-index, it has clickable elements)
Putting SVG in the :after pseudo element as a background image.
When I tried the last one, I run into the following obstacles:
This import throws an error:
import image from '../../assets/images/image.svg'; It works perfectly with png, btw.
Finally, I tried to use inline SVG as follows:
backgroundImage: `url("data:image/svg+xml,%3Csvg...")`
The after pseudo part appears in the DOM in the proper size. However, I cannot see the image.
Thanks in advance!

Related

How to use Tailwind background-image in SvelteKit

https://tailwindcss.com/docs/background-image#arbitrary-values
this is how I want to use Tailwind bg-image feature. This does not work using SvelteKit next 160 and Tailwind 3.0.9.
Code:
<script>
import globe from '$assets/bg/bg_globe2.png'
</script>
<div
class={`flex flex-col bg-primary-dark h-64 overflow-hidden bg-no-repeat bg-[right_-14rem_bottom_-10rem] bg-[url('${globe}')]`}
>
//children
</div>
the bg-[right_-14rem_bottom_-10rem] class works without problems, so I assume Tailwind has problem with Svelte file paths?
EDIT:
output from console.log(globe) is src/assets/bg/bg_globe2.png.
❌ Arbitrary values cannot be computed from dynamic values
<div class="bg-{ userThemeColor }"></div>
✅ Use inline styles for truly dynamic or user-defined values
<div style="background-color: { userThemeColor }"></div>
https://v2.tailwindcss.com/docs/just-in-time-mode#arbitrary-value-support
Tailwind needs to find the full text value in your code to be able to generate the utility classes.

How can I style a sub element of a Fluent UI component in React?

I am trying to style an HTML element inside the component from the Fluent UI React library.
What I want to do is put the "On" / "Off" text to the left of the toggle rather than on the left. When I look at my "compiled" code I can see that the component is translated into:
<div>
<label></label>
<div id="target-me">
<button>
<span></span>
</button>
<label></label>
</div>
</div>
I want to add an inline-flex to the target-me div and set flex-flow property to row-reverse in order to get the button element to the right of the label element. The problem is, I can't manage to target the "target-me" div in my code.
How can I achieve this without rewriting a custom component ?
Thanks!
Ok, well I found the answer to my own question so here it is:
<Toggle styles={{ container: { flexFlow: "row-reverse" } }} />
Essentially you can target different parts of the component (root, container, label..) by using the styles property. Use VS Code's Intellisense to find out what elements you can target inside the component and then just give it some regular CSS-in-JS that you want.

Can't find a way to tweak css of the "React Lazy Load Image Component"

I am referring to the React Lazy Load Image Component.
I need to tweak the display attribute of the image I am rendering with this library. But can't seem to find any way.
I tried to wrap the component with a div and use style={{display: 'inline'}}, but it didn't work.
<div className="ui image" style={{ display: 'inline' }}>
<LazyLoadImage
src={src}
effect="blur"
/>
</div>
I am using this portion of code inside a <Card/> component. The default css of the library contains display: inline-block which is making my image have an extra border at the bottom. I don't want it.
P.S.
I am using Semantic UI for my entire project. I want to use whatever style Semantic is providing me. That's why I need to teak the display attribute of this library.

How to add logo to AppBar in Vuetify?

I have a v-app-bar control, and I'm trying to add a logo/image to it.
Is there a standard approach in Veutify for adding a logo to the AppBar?
You can add a v-img component like this:
<v-app-bar color="light-blue lighten-3" app>
<v-img
class="mx-2"
src="https://i.imgur.com/qgGY4tB.png"
max-height="40"
max-width="40"
contain
></v-img>
<v-toolbar-title class="ml-2">
Page title
</v-toolbar-title>
</v-app-bar>
It's important to set a max-height and max-width, otherwise the image will overflow the nav vertically and push over the title horizontally. And also set contain to preserve the aspect ratio
Demo in CodePen
Note: If you're using Nuxt/Webpack, etc, you might need to build the image path with something like this: :src="require('~/assets/logo.png')"
Use v-avatar with a tile property set to true, just like this:
<v-avatar :tile="true">
<img :src="require('#/assets/logo.png')" alt="logo">
</v-avatar>
The full v-app-bar example:
<v-app-bar app light>
<v-app-bar-nav-icon #click.stop="drawer = !drawer"></v-app-bar-nav-icon>
<v-avatar :tile="true">
<img :src="require('#/assets/logo.png')" alt="logo">
</v-avatar>
<v-toolbar-title>Header text</v-toolbar-title>
</v-app-bar>
Yon can juste use the <img> balise from native html to set your logo.
Then you can resize them with width or height property.

CSS not applying when mat-expansion-panel-header is in child component

I have a component that uses MatExpansionPanel to display a list of products.
I'm using some CSS to hide the overflow of the product's description. Please, see this stackblitz for the current looking.
So I'm trying to extract the panel header into a child component and to apply the exact same CSS to it. However, the CSS doesn't seems to be working. Please, see this stackblitz.
Am I doing something wrong there ? Or is it that this Angular Material component is implemented in a way that it shouldn't be split in different components ?
You can wrap your product-panel-header.component between a div with display:flex like this:
html:
<div class="panel-header">
<mat-panel-title>
{{product.noProduit}}
</mat-panel-title>
<mat-panel-description class="product-name">
{{product.designation}}
</mat-panel-description>
<mat-panel-description>
{{product.quantite}}(+{{product.supplement}})
</mat-panel-description>
</div>
css:
.panel-header {
display: flex;
}
see working stackblitz

Resources