Text filled with blurred background image - css

I'm trying to create a title that has a glass looking visual which blurs the background image.
I was able to do it but I had to make references to the background image 3 times and it doesn't seem very optimal.
Here is the code I used.
body {
background: blue url("https://images5.alphacoders.com/318/318370.jpg") no-repeat center center fixed;
background-size: cover;
}
.bimage {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url("https://images5.alphacoders.com/318/318370.jpg") no-repeat center center fixed;
filter: blur(10px);
background-size: cover;
}
.title {
position: relative;
width: 100%;
height: 500px;
overflow: hidden;
}
h2 {
font-family: Verdana;
position: absolute;
top: 0;
left: 0;
//display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 500px;
margin: 0;
font-weight: bold;
font-size: 18vw;
text-align: center;
text-transform: uppercase;
mix-blend-mode: screen;
}
.mask {
background: #fff;
}
#h2 {
background: url("https://images5.alphacoders.com/318/318370.jpg") no-repeat center center fixed;
color: rgba(255, 255, 255, 1);
background-size: cover;
mix-blend-mode: multiply;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: rgba(255, 255, 255, 0.4);
text-shadow: 3px 3px 10px black;
}
<div class="title">
<div id="bimage" class="bimage"></div>
<h2 class="mask">MARIO</h2>
<h2 id="h2">MARIO</h2>
</div>
https://codepen.io/marceltoma/pen/zYWGYwp
I wonder if there's a better way to do this.

Looking at your codepen, you can start reusing css in many places.
This is just an example for you to get started:
/* Reusing background properties */
#h2, body, .bimage {
background: url("https://images5.alphacoders.com/318/318370.jpg") no-repeat center center fixed;
background-size: cover;
}
/* Reusing with children selector */
.title, .title * {
width: 100%;
position: absolute;
top: 0;
left: 0;
}
body {
background-color: blue
}
.bimage {
height: 100%;
filter: blur(10px);
}
.title {
position: relative;
height: 500px;
overflow: hidden;
}
h2 {
font-family:Verdana;
//display: flex;
align-items: center;
justify-content: center;
height: 500px;
margin: 0;
font-weight: bold;
font-size: 18vw;
text-align: center;
text-transform: uppercase;
mix-blend-mode: screen;
}
.mask {
background: #fff;
}
#h2 {
color: rgba(255,255,255,1);
mix-blend-mode: multiply;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: rgba(255, 255, 255, 0.4);
text-shadow: 3px 3px 10px black;
}
<div class="title">
<div id="bimage" class="bimage"></div>
<h2 class="mask">MARIO</h2>
<h2 id="h2">MARIO</h2>
</div>
Please give it a try, and keep DRY!

Related

Opacity for only a part of background image - CSS

Do you maybe know how (and if) I can add an opacity for the background image but only to PART of it?
The effect should be like this one: https://i.stack.imgur.com/HYvaU.png.
I have only added the image as a background but I cannot find any solution for this oppacity.
My HTML:
<header>
<img src="images/logo.svg" />
<h1>A history of everything you copy</h1>
<p>
Clipboard allows you to track and organize everything you copy.
Instantly access your clipboard on all your devices.
</p>
</header>
And CSS:
body {
font-family: "Bai Jamjuree", sans-serif;
text-align: center;
}
#media (min-width: 1200px) {
header {
width: 100%;
background-image: url(images/bg-header-desktop.png);
background-size: 100%;
background-repeat: no-repeat;
padding-top: 50px 150px;
}
}
h1 {
color: hsl(210, 10%, 33%);
font-size: 35px;
margin-bottom: 15px;
}
header > p {
color: hsl(201, 11%, 66%);
font-size: 18px;
}
Thank you in advance!
I have tried to use mask-image but it didn't work:
#media (min-width: 1200px) {
header {
width: 100%;
background-image: url(images/bg-header-desktop.png);
mask-image: linear-gradient(180deg, rgba(0, 0, 0, 1), transparent 74%);
background-size: 100%;
background-repeat: no-repeat;
padding-top: 50px 150px;
}
}
Do you have maybe any idea if I can give an opacity only for the bottom part of this background image using CSS?
With more than 1 background, you can put image in 1 and opacity on the other.
You can change 2nd background color as you want. It's opacity value is given by the RGBA background color (here 0.75 in the snippet).
body {
margin: 0;
padding: 0;
}
.wrapper {
position: absolute;
width: 100vw;
height: 50vh;
top: 50%;
transform: translateY(-50%);
font-size: 10em;
font-weight: bold;
font-family: sans-serif;
background: url("https://picsum.photos/id/22/1280/600");
}
.wrapper1 {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
clip-path: inset(50% 0 0 0);
background-color: rgba(255, 255, 255, 0.75);
display: flex;
justify-content: center;
align-items: center;
}
.wrapper2 {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
z-index: 2;
}
<div class="wrapper">
<div class="wrapper1"></div>
<div class="wrapper2">Hello World!</div>
</div>
Look at the snipper in full scree, for this demo I put width 100vw, so in small result is "strange"

