在悬停时在伪元素之前更改

时间:2019-03-09 14:42:22

标签: html css hover transition box-shadow

因此,在网上阅读后,我设法在图像上创建了嵌入式阴影。

它可以工作,但是我无法在:hover上进行更改。

目前我有:

.shadow {
  position: relative;
  max-width: 100%;
  float: left;
}

.shadow::before {
  border-radius: 100%;
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  box-shadow: inset 3px 3px 8px rgba(0, 0, 0, .6);
  transition: box-shadow .2s ease-in-out;
}

.shadow:hover:before {
  box-shadow: inset 5px 5px 55px rbga(0, 0, 0, .8);
}

.shadow img {
  float: left;
  border-radius: 100%;
  width: 300px;
}
<div class="shadow">
  <img src="https://picsum.photos/300/300?image=1015">
</div>

我已将代码放在这里:https://codepen.io/anon/pen/rRwGmV

我希望你们中的一些人知道该怎么做。

谢谢

2 个答案:

答案 0 :(得分:-1)

如果没有Scanner reader = new Scanner(System.in); System.out.println("Enter a positive number: "); int n = reader.nextInt(); if(n>0){ Thread[] ob = new Thread[n]; for (int i = 0; i < ob.length; i++) { int num = i+1; ob[i] = new Thread(new Runnable() { public void run() { System.out.println("Hello, I am Thread #"+num); } }); ob[i].start(); } }else{ System.out.println("Please Enter A Positive Integer"); } ,您会怎么做?

:before
.shadow img{
  border-radius: 50%;
  box-shadow: 3px 3px 8px rgba(0,0,0,.6);
}

img:hover {
      box-shadow: 5px 5px 5px red;
}

Here is my codepen whith this code

我忘了做某事吗?我该如何改善?

答案 1 :(得分:-1)

.shadow {
	position: relative;
	max-width: 100%;
	float: left;
	}
    
    .shadow::before {
        border-radius: 100%;
		content: "";
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		box-shadow: inset 3px 3px 8px red;
        transition: box-shadow .2s ease-in-out;
	   }

.shadow:hover::before {
    box-shadow: inset 5px 5px 55px green;
}
	   
.shadow img {
	  float: left;
    border-radius: 100%;
    width: 300px;
	} 
<div class="shadow">
  <img src="https://picsum.photos/300/300?image=1015">
</div>