Text overlay opacity - html

I'm trying to make an overlay on an image in css but I have some problems I don't know how to solve.
Check this image out, this is a mockup in PhotoShop:
but I got this:
As you can see the blockquote and text also have a opacity, this is the only thing I actually need to solve(the blur is not required, would appreciate a good example though)
I also created a codepen, other image, same code
img.header {
width: 100%;
}
div.wrapper {
position: relative;
/* important(so we can absolutely position the description div */
}
div.description {
height: 100%;
position: absolute;
/* absolute position (so we can position it where we want)*/
bottom: 0px;
/* position will be on bottom */
left: 50%;
width: 50%;
/* styling bellow */
background-color: #cddc39;
color: white;
opacity: 0.4;
/* transparency */
filter: alpha(opacity=60);
/* IE transparency */
}
p.description_content {
padding: 10px;
margin: 0px;
font-size: 30px;
}
<div id="praktijk" class="col s12">
<div class="row pad-top">
<div>
<div class='wrapper'>
<!-- image -->
<img class="header" src='https://www.w3schools.com/w3images/fjords.jpg' />
' />
<!-- description div -->
<div class='description'>
<!-- description content -->
<p class='description_content'>
<blockquote>
This is an example quotation that uses the blockquote tag.
</blockquote>
</p>
<!-- end description content -->
</div>
<!-- end description div -->
</div>
</div>
</div>
</div>

img.header { width: 100%;}
div.wrapper {
position: relative;
overflow:hidden;
}
div#imageBlur, div.description {
height: 100%;
position: absolute;
left: 50%;
width: 50%;
}
div#imageBlur {
background-repeat: no-repeat;
background-size: cover;
background-position-y: 8px;
background-position-x: 100%;
-webkit-filter: blur(3px);
filter: blur(3px);
bottom: 8px;
}
div.description {
bottom: 4px;
background-color:rgba(205, 207, 57, 0.4) ;
color: white;
}
p.description_content {font-size: 50px;}
blockquote{
border-left:solid 2px #ffd800;
padding-left:5px;
font-size: 25px;
}
<div id="praktijk" class="col s12">
<div class="row pad-top">
<div>
<div class='wrapper'>
<img class="header" src='https://www.w3schools.com/w3images/fjords.jpg' />
<!-- description div -->
<div id="imageBlur" style="background-image: url(https://www.w3schools.com/w3images/fjords.jpg);"></div>
<div class='description'>
<p class='description_content'>
<blockquote>
This is an example quotation that uses the blockquote tag.
</blockquote>
</p>
</div>
</div>
</div>
</div>
</div>

If you just want to apply the opacity to background, in this case just a background color, I prefer the rgba color.
See this : css color https://www.w3schools.com/cssref/css_colors_legal.asp
for apply this property, you must translate your color from hex to rgb color
Here the page : https://www.webpagefx.com/web-design/hex-to-rgb/
so your wrapper class will just be this:
.div.description{
height: 100%;
position: absolute;
bottom: 0px;
left: 50%;
width: 50%;
background-color: rgb(205,220,57,0.6);
color: white;
}

Sir Farhad Bagherlo got the right one. Just change the overlay's background color to rgb/rgba of the color and tone you want then remove the opacity. That makes it easeir.
Here is a list of colors you may use: https://www.december.com/html/spec/colorrgbadec.html

Oh, I'm sorry, I don't see the blured element
If you want to make only the background blured, you must not put the text inside the background. Instead make 2 div:
First div as the background and filtered blur, then set the position:absolute, fully width and height. Dont forget to set position:relative to the parent;
Second div as the text
I hope this will help

Related

Applying css background behind img icon

I am attempting to apply a css background behind an img icon I am importing into my project. When trying to do so the css background that I have applied completely covers the image. I am attempting to have the image set on top of the background to give it a border look.
I've attempted to adjust the z-index but it had no effect. I also attempted to use add a pseudo class but that does not show the css background color I applied.
How can I achieve this?
Here is some code sample:
img {
height:32px;
width:32px;
z-index: 500;
}
.background {
width:40px;
height:40px;
background: blue;
opacity: 0.08;
border-radius: 8px;
}
<div class="background">
<img src='https://i.ibb.co/GRJGJ2V/sharemoney.png'/>
</div>
<div class="">
<img src='https://i.ibb.co/GRJGJ2V/sharemoney.png'/>
</div>
I am expecting the image to sit in the center of the background: blue; I am attempting to apply.
img {
height:32px;
width:32px;
z-index: 500;
position: absolute;
left: 12px;
top: 12px;
}
.background {
width:40px;
height:40px;
background: blue;
opacity: 0.08;
border-radius: 8px;
position: absolute;
}
<div class="background">
<img src='https://i.ibb.co/GRJGJ2V/sharemoney.png'/>
</div>
<div class="">
<img src='https://i.ibb.co/GRJGJ2V/sharemoney.png'/>
</div>
I just set the position to absolute and set the offsets.

