Creating a CSS gradient effect on mirrored text

I am looking to style text using CSS and incorporate a gradient effect into it. You can see an example here. However, I want to achieve this without using a fade-out png image with alpha transparency since the background already has a color.

https://i.sstatic.net/gWMy4.png

https://jsfiddle.net/9318Ltkp/

.slogan {
  font-size: 30px;
  line-height: 121px;
  position: relative;
  float: right;
  margin-right: 115px;
  text-transform: uppercase;
  color: #f00;
}
.slogan::after {
  position: absolute;
  z-index: 1;
  right: 0;
  bottom: -26px;
  left: 0;
  display: block;
  content: 'coming soon';
  transform: scaleY(-1);
  opacity: .5;
}
<div class="slogan">coming soon</div>

Answer №1

Keep in mind: After experimenting, it appears there may not be a universal solution for achieving this effect across all browsers. It seems that support is limited to WebKit-based browsers only.

In this particular method, a gradient transitioning from transparent to semi-transparent black is utilized as the background for a pseudo-element responsible for creating the reflection effect. The key here is using WebKit's -webkit-background-clip property to clip the background within the text boundaries.

Unfortunately, the challenge lies in the fact that other browsers do not offer an equivalent property. In those cases, we can set a linear-gradient background for the element and make the text color transparent. However, unlike WebKit browsers, there isn't a way to clip the background solely within the text, as it will cover the entire element.

body {
  background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);
}
div {
  position: relative;
  display: inline-block;
  font-size: 24px;
}
div:after,
div:before {
  position: absolute;
  width: 100%;
  height: 100%;
  bottom: 0px;
  left: 0px;
  transform: scaleY(-1);
  transform-origin: bottom;
}
div:after {
  content: attr(data-content);
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.5) 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div data-content='Reflected Text'>Reflected Text</div>


A Solution Across Browsers:

The following represents my best attempt at finding a cross-browser solution. It involves manually truncating the reflected text by utilizing overflow: hidden on the parent container, albeit resulting in a less elegant fade effect.

