body { font-family: ‘Segoe UI’, Tahoma, sans-serif; color: #000; font-size: 10pt;…
- User
body { font-family: ‘Segoe UI’, Tahoma, sans-serif; color: #000; font-size: 10pt; background-image: url(‘bg.png’); background-size: cover; background-repeat: no-repeat; opacity: 0.8; }
I simply want the opacity of the background iamge changed
- Assistant
To change the opacity of the background image only (without affecting the text), you can't use the
opacityproperty on thebodydirectly because it will affect all child elements, including text. Instead, you need to create a pseudo-element or an actual separate element to control the background image's opacity.Here's how you can change the opacity of the background image using a pseudo-element:
body { font-family: 'Segoe UI', Tahoma, sans-serif; color: #000; font-size: 10pt; } body::before { content: ''; background-image: url('bg.png'); background-size: cover; background-repeat: no-repeat; position: absolute; top: 0; right: 0; bottom: 0; left: 0; opacity: 0.8; z-index: -1; }With the above CSS, the
::beforepseudo-element acts as an overlay carrying the background image and is positioned absolutely to cover the entire body. Thez-index: -1;ensures that the pseudo-element stays behind the content of the body.Make sure you're linking to your actual background image in the
url()part and change theopacityvalue to what suits your design.