How to Apply Transparent Background Color to Division Without Using Opacity Property

As you know CSS Opacity Property is making transparent background color or image. You can see samples below difference between opacity property, background-color:rgba and blend-mode properties.
div {
display:inline-block;
width:100px;
height:100px;
}
#sample1 {
background-color: rgb(221,51,85);
opacity:0.4;
}
#sample2 {
background-color:rgba(221,51,85,0.4);
}
#sample3 {
background-color:rgb(221,51,85);
}
#sample4 {
background-image: url(https://static.seattletimes.com/wp-content/uploads/2014/11/MattDay_Web-100x100.jpg);
background-color: rgba(221,51,85);
background-blend-mode: multiply;
color:#fff;
}
div h3 {
text-align:center;
}
<div id='sample1'>
<h3>Sample 1</h3>
<p>I'm NOT Original Color</p>
</div>
<div id='sample2'>
<h3>Sample 2</h3>
<p>I'm NOT Original Color</p>
</div>
<div id='sample3'>
<h3>Sample 3</h3>
<p>I'm Original Color</p>
</div>
<div id='sample4'>
<h4>Sample 4</h4>
<p>I'm Original Color</p>
</div>
In first sample opacity applies all elements in the div.
In second sample opacity only applies background color.
In third sample, using the original color in background color.
In fourth sample, blend-mode applies background-image not background-color
How can I transparent background without using opacity or rgba and also it shouldn't lost the original color.
Sample transparency usage without losing the original color;
EDIT
I also add a new sample to the snippet sample 4. It uses blend-mode property, I can apply the image only.
I think what you're looking for is the mix-blend-mode property.
You can read more about it and its compatibility with different browsers in this page. Here's an example (tested on Chrome):
div {
background-color: #d35;
display: inline-block;
width: 150px;
height: 150px;
position: absolute;
top: 20px;
left: 40px;
}
img {
mix-blend-mode: multiply;
}
<div></div>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcThfH4SD1Kod8gzTIO0WtldPqlDacHt2NLm5itWUPf7AHdbo9_2Dg" />
.solid {
background-image: url('http://res.cloudinary.com/sayob/image/upload/v1511882466/cat300x200_dq2ewf.jpg');
background-repeat: no-repeat;
width: 637px;
height: 306px;
z-index:1;
}
.transparent {
background-image: url('http://res.cloudinary.com/sayob/image/upload/v1527678168/Untitled3_vsdneg.png');
background-repeat: no-repeat;
width: 100px;
height: 100px;
position: absolute;
top: 40px;
left: 90px;
}
<div class="solid">
<div class="transparent"></div>
</div>

Horizontally and Vertically Center TextBox on Image

I'm trying to make one blog design, and I want to display text on image that is vertically and horizontally centered. My CSS class .featured-article have relative position. This is HTML and CSS:
<div class="featured-article">
<img src="images/Image.png" alt="Image"> <!-- This Works Perfect, I don't need to touch it anymore -->
<div class="article">
<img src="uploads/4.png" alt="Image"> <!-- Image where I need to add TextBox -->
<div class="title"> <!-- TextBox that I need to center on image -->
<span><strong>TEXT</strong> TEXT</span>
</div>
.......... Other Eelements
.......... Other Eelements
.......... Other Elements
CSS:
.featured-article { /* Container of Post */
position: relative;
margin-top: 60px;
}
.featured-article > img { /* Background Image, This Works Perfect */
position: absolute;
top: -150px;
left: 20px;
z-index: -1;
}
.featured-article > .article > img { /* Image where I need to add TextBox */
width: 100%;
}
.featured-article > .article > .title > span { /* TextBox that I need to center on image */
background-color: #9ED7D8;
padding: 25px 35px 25px 35px;
text-transform: uppercase;
max-width: 800px;
font-size: 30px;
font-weight: 300;
color: #FFF;
}
This should look like this: Example.
you can use css attribute background-image for your parent element, and inside that put your text in the child element.
after that there are many ways of positioning the child in the center of parent element...
one way would be like this:
html:
<div class="parent">
<div class="child">
your text
</div>
</div>
and css:
.parent{
background-image: url("images/Image.png");
height:...;
width:...;
}
.child{
position: absolute;
top: ....;
width: 100%;
text-align: center;
}

CSS Float Bottom of Image

