What is preventing me from translating an element using transform: translateY()?

I attempted to move the letter 'h' down by 40px on its own, but the translation only seems to work if I relocate the entire word. I also experimented with positioning 'h' absolutely relative to the parent element, but then 'ello' loses its original position.

HTML

<div class="container">
  <span class="word">
    <span class="character first" style="transition-delay: 0s;">h</span>
    <span class="character" style="transition-delay: 0.025s;">e</span>
    <span class="character" style="transition-delay: 0.05s;">l</span>
    <span class="character" style="transition-delay: 0.075s;">l</span>
    <span class="character" style="transition-delay: 0.1s;">o</span>
  </span>
</div>

CSS

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  width:100vw;
  height:100vh;
}

span {
  font-size:60px;
}

.word {
  border-style: solid;
  border-color: coral;
  display: inline-block;
}

.first {
  transform: translateY(40px);
}

Answer №2

To apply the transform property on a span, you can either add "display: block" to the element or simply use a div instead.

.first {
    transform: translateY(40px);
    display: block;
}

OR

<div class="container">
  <div class="word">
    <div class="character first" style="transition-delay: 0s;">h</div>
    <div class="character" style="transition-delay: 0.025s;">e</div>
    <div class="character" style="transition-delay: 0.05s;">l</div>
    <div class="character" style="transition-delay: 0.075s;">l</div>
    <div class="character" style="transition-delay: 0.1s;">o</div>
  </div>
</div>

Answer №3

Revise the CSS properties of your span element as shown:

span {
  font-size: 60px;
  display: inline-block;
}

Answer №4

The correct term for the category is not used by you

#word-j {
   transform: translateY(60px);
}
<span id="word-j" class="character second" style="transition-delay: 0.5s;">j</span>

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

Utilizing JSP to trigger a servlet upon loading without the use of script

Is there a way to automatically call a servlet when my JSP page is loaded? Currently, I have a link like this: <a href="ContentServlet?action=userContents">Homepage</a> However, I would like the servlet to be called without having to click th ...

HTML directory selector

As a beginner in HTML, I have a file available for users to download: <a href="filetodownload.exe" download>Download</a> By default, the file is downloaded to the Downloads directory. Is there a way to prompt the user with a dialog b ...

Tips for adjusting div content to fit a fixed height on all devices

Looking to adjust the size of the #left-content div based on the height of the window, while ensuring that all content is visible within the fixed #left-bg. However, when viewing on mobile or tablet devices, the content appears hidden. .left-bg{ backgro ...

Unable to modify the selector to "Remove preview files" on click in PHP and JavaScript

During the process of uploading multiple files (using <input type="file" multiple/>) with preview image file and successfully removing the image preview and file data, I encountered a problem. The issue arises when attempting to change the selector ...

What could be causing the whitespace around this element when using SASS from Refills / Bourbon.io?

I've recently started using the impressive SASS framework, Boubon.io created by the talented team at thoughtbot. As I experiment with their supplied templates (known as Refills), I'm finding that Bourbon.io serves as a versatile alternative to po ...

The PHP-based registration process is malfunctioning

Trying to simply register, but I'm encountering an issue where the file is named Login.html/.php instead of just Login.html. Below is my HTML form in Login.html: <!DOCTYPE html> <html> <head> <title>Register/ Login</title&g ...

Unable to Scroll HTML Division

At the moment, I am working on a new website. I have a div where I place images and overlay text on them to describe the images. The issue I am facing is that the text does not scroll even though the scroll bar is visible. This is my HTML: <!DOCTY ...

Using Javascript and JQuery to create an alert that pops up upon loading the page is not effective

I am having trouble making an alert show up when my website loads. The Javascript code is functional when directly included in the HTML, but once I move it to a separate file named script.js and link it, nothing happens. Can someone please help me identify ...

Is it possible for me to adjust these two images to fit the screen perfectly?

Technologies: CSS React JPG/PNG Objective: I am striving to resize two images to achieve this desired look: https://i.stack.imgur.com/B1b0h.png I am currently developing a 'skirt customizer' for either my mom or portfolio, where users can m ...

Instead of being arranged vertically, the tables are positioned horizontally on display

I am attempting to generate a table using PHP and HTML that pulls data from a MySQL database. The issue I'm facing is that the data is appearing horizontally rather than vertically. if (isset($_POST['winneron'])) { echo "<tr>"; ...

Learn the process of setting a timestamp using this PHP script

I have a script that retrieves data based on selected dates, but I want to modify it to work with timestamps instead. <link rel="stylesheet" type="text/css" href="tcal.css" /> <script type="text/javascript" src="tcal.js"></script> <fo ...

Guidance on transferring servlet variables to an HTML page through redirection in Java

I am looking for a way to open an HTML page from my Java servlet and utilize the variables of that servlet to populate the form fields in the HTML page when it is opened. Below is the code snippet of my servlet: import java.io.*; import java.sql.*; impor ...

Tips for organizing the data you have collected from the table

After successfully printing all the data from my database, I am facing a challenge in designing my data effectively. The table I am working with is called post_tbl and it has columns named post_id, post_message, and post_date. This is the query I am usin ...

Do you believe that using bower to install HTML5Boilerplate is a beneficial decision?

Is it recommended to use HTML5 Boilerplate with Bower for installation? What steps should one take afterwards, considering that it has its own directory structure for CSS and JavaScript, leading everything to be contained under bower_components/html5boil ...

Creating a sleek CSS animation for a slot machine effect: Ensuring it stops smoothly and at a specific time limit

I'm working on creating a CSS animation that mimics a slot machine, but I'm struggling to achieve a smooth transition. .scrollable { height: 150px; width: 150px; margin: 0 auto; padding: 0; background: #000; ...

What is the best way to distinguish between a button click and a li click within the same li element

In my angular and css GUI, each line is represented as an li inside a ul with a span. The functionality includes a pop-up opening when clicking on the li background and another action occurring when pressing the button (as intended). The issue arises when ...

Why is my navbar not functioning properly with Bootstrap 5 and HTML?

My navigation bar suddenly stopped working and now my background image, text on the background image, and navigation have all turned white after I added links to different hrefs. I'm also using bootstrap 5. The only thing I can see is from my id citat ...

The iframe remains unresponsive and fails to resize as needed

I am facing an issue while trying to embed an iframe into one of my websites. It seems that the responsiveness is lost and it does not scale properly on mobile devices. You can see the issue here. Interestingly, when I place the same iframe on a plain HTM ...

Assigning a class to every alternate item

Currently, I am in the process of compiling a list of products. To enhance the layout, I would like to assign a specific class to every other element. This class could be :before, :after, or simply .My-clas <div class="product-single"></div> ...

Navigating through sibling elements can be accomplished by using various methods in

Can someone help me figure out how to assign unique IDs to 6 different Div elements as I step through them? The code snippet below is not working as expected, giving all Divs the same ID. What is the correct way to accomplish this task? $('#main-slid ...