I'm trying to convert a Figma design into code but it has some text that uses an inner-shadow effect
I tried to style it using plain and clipping the text-shadow CSS property but the result doesn't quite match the design in which the shadow kind of clips/insets the text.
h1 {
font-family: 'Poppins';
font-style: normal;
font-size: 80px;
text-align: center;
color: #6225E6;
text-shadow: -6px 0px 0px #D63737;
background-color: #151717;
}
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<h1>This is some text<h1/>
You can get closer using mask (doesn't work in Firefox)
h1 {
font-family: 'Poppins';
font-size: 80px;
letter-spacing: 5px;
text-align: center;
color: #0000;
text-shadow:
5px 0 #6225E6,
0 0 red;
-webkit-mask: linear-gradient(#000 0 0);
-webkit-mask-clip: text;
mask-clip: text;
}
body {
background:#000;
}
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<h1>This is some text<h1/>
For better support you can duplicate the text and try like below:
h1 {
font-family: 'Poppins';
font-size: 80px;
letter-spacing: 5px;
text-align: center;
color: #0000;
text-shadow:
5px 0 #6225E6,
0 0 red;
position: relative;
}
h1:before {
content: attr(data-text);
position: absolute;
inset: 0;
background: #000;
color: #fff;
mix-blend-mode: darken;
text-shadow: none;
}
body {
background: #000;
}
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<h1 data-text="This is some text">This is some text</h1>
This kind of works, I guess depending on who is looking at it and what they're interpreting as the shadow versus the fill. The slight blur is me trying to throw the viewer off a bit but unfortunately, it doesn't give you much room to move the shadow either. I think any solution anybody comes up with is going to require some form of optical illusion to make it work.
body {
background-color: #151717;
}
h1 {
font-family: 'Poppins';
font-style: normal;
font-size: 120px;
background-color: #D63737;
color: transparent;
letter-spacing: 2px;
text-shadow: 2px 2px 1px #6225E6, 1px 1px 1px #D63737;
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
}
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<h1>This is some text</h1>
added this CSS property called letter-spacing
that makes every letter have some little gap between them, so the shadow doesn't touch the other letters.
letter-spacing: 6px;
documentation: The letter-spacing CSS property sets the horizontal spacing behavior between text characters. This value is added to the natural spacing between characters while rendering the text. Positive values of letter-spacing causes characters to spread farther apart, while negative values of letter-spacing bring characters closer together.
h1 {
font-family: 'Poppins';
font-style: normal;
font-size: 80px;
text-align: center;
color: #6225E6;
text-shadow: -6px 0px 0px #D63737;
background-color: #151717;
letter-spacing: 6px;
}
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<h1>This is some text</h1>
Related
I have made a background with the div box, following this triangles tutorial to separate it into two navy blue triangles and one white trapezoid.
I duplicated this div and added child elements with text to go in front of this background. I used position: absolute and the text was in front, but the text was grouped up funny, with the 3 sentences all duplicated and overlapping.
I then tried separating the div-child-text elements into 3 separate classes (.Child-text-01, -02, and -03) and adjusting the top function accordingly. And tada, no longer overlapping but still duplicated.
I tried position: relative for the text, and voila, it wouldn't show up because it is behind the box.
I checked my parses, they were fine as far as I know. I reasoned maybe the box isn't calculating its children because the relative position doesn't do it, I changed the boxes to position: absolute, but it screwed the web page up pretty hard. then I checked the HTML, and fiddled around with the ending parse, no dice, I am wondering what I am missing, I am a new coder and self-taught.
My code is below:
body {
background-color: #1d3c6e;
}
#font-face {
font-family: "cola-font";
src: url("cola-font-medium.ttf");
}
body h1 {
color: white;
font-size: 80px;
font-family: "cola-font";
font-width: 10px;
}
body h2 {
color: white;
font-family: "cola-font";
font-width: 10px
}
body h3 {
color: white;
}
body h4 {
color: white;
}
.Child-text-01 {
color: #212b2a;
font-size: 30px;
font-family: "cola-font";
position: absolute;
top: 2750px;
font-weight: bold;
}
.Child-text-02 {
color: #212b2a;
font-size: 30px;
position: absolute;
top: 2780px;
font-family: "cola-font";
font-weight: bold;
}
.Child-text-03 {
color: #212b2a;
font-size: 30px;
position: absolute;
top: 2810px;
font-family: "cola-font";
font-weight: bold;
}
.Child-text-04 {
color: white;
font-size: 100px;
font-weight: bolder;
font-family: "cola-font"
}
.Child-text-05 {
color: white;
font-size: 30px;
font-weight: bold;
}
.box-one-red {
background-color: #e30b0b;
width: 1200px;
margin: 50px;
border: 10px solid #050000;
position: fixed;
bottom: -50px;
}
.box-two-white-trapeziod {
border-bottom: 2048px solid #fff;
border-left: 512px solid #1d3c6e;
border-right: 512px solid #1d3c6e;
}
.box-two-navy-trapezoid {
border-top: 2048px solid #fff;
border-left: 512px solid #1d3c6e;
border-right: 512px solid #1d3c6e;
}
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="HtmlbrickhouseStyle.css">
<title> Cloth's Generic Website </title>
<meta: charset "UTF-8">
</head>
<body>
<header>
<div class="box-two-white-trapeziod">
<h1> Do You Want to see some of the stuff i made? </h1>
</div>
<div class="box-two-navy-trapezoid parent">
<div class="Cliffsidetest">
<div class="Child-text-01 child"> Number one Cliffsidetest, A TF2 map</div>
<div class="Child-text-02 child">Number two, Various Blender Models i Made Of Various Things,</div>
<div class="Child-text-03 child">Number three, A Mobile Game Currently In The Works</div>
</div>
</div>
So now the three sentences, (.Child-text-01, .Child-text-02, and .Child-text-03) are supposedly stuck behind the box element.
I am trying to get the Texas icon directly centered between the span and h1 element.
Here is the Screen Capture
I tried googling but I think I might be phrasing what I need poorly. Is it that I have to adjust the padding and margin in css? I just want to move the icon down the y-axis.
Thank you
<header id="top" class="main-header">
<span class="title">Keep it Weird in</span>
<div>
<img class="texas-icon" src="https://image.ibb.co/cGRVFG/texasicon_1.png" alt="texasicon_1" border="0"></a>
</div>
<h1>Austin</h1>
.main-header {
padding-top: 170px;
height: 850px;
background: linear-gradient(lightblue, transparent 90%),
linear-gradient(0deg, #fff, transparent),
#ffa949 url('https://media.giphy.com/media/3ohs7I9ho0H4dfeP7y/giphy.gif') no-repeat center;
background-size: cover;
}
.title {
color: white;
font-size: 1.625rem; /* 26px/16px */
letter-spacing: .065em;
font-weight: 200px;
padding-bottom: 10px;
}
h1 {
font-size: 12.5rem; /* 90px/16px */
color: rgba(255, 255, 255, 1);
text-transform: capitalize;
font-weight: normal;
text-align: center;
line-height: 1.3;
margin: 12px 0px 0px;
}
I think text-align:center is enough in your case, then simply play with margin of elements to create the spaces :
header {
background: blue;
text-align: center;
color: #fff;
max-height: 380px;
padding: 50px 25px 0px;
}
.title {
margin: 5px 0;
font-size: 1.3rem;
border: none;
display: inline-block;
}
h1 {
margin: 10px 0;
font-size: 5rem;
line-height: 1.1;
}
<header id="top" class="main-header">
<span class="title">Keep it Weird in</span>
<div>
<img class="texas-icon" src="https://image.ibb.co/cGRVFG/texasicon_1.png" alt="texasicon_1" border="0">
</div>
<h1>Austin</h1>
</header>
Thank you for the support. Unfortunately, none of the solutions worked but I decided just to change the line height of the h1 element and was able to get the result I wanted. I learned so many new things from the responses to my question. Again, thank you.
Updated Screen Capture
I encountered a problem when creating inner shadow for the text. I tried this method (some css does not work in such online-compilers, but the code is visible):
.text {
background-color: #565656;
font-size: 35px;
color: transparent;
text-shadow: 0px 2px 3px rgba(255,255,255,0.5);
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
}
<div class="text">
Text
</div>
The result is a light gray text, but I need the text of a different color. When I tried to change the text color and shadow color (not alpha), it became clear that, apparently, "background-clip: text;" do not cut the shadow in the text area, and I see a blurred silhouette outside the contours of letters.
This is what happens (the text and shadow colors are wrong here, but the overlap is visible):
And that's what I need:
By using a background color the same as main shadow color it's possible, there may be other ways but this is the most common one I know of.
Source code -- https://codepen.io/vincicat/pen/zikrC
body {
/* This has to be same as the text-shadows below */
background: #def;
}
h1 {
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 2em;
line-height: 1em;
text-align:center;
}
.inset-text {
/* Shadows are visible under slightly transparent text color */
color: rgba(10, 60, 150, 0.8);
text-shadow: 1px 4px 6px #def, 0 0 0 #000, 1px 4px 6px #def;
}
/* Don't show shadows when selecting text */
::-moz-selection, ::selection {
background: #5af;
color: #fff;
text-shadow: none;
}
<h1 class="inset-text">Inset text-shadow trick</h1>
.text {
font-size: 50px;
display:flex;
justify-content: center;
font-stretch: ultra-expanded;
color: rgb(96, 32, 24);
background-color: rgb(186, 186, 186);
background-image: url(http://previews.123rf.com/images/auborddulac/auborddulac1201/auborddulac120100059/12000991-Dotted-yellow-background-Stock-Photo.jpg);
text-shadow: rgb(224, 224, 224) 1px 1px 0px;
}
<div class="text">
Text
</div>
See this example:
I have several boxes with white background and huge black, translucent box shadows that overlap the boxes above. However, this leads to an irritating behavior: While the white background gets darker through the overlapping box shadows, nested objects, like text or other boxes, don't!
Could anybody tell me why this occurs? I guess it has something to do with z-index. I would like prevent this - the nested objects should become darker as well. Any solutions?
Thanks in advance!
Here's the code: https://jsfiddle.net/xq20hvp4/3/
<div>Coloured text <span>Box with background</span></div>
<div>Coloured text <span>Box with background</span></div>
<div>Coloured text <span>Box with background</span></div>
<div>Coloured text <span>Box with background</span></div>
<div>Coloured text <span>Box with background</span></div>
CSS:
div {
margin: 20px;
box-shadow: 0 0 0 250px rgba(0, 0, 0, 0.3);
font-size: 25px;
color: red;
font-weight: bold;
font-family: Consolas, Arial, sans-serif;
background-color: #ffffff;
}
div span {
background-color: #e7e7e7;
color: #555555;
font-weight: normal;
font-size: 17px;
padding: 1px 5px;
}
It's because those elements are on top of the div with the shadow. In order to put them behind, you can use position: relative; on the background element and give it z-index: 1:
div {
margin: 20px;
box-shadow: 0 0 0 250px rgba(0, 0, 0, 0.3);
font-size: 25px;
color: red;
font-weight: bold;
font-family: Consolas, Arial, sans-serif;
background-color: #ffffff;
/* Add this */
position: relative;
z-index: 1;
}
div .box {
background-color: #e7e7e7;
color: #555555;
font-weight: normal;
font-size: 17px;
padding: 1px 5px;
}
Here's an updated fiddle: https://jsfiddle.net/6wwz8usw/.
https://jsfiddle.net/fd7tx2c2/
div {
z-index: 1;
position: relative;
}
Z-index
Position
I need to center vertically the text inside a div but I am having a problem. This is the situation:
There is an hover attribute that I added in the CSS and in fact, when the mouse goes on the div, it changes the background and the text goes at the center of the div.
I would like the text to be centered also in the first case shown in the picture (when the mouse in not over the div). You can find the fiddle with the code here: Fiddle
.tab {
float: left;
margin: 0px;
height: 50px;
display: table-cell;
line-height: 50px;
}
This is the code that I have used for the div. And when the mouse goes over:
.tab:hover {
cursor: pointer;
box-shadow: inset 0 0 10px #999;
-moz-box-shadow: inset 0 0 10px #999;
-webkit-box-shadow: inset 0 0 10px #999;
background-color: #555;
line-height: 50px;
}
I have used the line-height in both cases but it works only in .tab:hover. Any idea?
That happens because you are setting after a declaration for the font:
.font_header {
font: 19px Century Gothic, sans-serif;
color: #EEEEEE;
}
This CSS is after and then the specificity goes with the declaration here. If you just change the order it will work, since the last has more precedence:
.font_header {
font: 19px Century Gothic, sans-serif;
color: #EEEEEE;
}
.tab {
float: left;
margin: 0px;
height: 50px;
display: table-cell;
line-height: 50px;
}
UpdatedFiddle
You need to set the line-height: 50px; for .font_header as well.
Example fiddle: http://jsfiddle.net/6tzwc17c/2/
At least in Chrome it works if you just split the font declaration, like:
font-family: Century Gothic, sans-serif;
font-size: 19px;
Instead of:
font: 19px Century Gothic, sans-serif;