I want to add blur behind text up to some amount of padding. I don't want some div behind and blur the div, I want it to be bound to the text.
Here is my attempt:
.container {
width: 400px;
height: 200px;
position: relative;
overflow: hidden;
}
.image {
z-index: -1;
object-fit: cover;
}
.text {
z-index: 2;
position: absolute;
width: auto;
bottom: 24px;
left: 24px;
font-size: 36px;
}
.text::before {
content: "";
position: absolute;
z-index: 1;
top: -5px;
bottom: -5px;
left: -15px;
right: -15px;
background-color: red;
opacity: 0.4;
filter: blur(10px);
}
<div class="container">
<img class="image" src="https://source.unsplash.com/random" />
<h1 class="text">Example Text</h1>
</div>
I am getting like this:
I want the edges to be not blurred.
I want something like below:
You can consider overflow:hidden to stop the blur effect and have a sharpe edge. I also considered padding instead of adjusting top/left/right/bottom:
.container {
width: 400px;
height: 200px;
position: relative;
overflow: hidden;
}
.text {
z-index: 1;
position: absolute;
width: auto;
bottom: 24px;
left: 24px;
font-size: 36px;
padding: 12px 22px; /*added this*/
overflow: hidden; /*added this*/
}
.text::before {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: red;
opacity: 0.4;
filter: blur(10px);
}
<div class="container">
<h1 class="text">Example Text</h1>
</div>
Related
I can't get this text to position (and center) itself on top of this image overlay I made.
The code of the image and its overlay is:
#post {
box-sizing: border-box;
vertical-align: middle;
display: inline-block;
padding: 9px;
}
#post img {
width: 250px;
height: 250px;
max-width: 250px;
max-height: 250px;
border: 2px solid #fafafa;
}
.overlay {
position: relative;
color: #fff;
}
.overlay:before {
content: "";
z-index: 5;
display: block;
position: absolute;
height: 25%;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.5)
}
<div id="post">
<div class="overlay">
Hello!
<img src="https://cdn.discordapp.com/attachments/766845496593219594/874918388856684574/image0.png" />
</div>
It keeps appearing like this:
An image of Childe from Genshin Impact with an overlay over him, and "Hello!" at the top of the image.
I want the text ("Hello!") to be ON TOP of the overlay, centered and not affected by the overlay. I'd also like to be able to put at least 2 lines of text. How can I do this?
Since you've already created a relative parent (the .overlay), we can wrap the text node, which is currently naked, with a simple span— basically, something which lets us target and position it.
#post {
box-sizing: border-box;
vertical-align: middle;
display: inline-block;
padding: 9px;
}
#post img {
width: 250px;
height: 250px;
max-width: 250px;
max-height: 250px;
border: 2px solid #fafafa;
}
.overlay {
position: relative;
color: #fff;
}
.overlay:before {
content: "";
z-index: 5;
display: block;
position: absolute;
height: 25%;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.5)
}
.overlay .text {
position: absolute;
z-index: 5;
bottom: 22px;
left: 50%;
transform: translateX(-50%);
}
<div id="post">
<div class="overlay">
<span class="text">Hello!</span>
<img src="https://cdn.discordapp.com/attachments/766845496593219594/874918388856684574/image0.png" />
</div>
</div>
jsFiddle
HTML is
<div id="post">
<div class="overlay">
<span class="text">Hello!</span>
<img src="https://cdn.discordapp.com/attachments/766845496593219594/874918388856684574/image0.png"/>
</div>
CSS is
.overlay{
position: relative;
}
.overlay .text{
position: absolute;
left: 200px;
top: 120px;
}
See Position's Approach here
target your text with a span class and add a top element to that with the .overlay and .overlay::before
#post {
box-sizing: border-box;
vertical-align: middle;
display: inline-block;
padding: 9px;
}
#post img {
width: 250px;
height: 250px;
max-width: 250px;
max-height: 250px;
border: 2px solid #fafafa;
}
.overlay {
position: relative;
color: #fff;
}
.overlay:before {
content: "";
z-index: 5;
display: block;
position: absolute;
height: 25%;
bottom: 0;
left: 0;
right: 0;
top: 0;
background: rgba(0, 0, 0, 0.5)
}
.overlay span {
position: absolute;
z-index: 5;
bottom: 22px;
left: 50%;
top: 10%;
transform: translateX(-50%);
}
<div id="post">
<div class="overlay">
<span>Hello!</span>
<img src="https://cdn.discordapp.com/attachments/766845496593219594/874918388856684574/image0.png" />
</div>
</div>
I have a list of images on a page and they are centered in a div 250 px x 175 px. What I want is to have the images increase in size to the div without messing the image's size ratio up, so if the image is 139 x 50 (small banner) it gets wider until it's 250 x 89, and vice versa a 50 x 100 image would scale to be 150x175.
I would prefer to just do it in CSS if possible.
.suppliers-blog-thumbnail .suppliers-overlay {
position: absolute;
top: 0px;
right: 0px;
background-color: #1c1c1c;
bottom: 0px;
left: 0px;
opacity: 0;
filter: alpha(opacity=0);
}
.suppliers-blog-thumbnail:hover .suppliers-overlay {
opacity: 0.4;
}
.suppliers-blog-thumbnail {
position: relative;
text-align: center;
width: 250px;
height: 175px;
}
.suppliers-blog-thumbnail .image_center img {
position: absolute;
margin: auto;
max-height: 175px;
max-width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class="suppliers-blog-thumbnail">
<a target="_blank" class="image_center" href="http://amico-securityproducts.com/lath.htm">
<img src="http://workspace3.joefoster.org/wp-content/uploads/2017/09/7b6442_1488bc59e28f439b89b942afef0f7646-mv2.gif">
<span class="suppliers-overlay"> </span>
</a>
</div>
Say you have:
<div class="wrapper-class">
<img class="image"/>
<img class="image"/>
</div>
You can have the CSS:
.wrapper-class{
width:275px;
height:160px;
}
.wrapper-class .image{
width:100%;
}
The catch here is that when the width takes up the entire div's width, the height is automatically adjusted.
I think this is what you want, img width set to 100% and height to auto.
.suppliers-blog-thumbnail .suppliers-overlay {
position: absolute;
top: 0px;
right: 0px;
background-color: #1c1c1c;
bottom: 0px;
left: 0px;
opacity: 0;
filter: alpha(opacity=0);
}
.suppliers-blog-thumbnail:hover .suppliers-overlay {
opacity: 0.4;
}
.suppliers-blog-thumbnail {
position: relative;
text-align: center;
width: 250px;
height: 175px;
}
.suppliers-blog-thumbnail .image_center img {
height: auto;
width: 100%;
position: absolute;
margin: auto;
max-height: 175px;
max-width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class="suppliers-blog-thumbnail">
<a target="_blank" class="image_center" href="http://amico-securityproducts.com/lath.htm">
<img src="http://workspace3.joefoster.org/wp-content/uploads/2017/09/7b6442_1488bc59e28f439b89b942afef0f7646-mv2.gif">
<span class="suppliers-overlay"> </span>
</a>
</div>
Look my solution for your answer, I hope this is what you mean. If I understand.
Usually for this kind of issues i'm using background-image instead img because of it flexibility.
.suppliers-blog-thumbnail .suppliers-overlay {
position: absolute;
top: 0px;
right: 0px;
background-color: #1c1c1c;
bottom: 0px;
left: 0px;
opacity: 0;
filter: alpha(opacity=0);
}
.suppliers-blog-thumbnail:hover .suppliers-overlay {
opacity: 0.4;
}
.suppliers-blog-thumbnail {
position: relative;
text-align: center;
width: 250px;
height: 175px;
}
.suppliers-blog-thumbnail .image_center img {
position: absolute;
margin: auto;
max-height: 175px;
max-width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.bg-responsive{
width: 100%;
height: 100%;
background-size: 100%;
background-position: center;
background-repeat: no-repeat;
}
<div class="suppliers-blog-thumbnail">
<a target="_blank" class="image_center" href="http://amico-securityproducts.com/lath.htm">
<div class="bg-responsive" style="background-image: url('http://workspace3.joefoster.org/wp-content/uploads/2017/09/7b6442_1488bc59e28f439b89b942afef0f7646-mv2.gif');"></div>
<span class="suppliers-overlay"> </span>
</a>
</div>
Hi I was wondering to get this structure design in css, I want background and text over the background color but the background should be bit away from the opening text. I have attached the design layout
thanks
Quick and dirty:
h1 {
position: relative;
height: 2em;
overflow: hidden;
}
h1:before {
display: block;
background-color: aqua;
content: "";
height: 1em;
width: 100%;
position: absolute;
top: .5em;
left: 5%;
z-index: -1;
transform: skewX(-15deg);
}
<h1>
Your Title Goes Here
</h1>
HTML:
<div id="title">
Your title goes here
</div>
CSS:
#title {
position: absolute;
top: 50px;
left: 50px;
font-size: 40px;
font-family: Arial;
}
#title:after {
position: absolute;
top: 5px;
left: 36px;
content: "";
width: 100%;
height: 100%;
background: cyan;
z-index: -1;
transform: skewX(-10deg);
}
I am attempting to place an image (after) behind a parent image. I've used boxes as example of what I am trying to achieve - the blue box is supposed to be behind the green box but no matter what z-index I use it doesn't seem to work.
.box-wrapper {
position: absolute;
overflow: hidden;
height: 100%;
width: 100%;
top: 0;
z-index: 1;
}
.box {
background-color: green;
position: relative;
display: block;
height: 52px;
width: 72px;
z-index: 53;
top: 2%;
z-index: 2;
}
.box:after {
content: '';
//position: relative;
background-color: blue;
display: block;
height: 50px;
width: 70px;
z-index: -3;
}
<div class="box-wrapper">
<div class="box"></div>
</div>
Remove the z-index of the box and add position:absolute for box:after
.box-wrapper {
position: absolute;
overflow: hidden;
height: 100%;
width: 100%;
top: 0;
z-index: 1;
}
.box {
background-color: green;
position: relative;
display: block;
height: 52px;
width: 72px;
top: 2%;
}
.box:before {
content: '';
position: absolute;
background-color: blue;
height: 50px;
width: 70px;
z-index:-2;
}
jsfiddle
The blue box is supposed to be behind the green box
Just remove all the irrelvant z-index values, then it works perfectly.
.box-wrapper {
position: absolute;
overflow: hidden;
height: 100%;
width: 100%;
top: 0;
}
.box {
background-color: green;
position: relative;
display: block;
height: 52px;
width: 72px;
top: 2%;
color:white;
}
.box:after {
content: '';
position: relative;
background-color: blue;
display: block;
height: 50px;
width: 70px;
z-index: -1;
}
<div class="box-wrapper">
<div class="box">I'm on top</div>
</div>
Here is how I want it to look:
I realize this is an ugly mockup and obviously when I do it for real the proportions will look better, but I am wondering how you would go about doing this with CSS.
fiddle is here http://jsfiddle.net/bU3QS/1/
<div class="header">
</div>
.header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #000;
z-index: 10000;
height: 110px;
overflow: hidden;
}
Use the :after pseudo element:
.header:after {
content: '';
position: absolute;
background: black;
width: 50px;
height: 50px;
z-index: 1;
border-radius: 50%; /* Makes the element circular */
bottom: -25px;
left: 50%;
margin-left: -25px;
}
For this solution, overflow: hidden; has been removed from the .header CSS.
Here's a fiddle: http://jsfiddle.net/t97AX/
Here's another approach, that doesn't rely on the width of the semicircle to center it properly:
.header:after {
content: '';
position: relative;
top: 100%;
display: block;
margin: 0 auto;
background: red;
width: 50px;
height: 25px;
border-radius: 0 0 50px 50px;
}
The fiddle (semicircle red for the sake of clarity): http://jsfiddle.net/x4mdC/
More on :before and :after: http://www.w3.org/TR/CSS2/selector.html#before-and-after
Use :after and border-radius to create the semicircle.
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
background-color: #000;
height: 110px;
}
.header:after {
content: '';
background-color: red;
position: absolute;
display: block;
width: 100px;
top: 110px;
left: 50%;
margin-left: -50px;
height: 50px;
border-radius: 0 0 50px 50px;
}
Demo: http://jsfiddle.net/bU3QS/2/
<div class="header">
<div class="circle">
</div>
</div>
.header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #000;
height: 110px;
}
.circle {
height: 100px;
width: 100px;
border-radius: 100px;
background-color: black;
margin: auto;
position: relative;
top:45px;
}
in action: http://jsfiddle.net/NickWilde/ngcce/