修复div

时间:2017-05-12 17:03:40

标签: html css

我的div有背景图片,但不透明度为50%。

现在我有一个孩子的div,我想要它拥有100%不透明度的每个内容。您可以在snipplet标题中看到文本框和按钮的不透明度较低。

任何人都可以帮忙解决这个问题吗?我试图将100%的不透明度应用于孩子,但它不起作用。

/* CSS to be fixed*/

#home_div
{	
	background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Shoppers_on_Dundas%2C_near_Yonge.jpg/1200px-Shoppers_on_Dundas%2C_near_Yonge.jpg");
	opacity: 0.5;
    filter: alpha(opacity=50);
	/*background-color: #0050A0;*/
	background-color: lightgrey;
	padding-top: 200px;
	color: white;
	padding-bottom: 200px;
	height: 100%;
}
#home_div_content
{
	opacity: 1.0;
    filter: alpha(opacity=100);
	text-align: center;

}
	#header
	{
		height: 70px;
		border-bottom: 4px solid lightgrey;
	}
	#header_content
	{
		margin-top: 10px;
		margin-left: 80px;
	}
	.brandmark
	{
		margin-top: -20px;
	}
	.link_to a
	{
		color: #0050A0 !important;
	}
.featured_div
{
	display: none;
}

.featured_close_anchor, .featured_anchor_close
{
	text-align: center;
}
#heading, #tag_line
{
	top: -300px;
  	position:relative;
  	color: #0050A0;
}
#search
{
	border-radius: 0 !important;
	border-color: #0050A0 !important;
	width: 60%;
height: 35px;
padding: 8px 15px;
color: #0050A0;   /* change  color of text to be typed inside search box */
font-size: 13px;
line-height: 20px;
background-color: transparent;
border: 1px solid #ccc;
-webkit-box-shadow: none;
box-shadow: none;
}
.btn-custom {
color: #FFFFFF;            
background-color: #0050A0;   /* change  button color */
border-radius: 0!important;    /* button border radius */
padding: 5px 11px;              /* Button size change*/
margin-top: -3.5px;
border-top: 2px solid #0050A0;
border-bottom: 3px solid #0050A0;
margin-left: -3px;
}

.btn-custom:hover{
background-color:#9AC94B; /* change  button color on hover */
border-radius: 0!important;

}
.left_categories
{
	padding-top: 5px;
	padding-bottom: 5px;
	margin-bottom: 1px;
	border-left: 4px solid #0050A0;

}
.left_categories:hover
{

	border-top: 1px solid lightgrey;
	border-bottom: 1px solid lightgrey;
	border-left: 4px solid #E5002B;
}
.active_category
{
	background-color: #0050A0;
	color: white !important;
	border-left: 4px solid #E5002B;
}
.search_section
{
	margin-top: 30px;
}
a
{
	text-decoration: none !important;
}


.flash_nav
{
	height: 90px;
	border: 0 !important;
	background-color: #283442;
}

.gradient
{
	background: -moz-linear-gradient(left, white 0%, white 45%, #12A8E0 85%, #0050A0 100%);
}

.flash_navbar a
{
	color: black !important;
}

.search_form
{
	width: 70%;
}

.nav_form
{
	border-radius: 0;
	margin-top: 27px;
}

#searchBar
{
	border-color: #0050A0;
}

#searchButton
{
	background-color: #0050A0;
	color: white;
	border: none;
}
<div id="home_div">
  <div class="container" id="home_div_content">
    <h1 id="heading">Find your product!</h1>
    <h4 id="tag_line">Search what you are looking for.</h4>
    <form method="GET" action="/product/search">
      <input type="text" name="product" id="search" placeholder="Enter product name" class="searchTextBox" />
      <button type="submit" id="quick-search" class="btn btn-custom"><span class="glyphicon glyphicon-search custom-glyph-color"></span></button>
    </form>
    <br />
    <a href="#" class="featured_anchor">view <i class="fa fa-chevron-down"></i> featuring</a>
  </div>
</div>

FIDDLE

1 个答案:

答案 0 :(得分:2)

不透明度规则将始终影响子/后代元素,因为它们是父元素的一部分,并且规则表明父元素应该是50%不透明度。

为了解决这个问题,请使用伪元素并将 减少不透明度而不是父元素。

HTML

<div id='outer'>
  <div id='inner'></div>
</div>

CSS

#outer { width: 200px; height: 200px; position: relative; padding: 2em; }
#outer::before { content: ''; position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: red; opacity: .5; z-index: -1; }
#inner { width: 100%; height: 100%; background: blue; }

Fiddle