This question already has answers here:
Is it possible to make a blurred gradient shadow with CSS?
(2 answers)
Closed 7 months ago.
What would the html and css look like to create a blurred gradient underneath an image?
I understand how to create the gradient, but am not sure how to get it underneath images.
Something like this:
The gradient can be found here:
background: linear-gradient(90deg, rgba(98,52,255,1) #6234FF%, rgba(255,0,128,1) 100%);
You can make use of a custom-gradient class which is styled like that:
.image-wrapper {
background-color: white;
height: 100%;
width: 100%;
}
.custom-gradient {
display: flex;
align-items: center;
justify-content: center;
padding: 12px;
box-shadow: inset 0 0 12px 12px white, inset 0 0 3px 2px white;
background: linear-gradient(to right, rgba(98, 52, 255, 1), #6234FF, rgba(255, 0, 128, 1))
}
<div class="custom-gradient">
<div class="image-wrapper">
<h1>My image</h1>
</div>
</div>
Related
This question already has answers here:
Weird effect when applying transparent border over an element with a gradient background
(7 answers)
Closed 2 months ago.
I have a div with a background defined as linear-gradient, and an almost transparent border on top of it. It should paint correctly, but the rendering is broken.
Here is the associated CodePen.
body {
background: black;
}
.gradient-background {
background: linear-gradient(270deg, #681c2e 0%, #232a6c 49.48%);
height: 80px;
border: solid 20px rgba(248, 251, 255, 0.1);
}
<div class="gradient-background"></div>
Do you know how to fix this with CSS? It behaves consistently on Chrome and Firefox. Is it an expected behavior in the spec of CSS and HTML?
rgba(248, 251, 255, 0.1); is what causes the issue.
Use background-origin: border-box; and it will work fine.
body {
background: black;
}
.gradient-background {
background: linear-gradient(270deg, #681c2e 0%, #232a6c 49.48%);
height: 80px;
border: solid 20px rgba(248, 251, 255, 0.1);
background-origin: border-box;
}
<html>
<body>
<div class="gradient-background"></div>
</body>
</html>
For more information about this, check this source.
I'm trying to display text (a number), which is displayed on a background image.
What I currently got is the following:
body {
background-image: url("https://i.picsum.photos/id/10/800/800.jpg");
background-repeat: no-repeat;
background-position: center;
width: 400px;
height: 400px;
}
#age {
/* 1 pixel black shadow to left, top, right and bottom */
text-shadow: 2px 0 0 #fff, -2px 0 0 #fff, 0 2px 0 #fff, 0 -2px 0 #fff, 1px 1px #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;
font-family: sans;
color: transparent;
font-size: 40vw;
}
<h1 id="age">27</h1>
Basically, it works more or less as I want. However, the number itself is always filled with white color. What I would like though, is to have that number displayed huge there, have it filled with no color (transparent) and only use it with a border around the number itself. Later on, I want to upgrade to a counter, that visibly counts to the defined number first. However, the first step for me would be to display the number without the white fill.
Do you know any possible way to do this and only display a white border and have the background shine through for the rest?
There is an experimental -webkit-text-stroke CSS property, that does what you need (see this answer):
#age-container {
background-image: url("https://images.pexels.com/photos/68568/primula-catchfly-blossom-bloom-pink-68568.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
width: 400px;
height: 400px;
display: flex;
}
#age {
margin: auto;
-webkit-text-stroke: 10px white;
font-family: sans-serif;
color: transparent;
font-size: 250px;
}
<div id="age-container">
<h1 id="age">27</h1>
</div>
Another option would be to use a font that already looks the way you need it to (like these).
The issue in 2020 with:
text-stroke
text-stroke-width
text-stroke-color
text-fill-color
is that - despite having been around for over half a decade - these are still experimental properties and have never yet been added to any offical spec (either W3C or WHAT-WG).
That's why, even though text-stroke now has wide support from browsers, all browsers (including Firefox) only support text-stroke with the -webkit prefix:
-webkit-text-stroke
See: https://caniuse.com/#feat=text-stroke
Using the -webkit- browser vendor prefix may not be an issue for you.
But if it is, there is another way to visually display a text-stroke-outlined transparent number within:
<h1 id="age">27</h1>
and that's to apply an SVG image background to the <h1> element.
Working Example:
body {
display: flex;
justify-content: center;
align-items: flex-start;
}
#age {
position: relative;
font-family: sans-serif;
color: rgba(0, 0, 0, 0);
background-image: url("https://images.pexels.com/photos/1749/fire-orange-emergency-burning.jpg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
}
#age[data-age="27"]::after {
content: '';
position: absolute;
top: 0;
left: 0;
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 400 400'><text x='204' y='320' text-anchor='middle' stroke='rgb(255, 255, 255)' stroke-width='6' fill='rgba(0, 0, 0, 0)' style='font: 320px sans-serif; font-weight: 700;'>27</text></svg>");
}
#age,
#age[data-age="27"]::after {
width: 400px;
height: 400px;
background-repeat: no-repeat;
background-position: center;
}
<h1 id="age" data-age="27">27</h1>
This question already has answers here:
How to darken a background using CSS?
(11 answers)
Closed 6 years ago.
I have a jumbotron from bootstrap and I want to darken its background without touching the text which is entered in it. Is there a way to do such a thing?
I have looked everywhere, but all solutions I've found darken the text as well.
What I have so far:
.mainJumbotron {
margin: 0px;
height: 250px;
text-align: center;
background-image: url(http://i.imgur.com/qj2w73W.png);
background-repeat: no-repeat;
background-size: cover;
}
<div class="jumbotron mainJumbotron">
<h1 style="">Hakkımızda</h1>
</div>
try something like this:
In your jumbotron class, give it a little more CSS by adding position:relative; to it if it's not already there. That will allow the next step to be positioned inside of that box.
Then, add an :after pseudo element. with the following CSS
.jumbotron:after {
content:"";
display:block;
width:100%;
height:100%;
background-color:rgba(0,0,0,0.5);
position:absolute;
top:0;
left:0;
z-index:1 /*Added this in the updated */
}
the background-color shade is controlled by the final value. 0.5 is 50% opacity, raise to 1 or lower to 0 to get your desired darkness.
UPDATE What has been pointed out is that anything inside of the box is covered by the new pseudo element. Here's a cheap fix. Add z-index:1; to your :after alement, then add the below
.jumbotron > * {
position:relative;
z-index:2;
}
Thanks to cale_b https://jsfiddle.net/e8c3ex0h/3/
You can try the following in you CSS to see if you get the desired result
#element {
-webkit-box-shadow: inset 0px 50px 100px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: inset 0px 50px 100px 0px rgba(0, 0, 0, 1);
box-shadow: inset 0px 50px 100px 0px rgba(0, 0, 0, 1);
}
This is how to do it :
body, h1 {
margin: 0;
}
.mainJumbotron {
margin: 0px;
height: 250px;
text-align: center;
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
url(http://i.imgur.com/qj2w73W.png);
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
h1 {
color: #fff;
}
<div class="jumbotron mainJumbotron">
<h1 style="">Hakkımızda</h1>
</div>
(see also this Fiddle)
I was trying make a transparent text background and the background should fill as far as any character goes.
If I use display:inline-block both line gets the same background width so filling text background effect is missing and that's not what I am trying to achieve.
getting on top one another can be fixed by increasing line height, or setting the line height normal but that makes huge gap between lines. Well I would like to have both line very close. which in this case is 55px line height with font-size of 47px.
Markup here:
.main {
width: 500px;
margin: 100px auto;
background: green;
padding: 30px;
}
.test {
width: 450px;
}
.main h2 {
color: #ffffff;
font-size: 47px;
line-height: 55px;
}
.main h2 span {
background: rgba(0, 0, 0, 0.2);
}
<div class="main">
<div class="test">
<h2><span>A title about your dream kitchen</span></h2>
Read MOre
</div>
</div>
Check in jsfiddle: http://jsfiddle.net/srmahmud2/ze4kpmuy/
not sure can I make you understand or not. here a screenshot for quick look
http://postimg.org/image/efnmpoiy1/
Another option, using drop shadows, courtesy of this blog. Here is the style for the .main h2 span:
.main h2 span {
background: rgba(0, 0, 0, 0.2);
box-shadow: 10px 0 0 rgba(0, 0, 0, 0.2),
-10px 0 0 rgba(0, 0, 0, 0.2);
}
jsfiddle: http://jsfiddle.net/slushy/mu8rwcjp/
This question already has answers here:
How to darken a background using CSS?
(11 answers)
Closed 7 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Should be a fairly simple question. In my website I do this:
#landing-wrapper {
display:table;
width:100%;
background:url('landingpagepic.jpg');
background-position:center top;
height:350px;
}
What I'd like to do is make the background image darker. Since I have UI elements inside this DIV I don't think I can really place another div over it to darken it. Suggestions?
You can use the CSS3 Linear Gradient property along with your background-image like this:
#landing-wrapper {
display:table;
width:100%;
background: linear-gradient( rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5) ), url('landingpagepic.jpg');
background-position:center top;
height:350px;
}
Here's a demo:
#landing-wrapper {
display: table;
width: 100%;
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('http://placehold.it/350x150');
background-position: center top;
height: 350px;
color: white;
}
<div id="landing-wrapper">Lorem ipsum dolor ismet.</div>