Conceal / reveal minuscule letters

Is it feasible to hide or select only the lowercase characters of a string using CSS?

<p>Richard Parnaby-King</p>

How can I display just RPK?

While ::first-letter allows me to show the letter R, is there a way to go further with this?

p {
  font-size:0;
}
p::first-letter {
  font-size:16px;
}
<p>Richard Parnaby-King</p>

Edit

I aim to animate the letters out. For example, having a CSS animation that transitions from RPK to Richard Parnaby-King upon hover.

I cannot modify the HTML structure.

My current approach involves changing the font color of the p tag to white (on a white background), adding an :after element containing "RPK" centered on the p tag, and on :hover, animating the rotation of "RPK" by 90 degrees, then hiding it with display:none (or similar), rotating the p tag by 270 degrees and animating it back to 360 degrees. This creates an effect where "RPK" rotates around as "Richard Parnaby-King" emerges. Below is a rough representation of my described effect, which doesn't handle text visibility correctly.

p {
  color: #fff;
  position: relative;
  text-align: center;
}
p:after {
  content: "RPK";
  position: absolute;
  left: 0;
  top: 0;
  color:#000;
  text-align: center;
  width:100%;
}
p:hover {
  animation: pSpin 1s forwards;
}
p:after:rhover {
  animation: pAfterSpin 0.5s forwards;
}
@keyframes pSpin {
  0% {
    transform:rotateY(0deg);
    color:#fff;
  }
  50% {
    color:#000;
    transform:rotateY(270deg);
  }
  100% {
    transform:rotateY(360deg);
    color:#000;
  }
  
}
@keyframes pAfterSpin {
  0% {
    transform:rotateY(0deg);
    color:#000;
  }
  100% {
    transform:rotateY(90deg);
    color:#fff;
    z-index:-5
  }
}
<p>Richard Parnaby-King</p>

Answer №1

To achieve the desired effect, you can make some adjustments to the HTML code. It may require a bit of experimentation to get it just right.

p span {
  font-size:0;
  display: inline-block;
}
p span::first-letter {
  font-size:16px;
}
<p><span>Alice</span> <span>Jones</span><span>–Smith</span></p>

Answer №2

After my inquiry, I was able to achieve the desired animation effect where lowercase text remains hidden until hovered over. Although it wasn't exactly what I initially envisioned (I didn't intend for the text to rotate), it is a close approximation.

The implementation involves a series of animations. The first one rotates the :after content. After its completion, the entire p tag is rotated and animated to reveal the full name.

div {
  padding:1em;
}

p {
  color: #fff;
  position: relative;
  text-align: center;
}
p:after {
  content: "RPK";
  position: absolute;
  left: 0;
  top: 0;
  color:#000;
  text-align: center;
  width:100%;
  
}
div:hover p {
  animation: pSpin 0.5s forwards;
  animation-delay:0.3s;
}
div:hover p:after {
  animation: pAfterSpin 0.5s forwards;
}
@keyframes pSpin {
  0% {
    transform:rotateY(0deg);
    color:#fff;
  }
  51% {
    color:#fff;
    transform:rotateY(270deg);
  }
  52% {
    color:#000;
    transform:rotateY(270deg);
  }
  99% {
    color:#000;
  }
  100% {
    transform:rotateY(360deg);
    color:#000;
  }
  
}
@keyframes pAfterSpin {
  0% {
    transform:rotateY(0deg);
    color:#000;
    z-index:2;
  }
  99% {
    color:#000;
    z-index:2;
  }
  100% {
    transform:rotateY(90deg);
    color:#fff;
    z-index:-5
  }
}
<div>
  <p>Richard Parnaby-King</p>
</div>

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

Lightbox2 is looking to reposition the caption to the right of the image

Can anyone help me understand how to move the caption, found in data-title, from underneath an image to the right of the image? I'm not very familiar with HTML/CSS, but it looks like the image is enclosed within a div called .lb-outerContainer, and t ...

How can I eliminate the empty spaces around a bar chart in Kendo UI?

