Add an overlay pattern (png) over a div - html

Is there a way using HTML to add an overlay using an image url in a specific div?
I managed to make something work using CSS :
#myDiv {
width: 100%;
height: 100%;
background: url(image.jpg) no-repeat;
}
#myDiv:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: transparent url(http://tympanus.net/Tutorials/CSS3FullscreenSlideshow/images/pattern.png) repeat top left;
opacity: .6;
}
But it is a bit tricky. When I tried to do the same for other divs, it did not work. So for instance I have this CSS code for a div :
.hi-icon-wrap img
{
border-radius: 80px;
width: 153px;
height: 153px;
margin:2%;
}
and I want to add an overlay. I am using this script but with no success:
.hi-icon-wrap img:before {
background: transparent url(http://tympanus.net/Tutorials/CSS3FullscreenSlideshow/images/pattern.png) repeat top left;
opacity: .6;
}
and I also tested that :
.hi-icon-wrap img:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: transparent url(http://tympanus.net/Tutorials/CSS3FullscreenSlideshow/images/pattern.png) repeat top left;
opacity: .6;
}
UPD:
HTML script:
<div class="hi-icon-wrap" class="hi-icon-wrap img" style="text-align: center">
<img src="image.png">
</div>

You should use overlay on div element and not on img
#myDiv {
position: relative;
display: inline-block;
border-radius: 80px;
overflow: hidden;
}
#myDiv:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: url(http://tympanus.net/Tutorials/CSS3FullscreenSlideshow/images/pattern.png) repeat top left;
opacity: .8;
}
img {
vertical-align: top;
}
<div id="myDiv">
<img src="http://placehold.it/150x150/D6E7FF/ffffff">
</div>
Edit: You can't use :after or :before on img as you can see here Demo because image elements don't contain text or have descendants, so what you can do is wrap img in div for example and then you get this Demo

Related

Change color of multi-layered image with CSS

I'm trying to create the following functionality:
Have two transparent images layered on top of each other inside of a <div>; one is an object and the other image represents the 'glow' around the object.
On hover, I want the glow to change colors, but I do not want the original object to change colors.
Here's my existing setup:
HTML:
<div id="container">
<div id="constellation">
</div>
<img src="https://storage.googleapis.com/astrology-images/constellations/aquarius-white.png"/>
</div>
CSS:
#container {
position: relative;
background: black;
width: 800px;
height: 250px;
}
#constellation {
position: absolute;
top: 0px;
left: 0px;
width: 250px;
height: 250px;
background-image: url("https://storage.googleapis.com/astrology-images/constellations/aquarius-halo-white.png");
}
#constellation:after {
content: '';
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: #4E6F2E;
mix-blend-mode: multiply;
opacity: 0;
}
#constellation:hover:after {
opacity: 1;
}
I've created an image of a constellation that lives in the <img>; this should always stay white.
In a separate <div> I have an image for the "halo"; this image uses the mix-blend-mode to multiply the image with a color on hover.
Unfortunately, the way I have it now has both images multiplied by the same color, even though they are in different elements! I have a live example here: I have an example here: https://jsfiddle.net/wcL2exa4/105/
How can I get my desired behavior?
The problem is that #constellation:after is positioned above your image. Set a higher z-index for your image and hover trigger on the parent.
#container {
position: relative;
background: black;
width: 800px;
height: 250px;
}
img {
position: relative;
z-index: 2;
}
#constellation {
position: absolute;
top: 0px;
left: 0px;
width: 250px;
height: 250px;
background: url("https://storage.googleapis.com/astrology-images/constellations/aquarius-halo-white.png");
}
#constellation:after {
content: '';
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: red;
mix-blend-mode: multiply;
opacity: 0;
}
#container:hover #constellation:after {
opacity: 1;
}
See example here: https://jsfiddle.net/pcaoyb7s/

Add transparent color overlay over an <img> tag