Trying to float a box on the bottom of this image slider. Essentially the slider will have a title and caption but I also want to have a box at the bottom of the image which will pull in data using PHP.
Anyway, my problem is trying to get the white box with text to sit on the bottom of the image and stay there. If the user decreases screen size the white box should follow and stay on the bottom.
jsFiddle provided: http://jsfiddle.net/fkpe1py6/1/
<div id="homepage-slider-wrap" class="clr flexslider-container">
<div id="homepage-slider" class="flexslider">
<ul class="slides clr">
<li class="homepage-slider-slide">
<div class="homepage-slide-inner container">
<div class="homepage-slide-content">
<div class="homepage-slide-box">Float this box at the bottom of the image.</div>
</div>
<!-- .homepage-slider-content -->
</div>
<img src="http://wpexplorer-demos.com/elegant/wp-content/uploads/sites/83/2012/08/game.jpg" alt="">
</li>
</ul>
<!-- .slides -->
</div>
<!-- .flexslider -->
</div>
<!-- #homepage-slider" -->
CSS (see jsFiddle for full CSS)
.homepage-slide-box {
float:left;
bottom: 0;
margin-top: 10px;
background: #31c68b;
font-size: 1.333em;
font-weight: 600;
color: #212121;
padding: 10px;
background: #fff;
}
Thanks for your help!
I would change a couple of things:
I would place the img tag inside the .homepage-slide-content class div (this will help the div to know the height of the image).
then add some things to your CSS so that your other slide divs mimic this height.
CSS
.homepage-slider-slide{
display:block;
position:relative;
}
.homepage-slider-slide img{
display:block;
}
.homepage-slide-inner {
position: relative;
height:100%;
width:100%;
}
.homepage-slide-content {
display: block;
position: absolute;
top: 0;
left: 0;
bottom:0;
z-index: 9999;
}
.homepage-slide-box {
position:absolute;
bottom: 0;
background: #31c68b;
font-size: 1.333em;
font-weight: 600;
color: #212121;
padding: 10px;
background: #fff;
width: 350px;
}
JS FIDDLE DEMO
remove this css positioning
.homepage-slide-inner {
position: relative;
}
and add this
.homepage-slider-slide {
position: relative;
}
and change position of top: 50px to .homepage-slide-content {bottom : 0}
jFiddle

How to apply an opacity without affecting a child element with html/css?

