I'm trying to make opacity on only navigation background, but its applying on all inner divs like logo and nav, but I don't want apply opacity to logo background.
How can i make this possible?
I'm using code like this:
HTML
<div class="navigation">
<div class="logo"> logo image here </div>
<nav> navigation code here </nav>
</div>
Hi please use rgba background which only make background opacity
.outer {
background:rgba(0,0,0,0.5);
}
If your background is color (not image) then you can give color using rgba instead of hash like this: background-color: rgba(200,100,200,0.5) (last number is opacity from 0 to 1)
If you set the opacity of an element, it applies to all the elements it contains. You can give them an opacity as well, but it will be relative between 0 and the parent's opacity, as you can see here:
http://jsfiddle.net/hLw2c/
In other words, it's not possible to do it like this:
<div class="outer">YO<div class="inner">Zippazip</div></div>
.outer {
opacity: 0.5;
background-color: red;
}
.inner {
opacity: 1;
background-color: blue;
}
One possible workaround is to use a pseudo element to fake the background, like this:
http://jsfiddle.net/hLw2c/1/
<div class="outer">YO<div class="inner">Zippazip</div></div>
.outer {
position: relative;
}
.outer:before {
position: absolute;
display: block;
content: "";
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0.3;
background-color: red;
z-index: -1;
}
.inner {
opacity: 1;
background-color: blue;
}
Now, the header itself is fully opaque and doesn't have a background. The background is made by the :before pseudo element. This can be half transparent without affecting the other content of the header, because that content is not inside the pseudo element.
You should save png with opacity background (for example 80%), and change only the background of the needed div. That's all I think!
Example:
div#navigation {background: url('/src/image.png') center center repeat;}
In that case png with opacity works for element background, and all otrher things (texts, etc) are perfectly visible.
Example of image: http://jacekkowalewski.com/images/black85.png
Or add CSS rgba background style:
background:rgba(0,0,0,0.5);
<div class="navigation">
<div class="logo"> logo image here </div>
<nav> navigation code here </nav>
</div>
.navigation{
opacity:0.6;
}
.navigation #logo{
opacity:1.0;
}
Related
I need to place NON-transparent text on an image. This image is defined in the html. (This is so it can be dynamic). I style the transparency with an :after pseudo element. I would like to have text on this image. apprecaited
However, the problem I'm running into is that the text inherits the transparency. All of the other solutions I have found either define the picture in CSS or don't use a picture at all. Any help would be appreciated, thanks!
EDIT: A colored transparency is desired.
<div class="col-md-6" id="red-square-parent">
<%= image_tag 'infos/home/teaching-3.jpg' %>
<div class="centered">Don't Apply Transparency to me!</div>
</div>
#red-square-parent img{
height: 100%;
width: 100%;
object-fit: none;
}
// Overlay
#red-square-parent:after{
content: '';
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
background: rgba($comp-color-red, 0.7);
}
So, the issue is that you're applying transparency to the parent element. Just target the image specifically for transparency:
JSFiddle
#red-square-parent img{
position: relative;
opacity: 0.5;
}
#red-square-parent div{
position: absolute;
bottom: 40px;
color: black;
font-size: 50px;
}
<div class="col-md-6" id="red-square-parent">
<img src="http://i.imgur.com/eTmzQ.jpg"/>
<div class="centered">Don't Apply Transparency to me!</div>
</div>
In order to apply a coloured filter over this image, you will not be applying background-color as this will not change the color of the image at all.
What you instead need to do it a bit complicated, but you must apply a filter to the image.
I would recommend using a tool such as this: CSS Generator - Filter to get the desired color effect you want.
When you have the desired filter, update your code to look something like this (using the code generated from the CSS Generator - Filter site. See my JSFiddle
#red-square-parent img{
position: relative;
opacity: 0.5;
/* Filter */
filter: grayscale(50%) opacity(1) brightness(100%) contrast(100%) hue-rotate(500deg);
-webkit-filter: grayscale(50%) opacity(1) brightness(100%) contrast(100%) hue-rotate(500deg);
}
#red-square-parent div{
position: absolute;
bottom: 40px;
color: black;
font-size: 50px;
}
<div class="col-md-6" id="red-square-parent">
<img src="http://i.imgur.com/eTmzQ.jpg"/>
<div class="centered">Don't Apply Transparency to me!</div>
</div>
Hi i am aware that you can add a greyscale filter on an image, but would it be possible for a white overlay using the filter setting. I have to do it through css without the need for another div, to be absolute positioned over the image, with a white background and opacity setting changed. Just a simple image within a a tag:
<a href="#">
<img src="http://placehold.it/300x200" />
</a>
css is basic
a img{
display:block;
max-width:100%;
height:auto
}
Solution 1:
You may use the :after psuedo-element. For example, add a class of white-out to your <a> element, and then use the following CSS:
a.white-out {
position: relative;
display: inline-block;
}
a.white-out:after {
position: absolute;
content: '';
display: block;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255,255,255,.5);
}
jsFiddle Demo
Solution 2:
Alternatively, you can try setting a white background on your <a> element, and reducing the opacity of the <img /> inside. For example:
a.white-out {
display: inline-block;
background: #fff;
}
a.white-out img {
opacity: 0.2;
}
jsFiddle Demo
I have a strange problem with opacity property in CSS. So, I want a hover effect, image should get transparent green overlay. It seems that opacity is just applying to the overlay color(it turns lighter when you decrease opacity but image under the overlay does not appear). I have also tried to solve the problem with rgba, but no success.
It's a little hard to explain, so here is the fiddle: http://jsfiddle.net/4T3dc/3/
<style>
.col-sm-4 {
padding-top: 20px;
}
.col-sm-4 .img-responsive {
width: 350px;
height: 350px;
cursor: pointer;
}
.col-sm-4 .img-responsive#one-image {
background: url(http://shrani.si/f/e/jm/42FHXzWF/cover.png);
}
.col-sm-4 .img-responsive#one-image:hover {
background: #1abc9c;
opacity: 0.3;
}
</style>
<div class="row">
<div class="col-sm-4">
<div class="img-responsive img-rounded" id="one-image"alt="Responsive image">
</div>
</div>
</div>
Thank you!
You can add the green/opacity hover effect using :after.
Example on JSFiddle.
Make the following changes to your CSS:
.col-sm-4 .img-responsive#one-image {
position: relative;
}
.col-sm-4 .img-responsive#one-image:hover:after {
background: #1abc9c;
opacity: 0.3;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
content:"";
}
What your CSS presently does isn't overlay a colour on the background image - instead, it completely replaces the background image with the colour you specify, and gives it an opacity. One way to achieve what you're suggesting is to use an actual <img> element, and use the background of its container (.col-sm-4 .img-responsive#one-image) to simulate an overlaid colour by changing the image's opacity.
So your HTML would shift slightly to:
<div class="row">
<div class="col-sm-4">
<div class="img-responsive img-rounded" id="one-image" alt="Responsive image">
<img src="http://shrani.si/f/e/jm/42FHXzWF/cover.png">
</div>
</div>
</div>
And your new CSS style definitions would be:
.col-sm-4 .img-responsive#one-image img {
width:100%;
}
.col-sm-4 .img-responsive#one-image {
background:#1abc9c;
}
.col-sm-4 .img-responsive#one-image:hover img {
opacity: 0.7; /* 1 - 0.3, where 0.3 is the desired opacity of the colour overlay */
}
Here's a JSFiddle to demonstrate. Hope this helps! Let me know if you have any questions.
If you are using CSS3 you can use -webkit-filter.
-webkit-filter: hue-rotate(240deg) saturate(0.6);
Like in this Fiddle: http://jsfiddle.net/4T3dc/6/
I am not entirely sure if that's what you want from your description. However, you can use this website to tweak effects to get exactly what you want:
http://html5-demos.appspot.com/static/css/filters/index.html
This is a slightly fiddly question- essentially, I am making a grid of images where a coloured overlay (div) is displayed upon rollover, with a bit of text within that div. This is very similar to this website- http://twoarmsinc.com/work/category/all. To do this with a div instead instead of an image would be easy- you would nest the overlay inside the other div and set width and height to 100%. However, since you can't nest within an image, and the image is responsively changing size, how should I go about this? I'm not sure background-image will work because I am using a responsive grid system (Simple Grid).
Here's a CodePen: http://codepen.io/anon/pen/iIsGm/
html:
<div>
<div class='overlay'></div>
<img src="http://placekitten.com/300/200" alt="thumb">
</div>
css:
.overlay{
width:100%;
height:100%;
background:#333;
position:relative;
z-index:10;
}
Apologies for the ambiguity- any and all help is greatly appreciated!
You will first need to swap .overlay with the img, so it comes second in the stack.
You have some options for the .container div, but you'll need to set a width to set up a grid. I didn't include it in the fiddle, but you will likely want to set img to max-width: 100%; width: auto; height: auto;, so they can resize and keep their aspect ratios when the browser is resized. For .container, you can also use float: left with a set width. I used display: inline-block here to reduce the amount of code.
DEMO
DEMO with multiple divs floating and simple grid
CSS:
.overlay{
background:rgba(0,0,0,0.5);
position:absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
color: white;
opacity: 0;
-webkit-transition: opacity 0.5s;
transition: opacity 0.5s;
}
img {
display: block;
}
.container {
position: relative;
display: inline-block;
}
.container:hover > .overlay {
opacity: 1;
}
HTML:
<div class="container">
<img src="http://placekitten.com/300/200" alt="thumb">
<div class='overlay'>Some text</div>
</div>
I'm sorry if this is a duplicate. I looked through the related posts and couldn't find anything similar to what I'm dealing with.
I have an image that when hovered on, the opacity reduces. I have text in a DIV above the DIV containing the image, which is affected by the opacity setting of the image. The text is suppose to stay solid, while the image becomes transparent. Unfortunately, both elements are becoming transparent on hover. I thought that since the text is considered a parent element, it should not be affected by the opacity setting of the image.
html:
<div class="album large">
<div class="writing">
<h1>blah</h1>
</div>
<div class="opac">
<img src="background/runaways.jpg">
</div>
</div>
CSS:
.album img
{
display:block;
margin: auto;
}
.album.large
{
background-image: url('background/bigblack.jpg');
background-repeat: no-repeat;
background-position: center;
margin-bottom: 50px;
}
.writing
{
position: absolute;
color:red;
left: 50%;
margin-left: -270px;
}
.opac img:hover
{
opacity: .4;
filter:alpha(opacity=40);
}
Solve opacity issue of parent div
Using Pseudo-elements we can get rid of this, Check the link given below for more details.