Reputation: 105
I'm trying to do this using only this <div>1 Hello, Welcome To Elzero Web School</div>
I tried but I can't figure it out that is my code :
div{
position: relative;
background-color: rgb(146, 141, 141);
width: 400px;
height: 50px;
}
div::first-letter {
background-color: red;
font-size: 40px;
color: white;
position: absolute;
left: -25px;
}
Upvotes: 0
Views: 515
Reputation: 176
Note: The ::first-letter pseudo-element can only be applied to block-level elements.
The following properties apply to the ::first-letter pseudo- element:
source- https://www.w3schools.com/css/css_pseudo_elements.asp
That is why position is not working for the pseudo-element and in order to align the first-letter you can use margin properties to align it outside of your box
I tried to replicate design as close as possible you can take idea from the snippet to position the first-letter
div{
padding:25px;
background-color: #d3d3d3;
font-size: 20px;
border:20px solid white;
display:inline-block;
}
div::first-letter {
background-color: red;
font-size: 20px;
color: white;
padding:15px;
font-weight:900;
margin-left:-40px;
margin-right:10px;
}
<div>1 Hello, Welcome To Elzero Web School</div>
Upvotes: 1
Reputation: 29
You can't change the position of the ::first-letter
selector.
Here's a list of what you can change with it
I'd suggest trying another approach
Upvotes: 0