I want to achieve this using html and css:
I have tried to set the opacity of the container to 0.3 and the box to 1, but it doesn't work: both divs have 0.3 opacity.
jsFiddle of my try here
The effect I am trying to achive is a popup box that comes on top of the page. It is highlighted by fading the content below (by lowering the opacity).
You can use opacity in combination with background color, like this:
#container {
border: solid gold 1px;
width: 400px;
height: 200px;
background:rgba(56,255,255,0.1);
}
#box {
border: solid silver 1px;
margin: 10px;
width: 300px;
height: 100px;
background:rgba(205,206,255,0.1);
}
<div id="container">
containter text
<div id="box">
box text
</div>
</div>
​Live demo
As far as I know you can't do it in a simple way. There a couple of options here:
Use absolute positioning to position box "inside" the container.
#container {
opacity: 0.3;
background-color: #777788;
position: absolute;
top: 100px;
left: 100px;
height: 150px;
width: 300px;
}
#box {
opacity: 1;
background-color: #ffffff;
position: absolute;
top: 110px;
left: 110px;
height: 130px;
width: 270px;
}
<div id="container"></div>
<div id="box">
<p>Something in here</p>
</div>
Use Javascript - almost the same as above, but position and size don't have to be hardcoded.
You can't apply an opacity property without affecting a child element!
"Opacity applies to the element as a whole, including its contents, even though the value is not inherited by child elements. Thus, the element and its children all have the same opacity relative to the element's background, even if they have different opacities relative to one another... If you do not want to apply opacity to child elements, use the background property instead." https://developer.mozilla.org/en-US/docs/Web/CSS/opacity
If you want the opacity to be applied only to the background, without affecting the child elements, use:
background-color: rgba(255, 255, 255, .3)
However, you can achieve the desired effect if you place them inside a div parent element and use CSS position property:
.parent {
border: solid green 3px;
position: relative;
width: 400px;
height: 200px;
}
.sibling-one {
border: solid red 3px;
position: absolute;
box-sizing: border-box;
width: 400px;
height: 200px;
opacity: .3;
}
.sibling-two {
border: solid blue 1px;
margin: 10px;
width: 200px;
height: 100px;
position: absolute;
transform: translateY(50%);
}
<div class="parent">
<div class="sibling-one">
<p>A sibling's one element</p>
</div>
<div class="sibling-two">
<p>A sibling's two element</p>
</div>
</div>
Try using rgba as a 'pre content' overlay to your image, its a good way to keep things responsive and for none of the other elements to be effected.
header #inner_header_post_thumb {
background-position: center;
background-size: cover;
position: relative;
background-image: url(https://images.pexels.com/photos/730480/pexels-photo-730480.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb);
border-bottom: 4px solid #222;
}
header #inner_header_post_thumb .dark_overlay {
position: relative;
left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.75);
}
header #inner_header_post_thumb .dark_overlay .container .header-txt {
padding-top: 220px;
padding-bottom: 220px;
color: #ffffff;
text-align:center;
}
header #inner_header_post_thumb .dark_overlay .container .header-txt h1 {
font-size: 40px;
color: #ffffff;
}
header #inner_header_post_thumb .dark_overlay .container .header-txt h3 {
font-size: 24px;
color: #ffffff;
font-weight: 300;
}
header #inner_header_post_thumb .dark_overlay .container .header-txt p {
font-size: 18px;
font-weight: 300;
}
header #inner_header_post_thumb .dark_overlay .container .header-txt p strong {
font-weight: 700;
}
<header>
<div id="inner_header_post_thumb">
<div class="dark_overlay">
<div class="container">
<div class="row header-txt">
<div class="col-xs-12 col-sm-12">
<h1>Title On Dark A Underlay</h1>
<h3>Have a dark background image overlay without affecting other elements</h3>
<p>No longer any need to re-save backgrounds as .png ... <strong>Awesome</strong></p>
</div>
</div>
</div>
</div>
</div>
</header>
See a working codepen here
Using background-color: rgba(#777788, 0.3); instead of opacity could maybe fix the problem.
Apply this css rule
.alpha60 {
/* Fallback for web browsers that doesn't support RGBa */
background: rgb(0, 0, 0);
/* RGBa with 0.6 opacity */
background: rgba(0, 0, 0, 0.6);
/* For IE 5.5 - 7*/
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);
/* For IE 8*/
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000)";
}
In addition to this, you have to declare background: transparent for IE web browsers.
For more details visit the following link:
http://robertnyman.com/2010/01/11/css-background-transparency-without-affecting-child-elements-through-rgba-and-filters/
Any child of an element with opacity set will take on that opacity.
To achieve this style you could use rgba colours and filters for IE for the background, and opacity on the textual elements. So long as the second box isn't a child of one of the text elements, then it won't inherit the opacity.
Another workaround is to simply use an overlay background to create a similar effect.
I personally like a black overlay with about a 65% opacity, but for what you are trying to do you may want to use a white overlay at round 70%.
Create a small (100 x 100 or less) PNG in Photoshop or GIMP that has the color and opacity you want. Then just set that as the background of your light box.
If you create multiple PNGs at different opacities you can easily switch between them with JS or dynamically at load via backend scripting.
It's not technically what you are trying to do, but aesthetically it can give a very similar effect and UX wise accomplishes the same thing. It is also very easy to do, and widely supported across pretty much everything.
Opacity will always inherits by the child element regardless whatever the element in there, there is no workaround up to today have suggested, when the moving of the child element outside the transparency background is not an option like in a popup menu/dialog box creation, use of background with the rgba is the solution.
Here is a input box that i created that i can turn on or off with the class property invisible by javascript
<div id="blackout" class="invisible">
<div id="middlebox">
<p>Enter the field name: </p>
<input type="text" id="fieldvalue" />
<input type="button" value="OK" id="addfname" />
</div>
</div>
CSS
#blackout {
z-index: 9999;
background: rgba(200, 200, 200, 0.6);
height: 100%;
width: 100%;
display: block;
padding: 0px;
clear: both;
float: left;
position: absolute;
margin-top: -10px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: -10px;
}
#blackout #middlebox {
border: thick solid #333;
margin: 0px;
height: 150px;
width: 300px;
background-color: #FFF;
top: 50%;
left: 50%;
position: absolute;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
padding: 10px 50px 0px 50px;
}
#middlebox p {
float: left;
width:100%;
clear:both;
}
#middlebox input {
clear:both;
margin-bottom:10px;
}
#middlebox input[type=text]{
width:100%;
}
#middlebox input[type=button]{
float:right;
width:30%;
}
.invisible{
visibility:hidden !important;
}
Use such elements that you can add :before or :after. My solution
<div class="container">
<div>
Inside of container element is not effected by opacity.
</div>
</div>
Css.
.container{
position: relative;
}
.container::before{
content: '';
height: 100%;
width: 100%;
position: absolute;
background-color: #000000;
opacity: .25
}
This might not be the most orthodox method but you can use a small semi-transparent background image for each div / container that repeats. It does seem that in this day and age you should be able to achieve this in pure (simple not hackish) css with no js but as the answers above show it isn't that straight forward...
Using a tiled image might seem dated but will work no worries across all browsers.
You can add a container's sibling absolutely positioned behind container, with the same size, and apply opacity to it.
And use no background on your container.
Now container's children have no opaque parent and the problem vanishes.