Image scrolling on hover

I want to make an image inside div to scroll down on hover. And that part is working.
Also, I need to make that it scroll longer if the image is longer and because of that I was trying to use calc inside of transition, but it is not working.
Here is my code:
.preview {
position: relative;
width: 75%;
height: 90vh;
overflow: hidden;
border: 1px solid red;
background-color: transparent;
}
.previewimg {
width: 100%;
height: 100%;
top: 0;
background-image: url(https://www.n2odesigns.com/wp-
content/uploads/Projema-Website-Preview-2016.jpg);
background-repeat: no-repeat;
background-size: 100% auto;
background-position-y: 0;
transition: all calc(0.02s * height) ease-in-out;
}
.previewimg:hover {
background-position-y: 100%;
height: 100%;
transition: all calc(0.02s * height) ease-in-out;
}
<div class="preview">
<div class="previewimg"></div>
</div>
If there is some other better way to do this I can use it too.
Ok to do this you need it to be an image only not a background image, to do this transition duration based on height functionality, please use the below code.
$('.previewimg').css("transition", "transform " + 0.02 * $('.previewimg').height() + "s ease");
.preview {
position: relative;
width: 75%;
height: 300px;
overflow: hidden;
border: 1px solid red;
background-color: transparent;
}
.preview .previewimg {
width: 100%;
height: auto;
transform: translateY(0px);
}
.preview:hover .previewimg {
transform: translateY(calc(-100% + 300px));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="preview">
<img class="previewimg" src="https://www.n2odesigns.com/wp-content/uploads/Projema-Website-Preview-2016.jpg"/>
</div>
If you are accepting JS as a solution then here is a code you can add without changing your HTML/CSS structure :
function getHeight(url) {
console.log(url);
var img = new Image();
img.src = url;
return 0.002*parseInt(img.height);
}
var e =$(".previewimg");
var tr = "all "+getHeight(e.css("background-image").replace(/^url\(['"](.+)['"]\)/, '$1'))+"s ease-in-out";
console.log(tr);
e.css('transition',tr);
.preview {
position: relative;
width: 75%;
height: 90vh;
overflow: hidden;
border: 1px solid red;
background-color: transparent;
}
.previewimg {
width: 100%;
height: 100%;
top: 0;
background-image: url(https://www.n2odesigns.com/wp-content/uploads/Projema-Website-Preview-2016.jpg);
background-repeat: no-repeat;
background-size: 100% auto;
background-position-y: 0;
}
.previewimg:hover {
background-position-y: 100%;
height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="preview">
<div class="previewimg"></div>
</div>
You don't actually use javascript for it.
it's codepen : codepen.io or it's the css code for you code:
.preview {
width:300px;
height:300px;
overflow: hidden;
}
.previewimg{
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-size: cover;
background-image: url(https://source.unsplash.com/500x1500/);
transition: background-position 2s ease-out;
}
.preview:hover .previewimg{
background-position: 0 100%;
}
you can add other body elements with the styles classes name. And it make a boxes that when we hover the logo is changed. The logo is changes on hover.
*{
box-sizing: border-box;
}
.logoses{
text-align: center;
list-style: none;
}
.logoses .logo{
width: 178px;
height: 75px;
background:
url('G:/touqeer/amp-landing-pages/assets/images/clients_logo.png') center top no-repeat;
margin: 0 2px 8px;
border: 1px solid #e0e0e0;
display: inline-block;
vertical-align: middle;
transition: all .4s ease-in;
}
#amara{
background-position: 5px -125px;
}
#amara:hover{
background-position: 5px 0px;
}
#ge{
background-position: -1486px -125px;
}
#ge:hover{
background-position: -1486px -2px;
}
#nuance{
background-position: -489px -124px;
}
#nuance:hover{
background-position: -489px -1px;
}
#gilson{
background-position: -329px -123px;
}
#gilson:hover{
background-position: -329px 0px;
}
#pcs_wireless{
background-position: -824px -125px;
}
#pcs_wireless:hover{
background-position: -824px -2px;
}
#herbalife{
background-position: -161px -123px;
}
#herbalife:hover{
background-position:-161px 0px;
}
#pcf{
background-position: -659px -125px;
}
#pcf:hover{
background-position: -659px -2px;
}
#seimens{
background-position: -991px -125px;
}
#seimens:hover{
background-position:-991px -2px;
}
#melesta_games{
background-position: -1156px -124px;
}
#melesta_games:hover{
background-position: -1156px 1px;
}
#samsung{
background-position: -1324px -123px;
}
#samsung:hover{
background-position: -1324px 0px;
}
.center_pd{
padding: 75px 0px;
}
.text_bottom{
margin: 0px 0px 60px 0px;
}
.center_text{
text-align: center;
}
.header{
margin: 0px 0px 20px 0px;
}
h2{
font-size: 30px ;
font-weight: 400;
color: #393939;
}
.prg{
font-size: 16px;
color: #333;
font-family: Open Sans;
}