I want to add a transparent black overlay over an img tag with some text in it, like in the example screenshot below. Ideally only with HTML and CSS.
I have been searching for hours and can't find anything.
I know this could be easily done if the image is used as a background, but this isn't an option for us (SEO reasons).
That shouldn't be so bad. Would something like this work? First some HTML:
#container {
position: relative;
width: 600px;
height: 400px;
}
#someimg {
postion: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#overlay {
position: absolute;
top: 0;
left: 0;
clear: float;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
color: #ffffff;
}
<html>
<body>
<div id="container">
<img id="someimg" src="https://www.w3schools.com/w3images/fjords.jpg"</img>
<div id="overlay">This is some text in an overlay</div>
</div>
</body>
</html>
Mic.com used the following code:
.article-card-8col__overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: -webkit-linear-gradient(top,transparent,rgba(0,0,0,.9));
background: linear-gradient(to bottom,transparent,rgba(0,0,0,.9));
}
I changed it slightly. You could also use their code with on a sibling div element of the image & the parent having position: relative; or use one like mine.
.wrapper {
position: relative;
display: inline-block;
}
.wrapper:after{
content: "";
background: -webkit-linear-gradient(transparent,rgba(0,0,0,.9));
background: linear-gradient(transparent,rgba(0,0,0,.9));
position: absolute;
display: block;
width: 100%;
top: 0;
bottom: 0;
}
<div class="wrapper">
<img src="https://thumbs.mic.com/MTAxZmJlOGIyMSMvYzNOMU1wRTJjMEdyWUZySS1UVjNnMV9LVkZRPS8xMngyNzM6NDk4MHgyODA5LzgwMHg0NTAvZmlsdGVyczpmb3JtYXQoanBlZyk6cXVhbGl0eSg4MCkvaHR0cHM6Ly9zMy5hbWF6b25hd3MuY29tL3BvbGljeW1pYy1pbWFnZXMvanQwY2dmZXZ5aW10aGhqZzBtYXc4cHZxNndrZmdwbmNqNzQzeTB4YmhybWtyOGc0YXYxcHVidWVldzU0OWIwcC5qcGc.jpg" />
</div>

Custom line on a word

I try to put a line on only one word. With changing its size and its position.
Here the result I would like to have:
I tried to use a span with background-image but no success.
https://jsfiddle.net/XZKS/193u9dam/
And other problem, background-image don't work when using local image.
My website arborescence:
_include
css
style.css
js
img
line.png
background-image: url("../img/line.png");
I hope someone could help me, thanks
Try this:
.myWordWithLine {
position: relative;
}
.myWordWithLine::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
z-index: -1;
height: 24px; // your line height
background-color: red; // your line color
}
Method #01:
You can use css linear-gradient() to draw this background:
Steps:
Create background image with linear-gradient().
Adjust its size with css background-size property.
Place it at the bottom position of the element with background-position css property.
Necessary CSS:
.line {
background: linear-gradient(to right, green, green) no-repeat;
background-size: 100% 5px;
background-position: left bottom 5px;
}
h3 {
font-size: 24px;
}
.line {
background: linear-gradient(to right, green, green) no-repeat;
background-size: 100% 5px;
background-position: left bottom 5px;
position: relative;
padding-top: 0;
padding-bottom:0;
}
<h3>MY <span class="line">BLOG</span></h3>
Method #02:
You can use ::before OR ::after pseudo element:
h3 {
font-size: 24px;
}
.line {
position: relative;
}
.line::after {
background: green;
position: absolute;
bottom: 5px;
z-index: -1;
content: '';
left: 0;
right: 0;
height: 5px;
}
<h3>MY <span class="line">BLOG</span></h3>
You can use this
http://codepen.io/B101844/pen/bgLPPb
html
<div class="main">MY
<div class="blog">
BLOG
<div class="underline"></div>
</div>
</div>
Css
.main{
font-size: 30px;
color: #1c3d93;
font-weight: 900;
}
.blog{
display: inline-block;
position: relative;
}
.underline{
position: absolute;
background-color: #91dfcf;
left: 0px;
right: 0px;
bottom: 7px;
z-index: -1;
height: 8px;
}

Keep img at the bottom of page

