I am trying to recreate this:
But I have not been able to do so. I tried with adding a :before on the img but that doesnt work. How would you go on about making this. It has to be responsive in the way that the background doesnt get bigger than the image.
SEO is not important so background-image or whatever is fine with me too.
WRITTEN IN SCSS - CHANGE IN HTML IS OK
UPDATED CODE TO ROB's ANSWER
This is the code I have so far
.imgbox {
padding: 5%;
position: relative;
height: auto;
.backdrop {
position: relative;
min-width: 100px;
min-height: 100px;
div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
max-width: 100%;
max-height: 100%;
background: rgb(208, 0, 0);
background: linear-gradient(
90deg,
rgba(208, 0, 0, 1) 0%,
rgba(149, 0, 0, 1) 100%
);
}
transform: translateX(-5px) translateY(5px);
}
.img {
width: 100%;
height: auto;
transform: translateX(5px) translateY(-5px);
}
}
<div className="imgbox">
<div className="backdrop">
<div></div>
</div>
<img
className="img"
src={'https://source.unsplash.com/400x250'}
alt="test"
>
</div>
It's simple with a box shadow.
The paddings in the parent are there to prevent it from cropping the shadow.
.imgbox {
padding: 0 0 30px 30px;
}
.imgbox .img {
display: inline-block;
box-shadow: -30px 30px 0 rgb(208, 0, 0);
}
<div class="imgbox">
<img
class="img"
src='https://source.unsplash.com/400x250'
alt="test"
/>
</div>
Very easy to get the gradient with a pseudo-element:
.image-container::after {
content:'';
position: absolute;
z-index:-1;
bottom:-24px;
left:-24px;
width:100%;
height:100%;
background: linear-gradient(red, firebrick);
}
You can change the gradient and offset using background, left and bottom respectively. I'm not sure if there is a second gradient as well, to the top right? If so, you pair this with a ::before to get a second background, and play around the with z-index to get the ordering correct.
Just remember - for an absolute positioned pseudo element to work, you'll need to set position:relative on the parent container, and content:'';
Codepen here.
Is it possible to cover text with blurry image border like in this picture? The problem is that the picture is contained in trapezoid shaped element. I was reading about clip-path and wanted to do the trick with inset box-shadow to get this transparent border effect but it is not working and I have no idea how to workaround this.
clip-path is not that well supported in most browsers (see this resource)
Use a graphic program to create that kind of effect and then stack all your layers together. I used Photoshop, but you can use any other graphic program that can save PNGs with an alpha channel (e.g. GIMP)
Here a step-by-step instruction:
Open your image and unlock background layer by double clicking on the lock in the Layers window. Then add a mask
Add a gradient to your mask
Save your image for Web as PNG-24 or PNG with alpha channel. Make sure Transparency is checked
Now to the code part:
.Header {
position: relative;
max-width: 488px;
height: 200px;
/* just some font stuff */
font: 2.5em sans-serif;
font-weight: bold;
text-transform: uppercase;
}
.Header > div {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.Header-layer1 {
z-index: 1;
}
.Header-layer1 span {
position: absolute;
left: 150px;
top: 50px;
}
.Header-layer2 {
background: url( https://i.stack.imgur.com/f9fIM.png ) no-repeat left top;
z-index: 2;
}
.Header-layer3 {
z-index: 3;
}
.Header-layer3 span {
position: absolute;
left: 175px;
top: 70px;
color: #ede8d7;
text-shadow: 1px 1px 10px rgba( 0, 0, 0, .05 );
}
<div class="Header">
<div class="Header-layer1">
<span>Some</span>
</div>
<div class="Header-layer2">
<!-- we add the background image to this layer with CSS -->
</div>
<div class="Header-layer3">
<span>text here</span>
</div>
</div>
Image credit
I want to add background-color to a div, and on the same div, on the bottom i want background-image. But when background-image begins, I want background-color to stop. Here is a image as example:
Here is an example using pure CSS - no image needed. Only one div is required to achieve this - no need for two!
You can apply whatever background-color you want without having to worry about it not being applied to the image.
Try changing the background-color in the demo!
jsFiddle demo
HTML
<div class="arrow">BUTTON</div>
CSS
.arrow {
position: relative;
background: #000000;
width:100px;
height:50px;
color:white;
}
.arrow:after {
top: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.arrow:after {
border-color: rgba(0, 0, 0, 0);
border-top-color: #000000;
border-width: 10px;
left: 50%;
margin-left: -10px;
}
Use nested divs:
<div class="button">
Text
<div class="arrow">
</div>
</div>
and
.button {
background-color: black;
}
.arrow {
background-image: ...
}
Of course you will have to adjust the positioning of the arrow image in the CSS, too.
Alternatively you could use :after to insert a pseudo element to represent the arrow.
I solved it with CSS, using 2 background images.
I made an illustration to be easier to understand:
background-image: url(http://www.yoursite.com/top_image.png), url(http://www.yoursite.com/bottom_image.png);
background-repeat: repeat-x, no-repeat;
background-position: left top, center top;
So i'm coding my website now, and i'm using two div to create a somewhat gradient in the background, where div#bg1 is grey and div#bg2 is dark grey. But when i'm then adding the wrapper div, bg1 and bg2 still follows the wrapper's top alignement, but it should not. bg1 and bg2 should stay at the top.
heres the html:
<div id="bg1"> </div>
<div id="bg2"> </div>
<div id="wrapper"></div>
and stylesheet:
div#wrapper {
background-color: #FFFFFF;
width: 800px;
height: 1000px;
margin-left:auto;
margin-right:auto;
margin-top: 30px;
position: relative;
z-index:3;
}
div#bg1 {
width: 100%;
margin:0px;
padding:0px;
height: 200px;
background-color: #ccc;
z-index: 2;
position: absolute;
box-shadow: inset 0px 10px 60px 0px rgba(0, 0, 0, 0.6);
}
div#bg2 {
width: 100%;
margin:0px;
padding:0px;
height: 100px;
background-color: #444444;
z-index: 2;
position: absolute;
box-shadow: inset 0px 10px 60px 0px rgba(0, 0, 0, 0.7);
}
i have the code currently on my website here: http://andreassvarholt.com/test/test3/
You have both your BG divs set to an absolute position.
To force them to the top, you need to define the "top" CSS attribute.
div#bg1 {
top: 0;
}
div#bg2 {
top: 0;
}
Furthermore, I must point out that your implementation is inelegant. Just make a 1px by 200px image that tiles as a background image on the body. There's no sense in stacking divs on top of divs just for a simple background effect.
Using divs to creat a background gradient is kind of jenky. Why not just go to one of the many free css3 gradient generators available online. Free and easy.
Good Luck
-brian
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.