Is it possible to have smooth gradient border colors with a 50px border radius? [duplicate]

This is what it should look like:
Attempts so far:
Using a gradient background plus an inner element to cover it and leave just an outer "border". The background is obviously not transparent.
body {
background: #242424;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
color: #FFFFFF;
}
div {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
align-items: center;
width: 100%;
height: 100vh;
}
h1 {
margin: 2em;
text-align: center;
}
a {
cursor: pointer;
transition: ease-in-out,.2s,color;
}
a:hover {
color: #DDD;
}
.nested {
display: block;
max-width: 20em;
padding: 2px;
overflow: hidden;
border-radius: 2em;
background: linear-gradient(to right, #00ff00 0%, #00e5ff 100%);
}
.nested span {
display: inline-block;
padding: 1em;
text-align: center;
background: #242424;
border-radius: 2rem;
}
.nested span p {
padding: 0 2em;
margin: 0;
}
.pseudo {
display: block;
margin-top: 20px;
position: relative;
border-radius: 2em;
padding: 1em 2em;
background: #242424;
}
.pseudo:after {
position: absolute;
z-index: -1;
top: -2px;
bottom: -2px;
right: -2px;
left: -2px;
background: linear-gradient(to right, #00ff00 0%, #00e5ff 100%);
border-radius: 2em;
content: '';
}
<div>
<h1>Gradient + Border Radius</h1>
<a class="nested"><span><p>ANOTHER ONE</p></span></a>
<a class="pseudo">AND ANOTHER ONE</a>
</div>
Using border-image. The corners are not rounded.
body {
background: url(http://subtlepatterns2015.subtlepatterns.netdna-cdn.com/patterns/ignasi_pattern_s.png);
height: 100%;
width: 100%;
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
a {
padding: 20px 40px;
border-image: linear-gradient(to bottom right, #00aeef 0%, #7cc578 100%);
border-image-slice: 1;
border-radius: 10px;
}
div {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
align-items: center;
width: 100%;
height: 100vh;
}
h1 {
margin: 2em;
text-align: center;
}
a {
text-decoration: none;
font-weight: bold;
color: black;
cursor: pointer;
transition: ease-in-out,.2s,color;
}
a:hover {
color: #DDD;
}
<div>
<h1>Gradient + [non working] Border Radius</h1>
CLICK ME
</div>
No, you can't use border-image on an element with border-radius because as per specs, only the background of the element is clipped based on border radius and not the border-image. So the image would always be a rectangle (or square).
If the need is for a transparent center portion (or a transparent content area) then the best bet is to use SVG. SVG's stroke can take even a gradient as value and so it can produce a rounded shape whose border is a gradient and center portion is transparent.
The path used for creating the shape is simple and you can read more about path commands here.
.border-with-grad {
position: relative;
height: 100px;
width: 250px;
color: white;
line-height: 100px;
text-align: center;
letter-spacing: 1.5px;
}
.border-with-grad svg {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
}
.border-with-grad path {
fill: transparent;
stroke: url(#border-gradient);
stroke-width: 4;
}
/* Just for demo */
body {
background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);
min-height: 100vh;
font-family: sans-serif;
}
<div class='border-with-grad'>
<svg viewBox='0 0 250 100'>
<defs>
<linearGradient id='border-gradient' gradientUnits='objectBoundingBox' gradientTransform='rotate(5 0.5 0.5)'>
<stop offset='0%' stop-color='rgb(248,244,135)' />
<stop offset='25%' stop-color='rgb(248,244,135)' />
<stop offset='75%' stop-color='rgb(53,176,182)' />
<stop offset='100%' stop-color='rgb(53,176,182)' />
</linearGradient>
</defs>
<path d='M50,95 a45,45 0 0,1 0,-90 h150 a45,45 0 1,1 0,90 h-150' />
</svg>
CLICK HERE
</div>
With CSS, we can use mask-image to make the center portion as transparent but its browser support is very poor. At present only webkit powered browsers support this property. Another way would be to make use of clip-path but that is no-go if you need to support IE and Firefox (Firefox supports SVG clip paths only).
If you need full browser support, And you want the inner part to be transparent, and you want a CSS only solution ... you can not use a gradient. You need to fake it whit shadows
.test {
width: 200px;
height: 80px;
border-radius: 40px;
position: relative;
overflow: hidden;
color: white;
font-size: 50px;
padding-left: 30px;
}
.test:after {
content: "";
position: absolute;
width: calc(100% - 10px);
height: calc(100% - 10px);
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
margin: auto;
border-radius: inherit;
box-shadow: -20px 0px 10px 5px rgba(250, 250, 20, 1),
20px 0px 10px 10px rgba( 20, 250, 200, 1);
}
body {
background: radial-gradient(circle, black, darkgrey);
}
<div class="test">TEST</div>

Is there a way to create a button (or div) with a border that has a gradient and has rounded corners?

This is what it should look like:
Attempts so far:
Using a gradient background plus an inner element to cover it and leave just an outer "border". The background is obviously not transparent.
body {
background: #242424;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
color: #FFFFFF;
}
div {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
align-items: center;
width: 100%;
height: 100vh;
}
h1 {
margin: 2em;
text-align: center;
}
a {
cursor: pointer;
transition: ease-in-out,.2s,color;
}
a:hover {
color: #DDD;
}
.nested {
display: block;
max-width: 20em;
padding: 2px;
overflow: hidden;
border-radius: 2em;
background: linear-gradient(to right, #00ff00 0%, #00e5ff 100%);
}
.nested span {
display: inline-block;
padding: 1em;
text-align: center;
background: #242424;
border-radius: 2rem;
}
.nested span p {
padding: 0 2em;
margin: 0;
}
.pseudo {
display: block;
margin-top: 20px;
position: relative;
border-radius: 2em;
padding: 1em 2em;
background: #242424;
}
.pseudo:after {
position: absolute;
z-index: -1;
top: -2px;
bottom: -2px;
right: -2px;
left: -2px;
background: linear-gradient(to right, #00ff00 0%, #00e5ff 100%);
border-radius: 2em;
content: '';
}
<div>
<h1>Gradient + Border Radius</h1>
<a class="nested"><span><p>ANOTHER ONE</p></span></a>
<a class="pseudo">AND ANOTHER ONE</a>
</div>
Using border-image. The corners are not rounded.
body {
background: url(http://subtlepatterns2015.subtlepatterns.netdna-cdn.com/patterns/ignasi_pattern_s.png);
height: 100%;
width: 100%;
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
a {
padding: 20px 40px;
border-image: linear-gradient(to bottom right, #00aeef 0%, #7cc578 100%);
border-image-slice: 1;
border-radius: 10px;
}
div {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
align-items: center;
width: 100%;
height: 100vh;
}
h1 {
margin: 2em;
text-align: center;
}
a {
text-decoration: none;
font-weight: bold;
color: black;
cursor: pointer;
transition: ease-in-out,.2s,color;
}
a:hover {
color: #DDD;
}
<div>
<h1>Gradient + [non working] Border Radius</h1>
CLICK ME
</div>
No, you can't use border-image on an element with border-radius because as per specs, only the background of the element is clipped based on border radius and not the border-image. So the image would always be a rectangle (or square).
If the need is for a transparent center portion (or a transparent content area) then the best bet is to use SVG. SVG's stroke can take even a gradient as value and so it can produce a rounded shape whose border is a gradient and center portion is transparent.
The path used for creating the shape is simple and you can read more about path commands here.
.border-with-grad {
position: relative;
height: 100px;
width: 250px;
color: white;
line-height: 100px;
text-align: center;
letter-spacing: 1.5px;
}
.border-with-grad svg {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
}
.border-with-grad path {
fill: transparent;
stroke: url(#border-gradient);
stroke-width: 4;
}
/* Just for demo */
body {
background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);
min-height: 100vh;
font-family: sans-serif;
}
<div class='border-with-grad'>
<svg viewBox='0 0 250 100'>
<defs>
<linearGradient id='border-gradient' gradientUnits='objectBoundingBox' gradientTransform='rotate(5 0.5 0.5)'>
<stop offset='0%' stop-color='rgb(248,244,135)' />
<stop offset='25%' stop-color='rgb(248,244,135)' />
<stop offset='75%' stop-color='rgb(53,176,182)' />
<stop offset='100%' stop-color='rgb(53,176,182)' />
</linearGradient>
</defs>
<path d='M50,95 a45,45 0 0,1 0,-90 h150 a45,45 0 1,1 0,90 h-150' />
</svg>
CLICK HERE
</div>
With CSS, we can use mask-image to make the center portion as transparent but its browser support is very poor. At present only webkit powered browsers support this property. Another way would be to make use of clip-path but that is no-go if you need to support IE and Firefox (Firefox supports SVG clip paths only).
If you need full browser support, And you want the inner part to be transparent, and you want a CSS only solution ... you can not use a gradient. You need to fake it whit shadows
.test {
width: 200px;
height: 80px;
border-radius: 40px;
position: relative;
overflow: hidden;
color: white;
font-size: 50px;
padding-left: 30px;
}
.test:after {
content: "";
position: absolute;
width: calc(100% - 10px);
height: calc(100% - 10px);
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
margin: auto;
border-radius: inherit;
box-shadow: -20px 0px 10px 5px rgba(250, 250, 20, 1),
20px 0px 10px 10px rgba( 20, 250, 200, 1);
}
body {
background: radial-gradient(circle, black, darkgrey);
}
<div class="test">TEST</div>

How can I create a postage stamp border?

I would like a div to look like this:
but would only like to use CSS, how would I go about creating a shape like this?
Do I create custom border for the top and bottom?
You can look at the code here, it does exactly what you want: http://codepen.io/orhanveli/pen/tbGJL
The code from the website:
HTML
<!-- Lets create a CSS3 stamp -->
<div class="stamp">
<!-- the image -->
<img src="http://thecodeplayer.com/uploads/media/css3logo.png" />
</div>
CSS
*{margin: 0; padding: 0;}
body {
background: #B1d202;
padding: 100px;
text-align: center;
}
.stamp {
width: 280px;
height: 180px;
display: inline-block;
padding: 10px;
background: white;
position: relative;
-webkit-filter: drop-shadow(0px 0px 10px rgba(0,0,0,0.5));
/*The stamp cutout will be created using crisp radial gradients*/
background: radial-gradient(
transparent 0px,
transparent 4px,
white 4px,
white
);
/*reducing the gradient size*/
background-size: 20px 20px;
/*Offset to move the holes to the edge*/
background-position: -10px -10px;
}
.stamp:after {
content: '';
position: absolute;
/*We can shrink the pseudo element here to hide the shadow edges*/
left: 5px; top: 5px; right: 5px; bottom: 5px;
/*Shadow - doesn't look good because of the stamp cutout. We can still move this into another pseudo element behind the .stamp main element*/
/*box-shadow: 0 0 20px 1px rgba(0, 0, 0, 0.5);*/
/*pushing it back*/
z-index: -1;
}
/*Some text*/
.stamp:before {
content: 'CSS3';
position: absolute;
bottom: 0; left: 0;
font: bold 24px arial;
color: white;
opacity: 0.75;
line-height: 100%;
padding: 20px;
}
.stamp img {
}
If you want to only have the borders on the top and on the bottom of your image you can create this by using pseudo elements.
.stamp {
margin-top: 50px;
margin-left: 50px;
position: relative;
width: 500px;
height: 300px;
background: #bbb;
-webkit-filter: drop-shadow(3px 3px 1px black);
filter: drop-shadow(0px 0px 5px white);
}
.stamp:before {
position: absolute;
top: -20px;
display: block;
content: "";
background: radial-gradient(circle, transparent 15px, #bbb 16px);
background-size: 50px 40px;
background-position: -20px -20px;
width: 100%;
height: 40px;
z-index: -1;
}
.stamp:after {
position: absolute;
bottom: -20px;
content: "";
display: block;
background: radial-gradient(circle, transparent 15px, #bbb 16px);
background-size: 50px 40px;
background-position: -20px -20px;
width: 100%;
height: 40px;
z-index: -1;
}
body {
margin: 0;
background-color: #333;
}
<div class="stamp">
</div>
You could use the mask-box-image property to do this.
FIDDLE
See this html5 Rocks article on masking
<img src="http://www.html5rocks.com/en/tutorials/masking/adobe/humayun-thom-arno.jpg" />
CSS
img {
-webkit-mask-box-image: url(http://www.html5rocks.com/en/tutorials/masking/adobe/stampTiles.svg) 35 repeat;
mask-box-image: url(http://www.html5rocks.com/en/tutorials/masking/adobe/stampTiles.svg) 35 repeat;
}

Resources