I need to make text exactly like this
This means that border should be behind the text. I tried many things and have been searching in the Internet all day.
If you now how, please help me)
CodePudding user response:
The following hopefully fits your needs:
*{
margin: 0;
font-family: Arial, sans-serif;
}
.container {
display: relative;
}
.behind {
height: .75rem;
width: 100%;
position: absolute;
z-index: -1;
top: 1.4rem;
border-radius: .375rem;
background-image: linear-gradient(to right, rgb(201, 157, 201), rgb(110, 202, 224));
}
.container h1 {
position: absolute;
}
<div class="container">
<h1>Stack Overflow
<div class="behind"></div>
</h1>
</div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
Well, you can just use another div and use the z-index property to make it go back of a text.
CodePudding user response:
try this code and change what you want:
<html>
<head>
<style>
div{
background-color:#a65cdb;
text-align:center;
font-family:sans-serif;
padding:5px 10px 0 10px;
color:white;
font-size:3rem;
font-weight:600;
z-index:0;
}
span{
background-color:white;
z-index:1;
padding:12px;
position:relative;
display:block;
border-radius:10px;
opacity:50%;
top:-22px;
margin-bottom:0;
</style>
</head>
<body>
<div>
LEADERBOARD<span></span>
</div>
</body>
</html>
CodePudding user response:
Unfortunately, I only saw your question now. Unfortunately too late. And there are also solutions. I would have done it similarly but without nesting. I prefer less nesting because it is easier to read. That would be my way:
body {
background-image: linear-gradient(to right, rgb(147,112,219), rgb(153,50,204));
height:100vh;
margin: 0;
font-family: Arial, sans-serif;
}
.container {
display: relative;
text-align: center;
}
.container .title {
font-size: 50px;
font-weight: bold;
color: white;
}
.underline {
height: 1.15rem;
width: 410px;
position: absolute;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
top: 2.3rem;
border-radius: .375rem;
background-color:white;
opacity: 30%;
}
<body>
<div class="container">
<div class="title">LEADERBOARD</div>
<div class="underline"></div>
</div>
</body>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
This is my solution using a (p) element to store the text and the (::after) element to create the line.
.container {
display: inline-block;
background: linear-gradient(to right, #826CDC, #A45DD5);
position: relative;
}
.text {
position: relative;
text-align: center;
margin: 16px 20px;
text-transform: uppercase;
font-size: 60px;
color: white;
font-weight: 700;
padding: 0 30px;
}
.text::after {
content: "";
position: absolute;
left: 0;
bottom: 0;
border-radius: 50px;
background: #ffffff;
opacity: 0.5;
height: 30px;
width: 100%;
}
<div class="container">
<p class="text">Leaderboard</p>
</div>
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>