我想做成背景透明,中间的container不透明的样子
<p class="back">
<p class="container bs-docs-container">
<p class="col-lg-10" role="main">
{% block content %}
{% endblock %}
</p>
</p>
</p>
css:
.back{
position: absolute;
margin-left: 20px;
margin-right: 20px;
background: url(images/back.png);
background-repeat: no-repeat;
opacity: 0.35;
z-index: 1;
}
网上有说把position设置成absolute,但这样压根不显示了。
用z-index也不行。
用的是flask框架。
求大神解答!!
You can do it with CSS3's
rgba
, but if you want to be compatible with older browsers, useabsolute
for the outer and inner layersIf the questioner has a learning attitude:
This question must first understand the stacking context
And then look at this to understand the opacity
If you want to solve the problem, I I think the following js solution is good
thatsNotYoChild.js — Fixing Parent-Child Opacity
Use rgba or translucent image as background instead of adding opacity
Thank you for your suggestions. Since I have very little exposure to front-end development and I don’t know much about browser compatibility, I haven’t given it much thought yet.
In addition, I wanted to set the background to an image and did not intend to use a processed translucent image, so I ended up writing it like this:
If you have any questions, please let me know.
Two methods. The first one is to use a transparent png image as the background. It has the advantages of good compatibility but the disadvantage of occupying capacity
General method: Use the rgba value for the background attribute and use 0. as the last digit to represent transparency
It is recommended to use RGBA, because there is no problem with mainstream browsers, only IE8 and below will have problems
It should be that the background of the picture should be transparent instead of solid color.
There is no need to create a new p, just set it directly in the :after pseudo-class of the container. An approximate example is as follows:
In which browser is it opaque?
Ie8 and below use filter:(alpha=35) to control transparency
It is unrealistic to set it to absolute. It is probably because your cotainer does not have a height, so it does not expand the height of the parent element
If you want to be compatible, you can only set the position of back: relative;
Then the container's position:absolute, z-index:1;
Create a layer below back to serve as a transparent layer, position:absolute, z-index: 0, opacity: 0.35.
This way
For a fixed window size, you can set both background and content.
position:absolute;top:0;
Use z-index to distinguish the front and rear of the z axis; then the outer frame is fixed in size and position: relative;The background p can be set arbitrarily;