Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elements with opacity < 1 not rendering in chrome when not in first column

I have a site that gets divided into multiple columns. Whenever an element is not in the first column and has opacity set to < 1, it doesn't get rendered when its container has both the overflow y and border radius properties.

Shown in this fiddle

css

.main {
    -webkit-column-width: 100px;
    column-width: 100px;
    max-height: 200px;
}

.main > div {
    overflow-y:auto;
    border-radius: 6px;
}
.opac {
    opacity: 0.5;
}

html

<div class="main">
    <div>
        <div class="opac">element 1</div>
    </div>
    <div>
        <div class="opac">element 2</div>
    </div>
    ...
    <div>
        <div class="opac">element 30</div>
    </div>
</div>

I'm using chrome 40.0.2214.94 (64-bit) on OSX 10.10.1. Works in Firefox.

like image 858
David Rice Avatar asked Jan 30 '15 20:01

David Rice


People also ask

Which of the following CSS property sets the opacity level for an element?

The opacity CSS property sets the opacity of an element.

How do you change the font opacity in CSS?

To set the opacity of a background, image, text, or other element, you can use the CSS opacity property. Values for this property range from 0 to 1. If you set the property to 0, the styled element will be completely transparent (ie. invisible).

How do you add black opacity in CSS?

You have to add the following CSS property to achieve the transparency levels. This sets the background-color of an element to black with 50% opacity. The last value in an rgba value is the alpha value. An alpha value of 1 is equal to 100% opacity, and 0.5 (or .

How do I make a transparent container in CSS?

Transparency using RGBA In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) - which specifies the opacity for a color. An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).


2 Answers

That looks like a rendering bug. For now you can mitigate the effect by applying will-change: opacity to the parent elements:

.main > div {
    overflow-y:auto;
    border-radius: 6px;
    will-change: opacity;
}

http://jsfiddle.net/yx1cp9f8/

like image 61
joews Avatar answered Sep 18 '22 15:09

joews


Anther workaround apparently is to set the opacity on the parent element:

<div class="main">
<div class="opac">
    <div >element 1</div>
</div>
<div class="opac">
    <div >element 2</div>
</div>
...
<div class="opac">
    <div >element 30</div>
</div>

Seems to work. (you seem to have forgotten to close your divs, so I did that as well)

like image 40
chris Avatar answered Sep 22 '22 15:09

chris