I know it's redundant question, but answers which I saw are unbelievable. Multiple lines for such easy task? No way.
I want to keep img at the end of page (not at the end of displayed screen - I have this issue now).
current, wrong code:
#footerimg {
position: absolute;
right: 0px;
bottom: 0px;
z-index:-2;
}
I need a situation, when I will not be able to see the image until I scroll at the bottom of page.
I can't believe that there is no such option in CSS like bottom-page:0px
EDIT:
Meet CSS transform property - apply transform: translateY(100%).
See demo below:
#footerimg {
position: absolute;
right: 0px;
bottom: 0px;
z-index:-2;
transform: translateY(100%);
}
<img id="footerimg" src="http://placehold.it/200x200"/>
EDIT:
Looking at the image added to the question, I think you don't need positioning - just put the img as the last element in the html markup.
A possible solution can be this:
.content {
height: 120vh;
}
section {
text-align: right;
}
img {
vertical-align: top;
}
<section class="content"></section>
<section>
<img id="footerimg" src="http://placehold.it/200x200" />
</section>
You need to define positioned relative block-level element at the end of body. This will create new block formatting context and all inside absolute positioned elements will be placed relatively to it.
Look at snippet example:
body {
width: 100%;
}
.blk1 {
display: block;
width: 100%;
height: 500px;
background: orange;
}
.blk2{
display: block;
width: 100%;
height: 300px;
position: relative;
background: #9c9;
}
img.btm {
position: absolute;
bottom: 0;
right: 0;
opacity: 0;
transition: opacity 1s ease;
}
.blk2:hover .btm {
opacity: 1;
}
<div class="blk1">
</div>
<div class="blk2">
<img src="//placehold.it/100/100" class="btm">
</div>
Here is another solution:
body {
width: 100%;
position: relative;
}
.blk1 {
display: block;
width: 100%;
height: 200vh;
background: orange;
}
body:after {
content: "";
display: block;
position: absolute;
bottom: 0;
right: 0;
width: 100px;
height: 100px;
background-image: url('//placehold.it/100/100');
}
<div class="blk1">
</div>
So you can just add position: relative to body css styles
body {
position: relative;
}
and add body:after:
body:after {
content: "";
display: block;
position: absolute;
bottom: 0;
right: 0;
background-image: url('//placehold.it/100/100');
}
Your question is little bit making confusing me you mentioned in your question like that: "when I will not be able to see the image until I scroll at the bottom of page."
Then I think you do not need any effort you need just place image under footer container, when you will go bottom then you will be found at bottom of the page and this is very traditional way no need any tricky code for that.

Possible to nest within &:before using SASS?

Trying to use sass to position a sprite: CodePen Link. I want to have each card show, but I can only get the visa one to show using the &:before method. Can I not nest .visa/.mastercard/.amex in &:before?
<div class="saved_cc_block">
<div class="saved_cc">
<a class="cc_img visa"></a>
</div>
<div class="saved_cc">
<a class="cc_img mastercard"></a>
</div>
</div>
.cc_img {
position: relative;
height: 26px;
left: 9px;
padding-left: 50px;
&:before {
content: "";
position: absolute;
width: 41px;
height: 26px;
top: 50%;
left: 0;
background: url('http://i.imgur.com/3zRD5fn.png') no-repeat;
.visa {
background-position: 0;
}
.mastercard {
background-position: -51px 0;
}
.amex {
background-position: -102px 0;
}
}
}
:before is a pseudo element, you can't nest other elements within it. I think you probably want to structure your css like this:
.cc_img {
position: relative;
height: 26px;
left: 9px;
padding-left: 50px;
&:before {
content: "";
position: absolute;
width: 41px;
height: 26px;
top: 50%;
left: 0;
background: url('http://i.imgur.com/3zRD5fn.png') no-repeat;
}
}
.visa:before {
background-position: 0;
}
.mastercard:before {
background-position: -51px 0;
}
.amex:before {
background-position: -102px 0;
}
No, you can't.
The elements with those class names are children of the cc_img div, not of the generated pseudo-element that appears before it. Psuedo-elements can't have child nodes.
Look at generating the psuedo-element before the link instead of before the div.