Center-aligned text animation in CSS3

My custom text includes a CSS3 animation. Check it out on this fiddle: http://jsfiddle.net/pwLxo78k/

In the animation, one part of the text ("I love") remains static while the other part changes dynamically.

I'm trying to center my text while ensuring that the static part ("I love") stays in place regardless of the length of the dynamic text. Can I achieve this while keeping the text-align: center property on my div?

Thanks!

Answer №1

If you want to achieve a similar effect, consider using tables like this:

<table style="width: 100%">
    <tr style="width: 100%">
        <td style="width: 50%">
            <div id="fixedspan">I adore</span>
        </td>
        <td>
            <div id="movingspan" class="moving">him</span>
        </td>
    </tr>
</table>

To style it properly, use the following CSS:

#fixedspan {
    text-align: right;
}

#movingspan {
    text-align: left;
}

Make sure to replace all instances of span with div for the text-align property. Check out the live example DEMO.

Answer №3

Check out this solution: No need for positioning: CSS:

#divHeader {
    text-align: center;
    width: 100%;
}
#divHeader span {
    display:inline-block;
    width:49%;
}
#fixedspan {
    text-align:right;
}
#movingspan {
    text-align:left;
}

See it in action here:http://jsfiddle.net/pwLxo78k/9/

If you prefer to use positioning. CSS:

#divHeader {
    text-align: center;
    width: 100%;
    position:relative;
}
#fixedspan {
    position:absolute;
    left:40%;
    width:38px;
}
#movingspan {
    position:absolute;
    left:calc(40% + 38px); //adjust the position based on width of "I love"
    margin:0 2px;
}

Try it with positioning here: http://jsfiddle.net/pwLxo78k/6/

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

I encountered a problem when trying to send a list of objects via ajax to my controller - the data was arriving

I've been trying to pass a list of objects in JSON to my controller, but despite the communication appearing to work, the data that I'm passing into my controller is showing up as null. I've gone through numerous posts, all pointing to simil ...

Learn the steps to integrate Infinite Scrolling with Node.js, Angular.js, and Firebase!

UPDATE 8: CODE: <% include ../partials/header %> <script src="https://www.gstatic.com/firebasejs/3.5.2/firebase.js"></script> <script src="https://cdn.firebase.com/libs/firebase-util/0.2.5/firebase-util.min.js"></script> & ...

Customize the appearance of the Vue.js datepicker starting from today's date

I am currently using the vue-datepicker component to display a date input field in my form. I want to set the default date to the current day and disable the selection of past dates. Additionally, I need to change the language of the component but it seems ...

Setting attributes to a DOM element using String in jQuery

I am currently facing a challenge where I have a list of attributes saved as a string variable, and I need to add that variable to a <div>. Unfortunately, I am stuck and uncertain about the best approach. Here is what I have so far: HTML: <div&g ...

What is the best way to organize table rows into a single column when the window is resized?

I am working on a table that has three pictures in a row, with 100% width. I want the table to be responsive and stack the pictures into one column when the space is limited. The issue I am currently facing is that the elements of the table do not stack i ...

Installing different versions of a package in npm can be done by loading multiple versions

I am in the process of setting up a web API and I want to provide support for various versions of the underlying library. In essence, I would like to access it through: where x.y.z represents the version of the library I am utilizing. Using npm for mana ...

The error message I'm receiving is saying that the map function is not recognized for the posts variable (posts.map

I encountered a puzzling error, even though everything seems fine: posts.map is not a function import React from 'react' import { useSelector } from 'react-redux' export const PostsList = () => { const posts = useSelector(state = ...

adding new data rows to an existing data list using Angular

I am currently working on displaying data from a backend system. The data is coming from a table that receives new rows within a specific time frame. To retrieve these new rows, I have set up a mechanism using an Angular timer. My query pertains to the tem ...

Whenever I run my HTML through a server, it doesn't seem to connect with my CSS file

I'm currently developing a Django app, and I have encountered an issue where the CSS is not loading when I run different pages through the server. Oddly enough, everything works fine when I open the files directly without using the server. The problem ...

How to convert an array of keys and an array of values into an array of objects using JavaScript

My question is similar to the one found here: Merging keys array and values array into an object using JavaScript However, I am unable to find a solution for my specific scenario. If I have these two arrays: const keys = ['x', 'y', &ap ...

When a new element is dynamically added to a table cell, how is the computation of "width: 100%" handled?

When utilizing Backgrid for editing values in a table, an <input type="text"> is inserted inside the <td>. Despite setting the input to max-width: 100%, it can still cause the column to expand beyond desired dimensions. To see this behavior in ...

How can NodeJS Websocket (ws) facilitate communication between various clients?

In my project, I have a scenario where client1 needs to share information with client2 and the latter should receive an alert upon receiving it. To achieve this, I am utilizing Websocket "ws" with NodeJS. The web page for client1 receives a response via A ...

Element Not Adjusting to Content Size

I am encountering an issue with my div. I have floated an image to the right and placed my text beside it. My aim is to create a div with a linear gradient, however, the div ends up filling the entire page. How can I make my div adjust to fit only its con ...

Unable to retrieve all AJAX parameters within the MVC Controller

When I make an ajax call to a controller, I am only getting the 2nd parameter. Ajax: return $http({ method: "post", url: "/myform/AddEmployee", data: '{ "EmpDetail":' + JSON.stringify(employee) + ', "File_ID": ...

JavaScript's local storage feature seems to be failing in both saving and retrieving data

I'm working on a fun math game where two random numbers and a sign (+ or -) are generated using Math.random(). The user needs to input their answer in the provided input box. However, I am facing an issue with saving and retrieving the score and high ...

Looking for ways to increase the speed of rendering in the basic window system using HTML5 and CSS3?

Check out these code samples: http://jsfiddle.net/5r3Eh/10/show/ and http://jsfiddle.net/5r3Eh/18/. I've noticed they are running slow on Chrome 12, slightly improved on 13. Is there a way to achieve drag-and-drop functionality for windows without us ...

Issue with Jest while testing a React component library that has been bundled without the React library

I have extensive experience building React applications and decided to create a React Component library. After researching different approaches, I chose to use Webpack and Babel for bundling without including React itself in the library. This decision was ...

Creating files using the constructor in Internet Explorer and Safari

Unfortunately, the File() constructor is not supported in IE and Safari. You can check on CanIUse for more information. I'm wondering if there's a workaround for this limitation in Angular/JavaScript? var file = new File(byteArrays, tempfilenam ...

Creating Instances of a Subclass from an Object in TypeScript

Here is the code snippet I am working with: class MyClass { name: string = "myname"; constructor(public action: string) { } } let obj1: MyClass = { action: "act1" }; The code does not compile and the error displayed pertains to the last line: P ...

Retrieve the JSON item using the item variable

JavaScript: var myObjects = {object1: {name: 'John'}, object2: {name: 'Jane'}}; $('li').click(function() { var liID = $(this).attr('id'); // Returns either 'object1' or 'object2' var desired ...