I'm trying to create a simple little frontend project, and I need to make some text discernible from a background image.
How can I make the background behind the text blur? It's just blurring the container, I'd like to only blur behind the actual text.
My current code for this text:
.center h1 {
font-size: 100px;
font-style: italic;
font-family: 'Montserrat', sans-serif;
background: -webkit-linear-gradient(0deg,rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.25));
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
backdrop-filter: blur(10px);
}
/* added by editor for deomnstration purpose */
body {
background-image: url('https://upload.wikimedia.org/wikipedia/commons/5/5b/St_Mary%27s_Church%2C_Castle_Street_1.jpg');
background-size: cover;
}
.center {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -100%);
text-align: center;
width: max-content;
}
<div class="center">
<h1>GLUSH</h1>
<!-- Added by original poster for better running -->
</div>
This is just ending up like this:
Is there any way to do this? I was working with background-clip earlier...
Just use backdrop-filter and play with the blur and saturate filter to your liking. blur obviosly blurring the background while saturate givin it more "color depth"
h1 {
backdrop-filter: blur(10px) saturate(70%);
}
/* to make the header only as wide as the content and centering it */
h1 {
width: min-content;
padding: 20px;
margin: 0 auto;
}
/* added by editor for deomnstration purpose */
body {
background-image: url('https://upload.wikimedia.org/wikipedia/commons/5/5b/St_Mary%27s_Church%2C_Castle_Street_1.jpg');
background-size: cover;
}
h1 {
font-size: 5em;
}
<h1>GLUSH</h1>
Related
I am making a webpage with header menu,
and content has gradient text somewhere.
I just found out that the text is visible through the header menu, it seems the text somehow makes the header menu transparent.
the text is visible through the menu
supposed to look like:
Is this normal? Is there any other way to make gradient text without affecting other elements?
css of the header and the text looks like this by the way:
#header {
position: sticky;
top: 0;
background-color: black;
height: 100px;
align-items: center;
padding: 10px 10px 10px 10px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
}
.content_right_text {
font-size: 60px;
font-weight: 700;
background: -webkit-linear-gradient(0deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0.2) 10%, #ffffff 50%, #ffffff 100%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
-webkit-box-decoration-break: clone;
}
Try adding a z-index to your header element so that it stays on top even while scrolling as the position is set to sticky.
#header {
position: sticky;
.
.
.
z-index: 1;
}
I have a problem with my icon when on hover. I want to replace my img src during on hover: heres my code so far:
#aks {
width: 0px;
max-height: 0;
transition: max-height 0.15s ease-out;
overflow: hidden;
background: url("https://img.icons8.com/windows/32/000000/like.png") no-repeat;
padding: 50px;
}
#aks:hover {
background: url("https://img.icons8.com/officexs/32/000000/like.png")
no-repeat;
max-height: 500px;
transition: max-height 0.25s ease-in;
}
<img id="aks" src="https://img.icons8.com/windows/32/000000/like.png" />
What I really want to achieve is when hovered on outline heart icon will replace with heart filled icon but during replacing the outline icon it will show/animate from bottom height 0 to full height so it look like it filled the outline icon. here some example: codepen
any alternatives or solutions other than this is highly appreciated.
thanks in advance!
This isn't particularly easy on a CSS-only heart because the sliding animation would have to be applied to three completely distinct elements (the rotated square, plus the two circles).
For the sake of thoroughness, here is an example using a font that includes a heart. For simplicity, I used Webdings but you should use Font Awesome in actual live code.
The summary is your background is a 2x taller gradient that is 50% white and 50% red, and you slide the background from showing the white half to instead showing the red half upon hover. Two important properties of this will currently only work on webkit browsers: text-stroke, which adds the outline to the text -- and background-clip, which clips the non-text portion of the span's background.
span {
background-size: 100% 200%;
background-image: linear-gradient(to bottom, white 50%, red 50%);
color: transparent;
font-family: webdings;
font-size: 200px;
transition: background-position 2s;
-webkit-background-clip: text;
background-clip: text;
-webkit-text-stroke-width: 5px;
-webkit-text-stroke-color: red;
text-stroke-width: 5px;
text-stroke-color: red;
}
span:hover {
background-position: 0 100%;
}
<span>Y</span>
Well if using css is an option for you then, you can take a look at this:
.heart {
background-color: red;
height: 30px;
width: 30px;
transform: rotate(-45deg);
transition: background-color 1s;
}
.heart::before,
.heart::after {
content: '';
background-color: red;
height: 30px;
width: 30px;
border-radius: 50%;
position: absolute;
transition: background-color 1s;
}
.heart::before {
top: -15px;
}
.heart::after {
left: 15px;
}
.heart:hover,
.heart:hover::before,
.heart:hover::after {
background-color: #F5A9AE;
}
body {
display: flex;
height: 100vh;
}
.heart {
margin: auto;
}
<div class="heart"></div>
You can do it with background animation like below:
.heart {
width: 50px;
height:50px;
padding-top:50px;
background:
url("https://img.icons8.com/officexs/32/000000/like.png") bottom padding-box content-box,
linear-gradient(#fff,#fff) bottom padding-box content-box,
url("https://img.icons8.com/windows/32/000000/like.png");
background-size:100% 100%;
background-repeat:no-repeat;
box-sizing:border-box;
transition:0.5s;
}
.heart:hover {
padding-top:0;
}
<div class="heart"></div>
Here's my issue:
I have a mockup from a design company that wants a text block with a 'broken' square border behind some big text that looks like this (description: there is a small white frame behind large text that is broken up by the text, and then a smaller text link below):
Image of an element on client's website,
In the design, the text is displayed accross the white square frame. The way I have implemented it right now is to make the big text's background color gray. Because the current image's background is gray the desired effect is achieved.
What is needed is to achieve that effect (of breaking the white frame) REGARDLESS of the appearance of the image. Because right now, this happens:
the gray background of the text appears like a box in front of the image -- it ought to be transparent
To further illustrate, if I set the background-color of the big text to transparent, the whole frame is shown (the desired effect is a broken frame):
background: transparent #1
More info if it helps:
The white frame element is just a div with a white border.
I am not sure exactly what to search for in this case, if there is an appropriate CSS solution (preferrable) or if I need to use SVG or maybe a PNG? Thank you for any help.
As #Temani Afif pointed out in the comments, it's not one box, but two separate shapes in CSS.
I made an example to illustrate this using flexbox.
.page {
background-color: black;
width: 400px;
height: 400px;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.box-top {
width: 100px;
height: 10px;
border-color: white;
border-width: 2px;
border-style: solid;
border-bottom: none;
}
.box-bottom {
width: 100px;
height: 30px;
border-color: white;
border-width: 2px;
border-style: solid;
border-top: none;
}
.separator {
color: white;
width: 100%;
margin: 5px 0;
padding: 0;
font-size: 40px;
text-align: center;
}
<div class="page">
<div class="box-top"></div>
<p class="separator">
Headline
</p>
<div class="box-bottom"></div>
</div>
You can make a square element with a border and use a mask on it:
body {
margin: 0;
min-height: 100vh;
background: black;
box-sizing: border-box;
padding-top: 1px;
}
h2.fancy {
position: relative;
text-align: center;
color: white;
padding-top: 12px;
}
h2.fancy:before {
content: '';
position: absolute;
left: 50%;
top: 0;
transform: translateX(-50%);
width: 100px;
height: 100px;
border: 5px solid white;
clip-path: polygon(0 0, 100% 0, 100% 10px, 0 10px, 0 40px, 100% 40px, 100% 100%, 0 100%);
}
<h2 class=fancy>I'm a fancy title...</h2>
The advantage of this solution is that you can make it scale easily with what might change on various screen sizes. For example, with the title's font-size:
document.querySelector('input.font-size').addEventListener('input', function(e) {
document.querySelector('h2').style.fontSize = e.target.value + 'px';
})
body {
margin: 0;
min-height: 100vh;
background: url(https://picsum.photos/800) center /cover;
box-sizing: border-box;
padding-top: 1px;
}
.overlay {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,.5);
}
h2.fancy {
z-index: 1;
position: relative;
text-align: center;
color: white;
padding-top: 12px;
}
h2.fancy:before {
content: '';
position: absolute;
left: 50%;
top: 0;
transform: translateX(-50%);
width: 100px;
height: 100px;
display: block;
border: 5px solid white;
clip-path: polygon(0 0, 100% 0, 100% 10px, 0 10px, 0 calc(10px + 1.3em), 100% calc(10px + 1.3em), 100% 100%, 0 100%);
}
input[type=range] {
position: absolute;
bottom: 1rem;
left: 1rem;
z-index: 1;
}
<h2 class=fancy>I'm a fancy title...</h2>
<div class=overlay></div>
<input type=range min=12 max=36 class=font-size>
The disadvantage is that it doesn't work in IE or Edge lower than 18 or in Opera mini. This particular example works in IE 18, though, as it only uses polygon().
I need to find a way to view the image behind a div through the text in the div:
E.g.
I have the font as a web font. Is this possible without having to do image replacement?
One of the ways to accomplish your specification using only CSS is to overlap the two background images perfectly thereby creating a "transparent" effect that you've described. Here's a fiddle: http://jsfiddle.net/v780v1Ln/.
Note: paddings and such alter the dimensions of the element and affect the coordinates that must be set for background images.
HTML:
<div id = "wrapper">
<h1><span>DRD</span></h1>
</div>
CSS:
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
background: #e2e2e2;
}
#wrapper {
position: absolute;
width: 70%;
height: 50%;
top: 25%;
left: 15%;
background: url(http://i58.tinypic.com/2vdieso.jpg)
no-repeat
0 0/500px 362px;
}
#wrapper > h1 {
background-color: #fff;
text-align: center;
position: absolute;
padding: 0 55px 0 25px;
top: 25px;
left: 25px;
}
#wrapper > h1 > span {
font: bold 70px/1 Sans-Serif;
text-transform: uppercase;
background: url(http://i58.tinypic.com/2vdieso.jpg)
no-repeat
-45px -25px/500px 362px;
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
this worked for me and my project. by stacking the images on top of each other I was essentially able to mirror them even when the position of the box may change
background-image: url("background.jpeg");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: cover;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
background-clip: text;
Is it possible to have transparent text on top of a white background with an image behind it, so that the text appears to be the colour of the image behind it.
Here's a JSFiddle of what I started to give you a better understanding of what I mean:
http://jsfiddle.net/g3SfD/
Right now the text is black, but is there a way to make it transparent so that the colour of the text is that of the background image?
HTML:
<div class="image">
<div class="box">
<div class="text">Sample Text</div>
</div>
</div>
CSS:
.text {
color: black;
font-family: Arial;
font-size: 72px;
font-weight: bold;
}
.box {
display: inline-block;
background: white;
padding: 5px 10px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -219px;
margin-top: -47.5px;
}
.image {
background: url('http://www.menucool.com/slider/prod/image-slider-4.jpg') no-repeat;
width: 960px;
height: 420px;
position: relative;
}
Demo
Ok thanks to this example provided by ralph.m, it seems possible using -webkit-background-clip which would only be supported by browsers that can use webkit.
.text {
font-family: Arial;
font-size: 72px;
font-weight: bold;
text-align: center;
background: url('http://www.menucool.com/slider/prod/image-slider-4.jpg') no-repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 200% 200%;
background-position: -200px -50px;
}
Your background size and position may need tweaking to suit.
I guess you're looking for the rgba() function.
It takes 4 parameters, 3 colors channels and one alpha that controls the opacity of the color.