Background image color overlay best practices? #1767
Replies: 5 comments 5 replies
-
The docs don't talk about <div class="bg-fixed ..." style="background-image: url(...)"></div> Edit: forgot that I had an example here using an |
Beta Was this translation helpful? Give feedback.
-
Found a solution:
Usage:
Hopefully there will be some better solution soon. |
Beta Was this translation helpful? Give feedback.
-
Every tutorial and video I've seen uses inline style for Example<div class="grid" style="grid-template-columns: 1fr 300px 2rem;">
Children
</div> When to use inline styles (in my opinion)
Common inline style css
Sure you can build a plugin or add it to Other solutionsWhen you start to duplicate things, you should probably not add it as inline style anymore.
|
Beta Was this translation helpful? Give feedback.
-
Hi! This is how I ended up solving this; <template>
<div
class="flex h-96 bg-cover bg-no-repeat bg-center select-none"
:style="{ backgroundImage: `url(${src})` }"
>
<div class="flex h-full w-full hover:bg-core-secondary hover:bg-opacity-25">
<div class="m-auto invisible sm:visible">
<h3 class="text-2xl text-center text-white">
{{ title }}
</h3>
</div>
</div>
</div>
</template>
<script>
export default {
props: {
src: String,
title: String,
},
}
</script> This will create a parent container, with the background image. Inside, there's a child div that fills up the entire parent, on this child div, you put a Good luck |
Beta Was this translation helpful? Give feedback.
-
Hello! I think it can be solve like this: <div class="w-1/2 relative">
<div class="bg-black rounded-xl opacity-30 w-full h-full absolute" />
<img src="test.png" class="object-cover w-full rounded-xl" alt="" />
</div> |
Beta Was this translation helpful? Give feedback.
-
What's the best practice to show a background image with color overlay using Tailwind CSS?
Beta Was this translation helpful? Give feedback.
All reactions