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

The style of CSS remains constant within the JSP file

Having trouble updating styles on a JSP page using CSS. Here is the code snippet for linking: <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/Profile.css" /> Initially, the styling wo ...

Ways to match a string against a numeric value

I have a span id with textContent which have their own time(hour/minutes) <div class="here"> <span class="time" >8 min</span> </div> <div class="here"> <span class="time" >22 min&l ...

Show the Table and Conceal the Overflow

Currently, I am experimenting with creating an Img hover for entertainment purposes. However, I have added some text to my div. In order to center the text beautifully within my div, I utilized the following CSS code: display: table-cell; vertical-align: ...

Is it possible to create this design using CSS?

I attempted to break away from the conventional square layout of the internet with this design, but I am struggling to utilize Z-index to layer the backgrounds effectively. Here is the current code: <!--############################################# ...

Guide to Indicating an Icon in Front of an HTML Link and Emphasizing Both with Tap

When using an iOS UIWebview, I am facing the issue of needing to add an icon before standalone links that are within a locally loaded HTML file. In addition to adding the icon, I also need both the icon and link to be highlighted when tapped. The desired ...

Adjust the height of a div according to the width using CSS in a progressive manner

I'm looking to create a fluid container that adjusts its height gradually based on the width of the window (as the div's width is set to 100%). Similar to the behavior achieved with the aspect-ratio CSS rule, I want the height to smoothly increas ...

Customize the text color across all sections of the application in ExtJS 6

I am looking to update the text color across my entire application. Currently, it's gray and I would like to change it to black. The platform I am working with is classic. I came across this code snippet in CSS: .x-body { margin: 0; -webkit-f ...

Customizing jQuery dialog: What is the best way to change the appearance of the close button?

I am struggling to style the close tag in my jQuery dialog box. I have looked through the documentation and tried various CSS alterations, but nothing seems to be working. Any suggestions or insights would be greatly appreciated. My code is provided below ...

What is the process for converting x and y coordinates to align with a fixed display?

When I make an API call, I am receiving X and Y coordinates in the following format: x: "-0.0120956897735595703" y: "0.147876381874084473" To display these coordinates on my minimap images, I have set their display to be absolute. The "left" and "top" pr ...

Sliding Image Menu using jQuery

I am struggling with creating a menu using jquery mouseenter / mouseout effects. My goal is to have a small icon displayed that expands to the left and reveals the menu link when a user hovers over it. The issue I am facing is that the effect only works w ...

Arranging images in a row with the help of :before and :after styling

Looking to use the pseudo selectors :before and :after to create a border around a div with images, but running into some issues. The :after image is not positioning correctly on the right side of the element and the text is dropping below the image. Check ...

How far apart are two surfaces when they are rotated along the Y-axis

Access Code: Click here to access the code I am trying to make sure that the red surface lies completely flat on top of the gray surface. However, there seems to be a gap (marked ??) between the two surfaces when I rotate 'modifier1'. How can I ...

Applying inline styles in PHP using if/else conditions

I want to customize the appearance of my table based on the status of each entry. Specifically, Completed = Green & Pending = Orange This involves PHP code that retrieves data from a MySQL database. $query = mysql_query("SELECT * FROM cashouts WH ...

The rendering of the font appears distinct when viewed on an iPad compared to when displayed

Visit this website. The menu displays correctly on desktop, but on iPads, the font appears larger leading to a line break. Is it because the selected font isn't loading and defaulting to Times New Roman instead? It seems likely since I experience the ...

extracting an attribute from a class's search functionality

Let's consider the following HTML structure: <div id="container"> <div> <div class="main" data-id="thisID"> </div> </div> </div> If I want to retrieve the value inside the data-id attribute ...

Is there a way to keep my footer fixed to the bottom of the page in Google Chrome?

I recently made some updates to my aging website by adding a footer menu. However, I encountered an issue with the placement of the footer on Google Chrome. It appears too high, overlapping certain elements of the site. I attempted to resolve this problem ...

Display when moving up and conceal when moving down

Is there a way to make the div appear when scrolling up and down on the page? I'm new to jquery and could use some assistance, please. ...

Modify the styling of the main webpage using the iframe

Can the CSS of a parent page be modified from an iframe when the parent page and iframe are hosted on separate domains? ...

Expansive menu that stretches the full height of the webpage

I'm having difficulty making my side spry menu extend the full length of the webpage. I tried using this code: $("nav").css({ "height" : $("nav").height() }); but it still isn't working as expected. I just want the grey color, like ...

Is it possible to arrange elements in CSS based on their attribute values?

I need to arrange a list of images in ascending order based on the index attribute using CSS. The challenge is that the index values will change dynamically and new images will be added through Ajax, so I want them to automatically update in the correct or ...