Can exchange opacity
for rgba
in the attributes border
, being like this:
.quadrado{
width: 18.5vw;
margin-left: 5vw;
height: 18.5vw;
overflow: hidden;
float: left;
display: inline-block;
box-sizing: border-box;
border-radius: 1vw;
border: 2px solid rgba(0, 0, 0, .9);
}
.quadrado:hover{
transform: scale(1.1);
border-color: rgba(0, 0, 0, .3);
}
And to prevent the transform
affects the child, can place within the other child elements transform
when the :hover
, for example:
.quadrado:hover > * {
transform: scale(.9);
}
The .9
makes up for the .1
augmentation used in scale(1.1)
, that is, in the element .quadrado
is increased +0.1
and the child(s) element(s) is reduced -0.1
Note:
I applied the transition
for the child elements .quadrado > *
to avoid the effect of increases and decreases in child elements
.quadrado, .quadrado > * {
transition: all .2s ease-in-out;
}
First example
Should stay like this:
Note: The image https://i.stack.Imgur.com/Minz1.png is only for testing
#quadrados{
padding-top: 2vw;
overflow: hidden;
width: 100%;
height: 30.5vw;
background:url(https://i.stack.imgur.com/MinZ1.png);
background-position: bottom;
background-size: 100%;
}
.quadrado{
width: 18.5vw;
margin-left: 5vw;
height: 18.5vw;
overflow: hidden;
float: left;
display: inline-block;
box-sizing: border-box;
border-radius: 1vw;
border: 2px solid rgba(0, 0, 0, .9);
}
.quadrado p{
text-align: center;
margin-top: 8.2vw;
opacity: 1;
font-size: 2vw;
}
.quadrado, .quadrado > * {
transition: all .2s ease-in-out;
}
.quadrado:hover{
transform: scale(1.1);
border-color: rgba(0, 0, 0, .3);
}
.quadrado:hover > * {
transform: scale(.9);
}
<section id="quadrados">
<div class="quadrado" id="quadrado1">
<p>O texto altera</p>
</div>
<div class="quadrado" id="quadrado2">
<p>Quero que o texto</p>
</div>
<div class="quadrado" id="quadrado3">
<p>Permaneça</p>
</div>
<div class="quadrado" id="quadrado4">
<p>Inalterado</p>
</div>
</section>
Second example
The effect of transform
still causes some Blur, Apart from the fact that the PA (author of the question) stated that it is necessary opacity
as it is using background images in each frame adding another element
The element . photo will be position: absolute;
and will be related to the parent element, it was also necessary to remove the overflow: hidden;
of .quadrado
, so with this:
.quadrado:hover .foto {
transform: scale(1.1);
opacity: .3;
}
It was necessary to apply the z-index
in the element .quadrado p
so he doesn’t get down:
.quadrado p{
position: relative;
z-index: 101; /*necessário para que fique na frente*/
The opacity
and the transform
are only applied to the element .foto
, follows the full code:
#quadrados{
padding-top: 2vw;
overflow: hidden;
width: 100%;
height: 30.5vw;
background:url(https://i.stack.imgur.com/MinZ1.png);
background-position: bottom;
background-size: 100%;
}
.quadrado{
width: 18.5vw;
margin-left: 5vw;
height: 18.5vw;
float: left;
display: inline-block;
box-sizing: border-box;
position: relative; /*posiciona a imagem dentro do quadrado*/
}
.quadrado p{
position: relative;
z-index: 101; /*necessário para que fique na frente*/
text-align: center;
margin-top: 8.2vw;
opacity: 1;
font-size: 2vw;
}
.quadrado .foto {
position: absolute;
z-index: 100;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 1vw;
border: 2px solid black;
opacity: .9;
transition: all .2s ease-in-out;
background-size: cover; /* a imagem ocupa o elemento todo */
}
.quadrado:hover .foto {
transform: scale(1.1);
opacity: .3;
}
<section id="quadrados">
<div class="quadrado" id="quadrado1">
<p>O texto altera</p>
<div class="foto" style="background-image: url(https://i.stack.imgur.com/xTaZV.jpg);"></div>
</div>
<div class="quadrado" id="quadrado2">
<p>Quero que o texto</p>
<div class="foto" style="background-image: url(https://i.stack.imgur.com/Yo2KL.jpg);"></div>
</div>
<div class="quadrado" id="quadrado3">
<p>Permaneça</p>
<div class="foto" style="background-image: url(https://i.stack.imgur.com/xTaZV.jpg);"></div>
</div>
<div class="quadrado" id="quadrado4">
<p>Inalterado</p>
<div class="foto" style="background-image: url(https://i.stack.imgur.com/Yo2KL.jpg);"></div>
</div>
</section>
Remove all reference
opacity
of the CSS– Sam
the size of the text will increase equally...
– Droopy