You can change opacity
by rgba
in attributes border
, thus:
.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 transform
from affecting the child, you can put another transform
inside the child elements when :hover
occurs, for example:
.quadrado:hover > * {
transform: scale(.9);
}
The .9
compensates the .1
used in the scale(1.1)
, that is, in the element .quadrado
is increased +0.1
and in the child element (s) is reduced -0.1
Note:
I applied the transition
to the child elements .quadrado > *
to avoid the effect of increases and decreases in the child elements
.quadrado, .quadrado > * {
transition: all .2s ease-in-out;
}
First example
It should look like this:
Note: The link image is test-only
#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 , except that the AP (author of the question) stated that opacity
is required because it is using background images in each frame by adding one
The .photo element will be with position: absolute;
and will be relative to the parent element, it was also necessary to remove overflow: hidden;
from .quadrado
, so with this:
.quadrado:hover .foto {
transform: scale(1.1);
opacity: .3;
}
It was necessary to apply the z-index
to the .quadrado p
element so that it does not fall below:
.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
, it follows the complete 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>