Struggling to eliminate the extra space surrounding the Kendo UI chart below. Could this be due to a gap or spacing issue? The goal is to create a single-line bar chart with only grey appearing on the right side. Access JSFiddle Codes Here $(doc ...

Struggling to Achieve Consistent Design Across Different Browsers When Styling a Calendar

My webpage has a calendar that retrieves data from the server using Jquery. Interestingly, the calendar looks perfect on Google Chrome but falls apart on Firefox. I can't seem to style it to make it look consistent across different browsers like in C ...

Centering content within a <th> tag

Hey there, I'm currently facing an issue with aligning a div inside another one. To illustrate the problem, I've set up a small fiddle which you can check out here: https://jsfiddle.net/jpq7xzoz/ The challenge arises when using the jQuery table ...

Bootstrap 4 cards continue to resize instead of adapting to the constraints of the designated space

I've been attempting to implement functionality with bootstrap 4 cards, but I'm running into issues where the card size expands based on the length of the text. Below is my code: <div class="row row-container"> <div class=& ...

JQuery integration resulting in disappearance of Input-group-btn element

Allow me to explain my current project. I am in the process of developing a Modal that enables users to input a password There will be an option to toggle between showing or hiding the text in the password field using a button positioned on the right sid ...

Understanding the differences between jquery's addClass method and the .css()

After creating a function to set a background on a click event, I encountered an issue. I attempted two different methods, expecting both to be successful. However, only the .css() version worked while the addClass method failed. Why is this happening? fu ...

Two challenges I encountered with my CSS dropdown menu bar

I've been working on a CSS top dropdown navigation bar, but I'm encountering two issues that I can't seem to resolve. The first problem is that my nav div either extends too far down or my 1px right border tabs aren't reaching the botto ...

When you hover over them, Material UI icons shrink in size due to the Border

I've been working on a React application that includes Material UI icons in the header. My goal is to add a border at the bottom of each icon when hovered over, but currently, the borders are too close to the icons. Another problem I'm facing is ...

Navigate through previous and next siblings in jQuery until a difference is found

Here's the issue: I have a div with multiple siblings positioned before and after it. For example: <div id="parent"> <div class="invalid"></div><!-- break iteration here !--> <div class="operand"></div> <div cl ...

CSS Grid with dynamically changing number of rows set to "auto", while ensuring one row always has a fixed size of "1fr"

Currently, I am experimenting with a CSS grid-based frontend and have encountered a specific requirement that keeps repeating itself in various parts of the frontend: A grid with a dynamic number of rows. Each row should be of variable size (auto). The f ...

Add formatting to a particular element without affecting elements within another element

Consider the following scenario: <input type='text' /> <br /> <iframe> <input type='text'> </iframe> With the style defined as: input[type='text'] { border: 1px solid black; } If you w ...

How to Style Your ASP.NET Website: Utilizing a Stylesheet with Visual Studio 2010

I am having trouble adding a stylesheet to the master page of my asp.net web form. I want to create an inline navigation menu at the top of the page, but I can't seem to get it working. I have created the stylesheet in the same way I would for an HTML ...

Overlap caused by padding between two elements

I'm encountering an issue where adding padding to a block element is causing it to overlap with the padding of other elements. Below is the code snippet showcasing this problem. <section class="hero"> <h1>Studying REDEFIN ...

Updating the iFrame source using jQuery depending on the selection from a dropdown menu

I want to create a dynamic photosphere display within a div, where the source is determined by a selection from a drop-down menu. The select menu will provide options for different rooms that the user can view, and the div will contain an iframe to showca ...

Ways to divide the vuetify-text-field-label into two lines

My vuetify text field has a label that is too long for mobile devices. I am wondering if there is a way to automatically wrap the text. I attempted using div and p, as shown in this codepen link <div id="app"> <v-app id="inspire ...

Exploring the Potential of CSS Styling within Vue.js

I am in the process of creating a website and I am looking for a way to manage my styles through Vue. I want to be able to utilize CSS with Vue, as the style of .skill-bar serves as the background of the bar, while .skill-bar-fill represents the green fil ...

Stretch element to reach the edge of the container

I need help with positioning an input and a textarea inside a container that has a height of 52.5vh. I want the textarea to start right below the input and expand all the way to the end of the container. How can I achieve this layout? Both elements should ...

The cascading style sheet used by a lightbox

I constructed a lightbox using the following HTML code: <a id="show-panel" href="#">Show Panel</a> <div id="lightbox-panel"> <h2>Lightbox Panel</h2> <p>You can add any valid content here.</p> <p align="center" ...

Icons will be displayed when hovered over

Is it possible to display icons on hover in a div and hide them otherwise using just CSS? Or do I need to use javascript for this function? Thanks in advance! Example: HTML: <div id="text_entry"> <p>Some text here</p> <span ...