简体   繁体   English

如何使用CSS或JS从子div中删除样式?

[英]How to remove style from child div using css or js?

I have apply opacity using 'rgba' on parent div and i don't want to inherit this effect on child div.. How can i restrict rgba style from child element... i have posted images as well for better assistance. 我已经在父div上使用“ rgba”应用了不透明度,并且我不想在子div上继承此效果。如何限制子元素的rgba样式...我也张贴了图像,以提供更好的帮助。

' http://imgur.com/a/YxipO ' = (actual image of my code) ' http://imgur.com/a/YxipO'= (我的代码的真实图片)

' http://imgur.com/a/7ltDa ' = (what i want to do using css or js) ' http://imgur.com/a/7ltDa'= (我要使用CSS或JS做的事情)

.banner-inner {
background-color: rgba(255,255,255,0.2);
padding: 3%;}

.logo-circle {
width: 15%;
border: 7px solid #fff;
border-radius: 50%;
padding: 16px;}

You may consider following example approach: 您可以考虑以下示例方法:

 .content { height: 200px; width: 200px; position: relative; } .banner-inner { background-color: rgba(0, 0, 0, 0.2); padding: 3%; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; } .logo-circle { width: 1em; border: 7px solid #fff; border-radius: 50%; padding: 1em; z-index: 2; height: 1em; position: absolute; top: 50%; margin-top: -1.5em; left: 50%; margin-left: -1.5em; } 
 <div class="content"> <div class="banner-inner"></div> <div class="logo-circle"></div> </div> 

You could use the same picture (as seen in the background) as background in .logo-circle . 您可以使用与.logo-circle中的背景相同的图片(如背景所示)。 And set the position of the image like this: background-position: center; 然后像这样设置图像的位置: background-position: center;

or: 要么:

Use a wrapper div for .logo-circle with the same size of the image and set overflow: hidden; 为图像的大小与.logo-circle一起使用wrapper div并设置overflow: hidden; . For .logo-circle set a very big shadow, like box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.2); .logo-circle设置一个非常大的阴影,例如box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.2);

For background in circle use RGBA 对于圆形背景使用RGBA

.logo-circle {
  background: rgba(0, 0, 0, 0.2);
  width: 15%;
  border: 7px solid #fff;
  border-radius: 50%;
  padding: 16px;
}

You can use a box shadow, like this 您可以像这样使用阴影

 .content { height: 200px; width: 300px; position: relative; background: url(http://lorempizza.com/500/350/); background-size: cover; } .logo-circle { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 100px; height: 100px; border: 7px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1000px rgba(255,255,255,0.5); /* background: rgba(0,0,0,0.5); uncomment if you want a semi transparent opacity inside circle */ } 
 <div class="content"> <div class="logo-circle"></div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM