Here is what my output currently looks like. I have a two divs for the background colour (black and white), and another div on top that holds my text. I want half of the text to be white and half of it to be black so that it can be seen on each half. I have tried making two inner paragraphs in the div to hold my text, and then modifying those, but that way seems inefficient and requires more work. I was wondering whether or not there is a linear gradient like feature for the foreground colour instead of background. If not, what do you suggest me doing?
Asked
Active
Viewed 933 times
2 Answers
2
You can use linear-gradient
here:
body {
background-color: white;
}
#background {
position: fixed;
top: 0px;
left: 0px;
width: 50%;
height: 50%;
background-color: black;
z-index: 1;
}
#content {
position: relative;
z-index: 2;
padding: 30px;
text-align: center;
font-weight: bold;
font-family: Arial, sans-serif;
}
p{
display: inline-block;
margin: 0;
background: linear-gradient(to right, #fff 50%, #000 50%);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<div id="content">
<p>This is some content.</p>
</div>
<div id="background"></div>

Sumit Sharma
- 1,192
- 1
- 4
- 18
0
You can use these css properties:
background: linear-gradient(to right, #fff 50%, #000 50%);
background-clip: text;
-webkit-background-clip: text; /* Safari and Chrome */
-moz-background-clip: text; /* Firefox */
-ms-background-clip: text; /* IE 9 */
-o-background-clip: text; /* Opera */
-webkit-text-fill-color: transparent;
#content {
padding: 30px;
text-align: center;
background: linear-gradient(to right, #000 50%, #fff 50%);
}
p{
font-weight: bold;
font-family: Arial, sans-serif;
background: linear-gradient(to right, #fff 50%, #000 50%);
background-clip: text;
-webkit-background-clip: text; /* Safari and Chrome */
-moz-background-clip: text; /* Firefox */
-ms-background-clip: text; /* IE 9 */
-o-background-clip: text; /* Opera */
-webkit-text-fill-color: transparent;
}
<div id="content">
<p>This is some content.</p>
</div>

Mubeen Ahmad
- 428
- 3
- 11