body {
  background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);
}
div {
  position: relative;
  display: inline-block;
  font-size: 24px;
  height: 1em;
  padding-bottom: .5em;
  overflow: hidden;
}
div:after {
  position: absolute;
  content: attr(data-content);
  width: 100%;
  height: 1em;
  top: 0px;
  left: 0px;
  transform: scaleY(-1);
  transform-origin: bottom;
  opacity: 0.3;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div data-content='Reflected Text'>Reflected Text</div>


The Original Suggestion:

To achieve this effect, one approach suggested is overlaying a :before pseudo-element with a gradient background above the existing :after pseudo-element.

This method is effective when the background is a solid color, as it entails adjusting the gradient colors accordingly. However, the technique may not seamlessly integrate with image or gradient backgrounds.

div {
  position: relative;
  display: inline-block;
  font-size: 24px;
}
div:after,
div:before {
  position: absolute;
  width: 100%;
  height: 100%;
  bottom: 0px;
  left: 0px;
  transform: scaleY(-1);
  transform-origin: bottom;
}
div:after {
  content: attr(data-content);
}
div:before {
  content: '';
  background: linear-gradient(to bottom, rgba(0, 128, 0, 1) 30%, rgba(0, 128, 0, 0.7) 70%);
  z-index: 2;
}
body {
  background: rgb(0, 128, 0);
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div data-content='Reflected Text'>Reflected Text</div>

Answer №2

When it comes to gradients, I have already designed one. You can find it in the code snippet below:

<html>
<body>

<svg height="150" width="400">
  <defs>
    <linearGradient id="grad2" x1="0%" y1="0%" x2="100%" y2="0%">
      <stop offset="0%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
      <stop offset="100%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
    </linearGradient>
  </defs>

  <text fill="url('#grad2')" font-size="45" font-family="Verdana" x="150" y="86">SVG</text>
  Sorry, your browser does not support inline SVG.
</svg>

</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Substituting HTML checkboxes with highlighted images for consistent display across different web browsers

I am looking to transform a list of HTML checkboxes into clickable images for the user to select or deselect. My goal is to create a similar functionality as shown in this video using just CSS if possible. I have successfully implemented it in Chrome wit ...

Tips on concealing the active tab border when it is not located on the ul element

Is it possible to remove or cover the border on an active tab when the border is set on a different panel? I know how to do it when the border is on the ul element by using margin-right: -1px, but what about in this scenario? I tried setting margin-right: ...

The error of type TypeError has been encountered while using Bootstrap in conjunction with

I have encountered an issue while attempting to incorporate Bootstrap <link> and <script> tags into my HTML within an Angular project. I acquired all the content delivery network (CDN) links from this website, but unfortunately, I am receiving ...

Add a space following each individual character using CSS styling

Imagine we start with this HTML: <h2>TITLE</h2> Can CSS alone transform it into something like this: <h2>T I T L E</h2> The goal is to justify the letters within the title over a specified width without relying on server-side so ...

What is the typical method for identifying a mobile email application?

Is there a way to detect the specific mail client being used to open an email and format the message accordingly? Similar to how websites have mobile-friendly versions that load based on user-agent detection, is it possible to customize the email display f ...

What is the best way to incorporate a badge into my Bootstrap site?

I am delving into the world of front-end development, starting with a Bootstrap project. However, I have hit a roadblock. I am trying to incorporate badges similar to those in my design, but every attempt throws off the alignment and messes up the layout o ...

Adjustable / consistent box height

For hours, I've been attempting to make some divs the same height. Check out my JSfiddle here: https://jsfiddle.net/4cj5LbLs/15/ I experimented with using display: table; in the parent element and either display: table-cell; or display: table-colum ...

Choose a child using react material ui's makeStyles

Currently utilizing React and Material UI, I am attempting to use the nth-child selector with the MUI makeStyle function. However, it is not working as expected. Here are some screenshots for reference: https://i.sstatic.net/5dVhV.png https://i.sstatic.ne ...

scrollable list using bootstrap

<div class="panel panel-primary" id="result_panel"> <div class="panel-heading"><h3 class="panel-title">List of Results</h3> </div> <div class="panel-body"> <ul class="list-group"> &l ...

Set a variable to represent a color for the background styling in CSS

My goal is to create an application that allows users to change the background color of a button and then copy the CSS code with the new background color from the <style> tags. To achieve this, I am utilizing a color picker tool from . I believe I ...

Modify Navbar Color based on State using Styled Components

I am looking to update the navbar color upon scrolling using the useState hook. const Navbar = () => { const [colorChange, setColorchange] = useState(false); const changeNavbarColor = () =>{ if(window.scrollY >= 38){ setC ...

Utilize dynamic inline styling to pass asset image paths as background images in Nuxt.js

I am in the process of developing a Nuxt.js application and I have a requirement to dynamically set the background image of an element using images from the assets folder. Here is what I have implemented: <template> <div> <div v ...

Adjust the background hue while scrolling (scrolling feature not functioning properly)

Seeking assistance with changing the background color of a component based on user scrolling behavior. I have attempted to achieve this using the following code snippet: const [mainColor, setMainColor] = useState('red') const listenScrollEve ...

The buttons on my screen have a visible border, but it magically disappears whenever I click elsewhere on the screen

Recently, I’ve been facing an issue with my buttons displaying a border when they first load, with the border color varying across different browsers (blue in Safari, a dotted black in Chrome). I suspect it has to do with some sort of default selection b ...

Exploring the creation of CSS animations using box-shadow effects

Looking to create a CSS animation where part of a line (200px) changes color like a gradient. Any ideas on how to achieve this effect? Below is the current code being used: * { margin: 0; padding: 0 20px; } h1 { text-align: center; } ...

What is the best way to customize the styles of a reusable component in Angular2?

I am working with a reusable component called "two-column-layout-wrapper" that has its styles defined in the main .css file. In another module, I need to use this component but customize the width of two classes. How can I override these styles? import ...

Guide to changing the border color in a Material-UI TextField component styled with an outline design

To complete the task, utilize the Material UI outlined input field (TextField component from "@material-ui/core": "^4.12.2",) and apply a custom blue color style to it. Here is the outcome of my work: https://i.sstatic.net/lw1vC.png C ...

Setting up button value dynamically according to dropdown selection in Angular 2

I'm a beginner in angular 2 and I have a button with a dropdown. When I select an option from the dropdown, I want its value to be displayed on the button. The CSS code for styling the dropdown is provided below: .common_select_box { width: 100%; } ...

Understanding the Contrast between Relative Paths and Absolute Paths in JavaScript

Seeking clarification on a key topic, Based on my understanding, two distinct paths exist: relative and absolute. Stricly relative: <img src="kitten.png"/> Fully absolute: <img src="http://www.foo.com/images/kitten.png"> What sets apart R ...

Materialize.css | managing spaces, indentation, and 'overriding' in a span element

I recently started using a new framework called Materialize CSS for my project and I'm still getting the hang of it. One issue I've encountered is that long texts in my sidebar are creating large spaces between line breaks and strange indents. D ...