Trouble centering absolute-positioned text within a div, even after implementing the text-overflow property in CSS

Apologies for returning with another question. I recently included a text-overflow: ellipses attribute to my TextCut div in order to truncate the text, however, it caused the content to no longer be centered. Instead of being positioned at the center as intended, it now aligns to the left side. Despite spending an hour trying to resolve it on my own, I am struggling to find a solution. Here is my code once again. Appreciate any assistance provided.

Answer №1

apply the style margin: auto; to the element with ID #TextCut

$(function(){
    $("#TextWrapper div:gt(0)").hide();
    setInterval(function(){
        var current = $('#TextWrapper div:visible');
        var next = current.next().length ? current.next() : $('#TextWrapper div:eq(0)');
        current.fadeOut(500);
        next.fadeIn(500);
    }, 1000);
});
.Border {
    border: 1px solid black;
    display: inline-flex;
    height: 110px;
}
#ImgAndText {
    text-align: center;
}
.Img {
    width: 75px;
    height:75px;
}
#TextWrapper, #TextWrapper1 {
    font-family: Helvetica;
    font-size: 13px;
    padding: 5px 5px 5px 5px;
    position: relative;
    text-align: center;
}
#TextWrapper div, #TextWrapper1 div {
    position: absolute;
    text-align: center;
    left: 0;
    right: 0;
}
#TextCut {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis
    text-align: center;
    width: 50%;
    margin: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<div class="Border">

<div id="ImgAndText"> 
<img src="#" class="Img">

<div id="TextWrapper">
<div>Text</div>
<div id="TextCut">EvenMoreText</div>
</div>
</div>

</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

Nuxt issue: Vue router push not reflecting query updates

Recently, I encountered an issue with vue-router-query. When using a click event to navigate to the filter page and append the URL query to it, there seems to be a problem with updating the query data dynamically. The function responsible for sending the q ...

When using useEffect in React, the handleKeyDown function is causing the output to double with each

Whenever a user inputs something, the output doubles each time, leading to a long loop after just a few inputs. Below is the code snippet: const [direction,setDirection] = useState(Array(1).fill(0)); const directions = ["botNorth","botEa ...

The footer is failing to appear in its correct position on the homepage of the Rails application

My footer looks great throughout my Rails app except for the Home page. Here is the content of my application.html file: <!DOCTYPE html> <html> <head> <title><%= yield(:title) || "Wagon Rails" %></title> <meta n ...

Express encounters difficulties loading JavaScript files

I'm currently working on building an express web app, but I'm encountering a problem with importing a javascript file. Within board.js, there's a line const utility = require('./utility');. However, this line is causing an error: ...

I'm currently facing some issues with switching my navigation bar on and off. I am utilizing the most recent version of Bootstrap, which is v5.1.3

Greetings! I'm new here and still learning the ropes, so please bear with me if I make some mistakes. I'm having an issue with my navbar-toggler not functioning as expected. I've tried various methods like adding older script sources and boo ...

The .env file is functioning properly for the current keys, but any new ones I include remain undefined

Recently, I took over a Vue application that utilizes axios. Within the dataService.js file, it retrieves URLs from a project's .env file using process.env.FOO_BAR for GET requests. The pre-existing key-value pairs such as VUE_APP_DATA_URL function p ...

Removing custom scrollbars using jQuery from an element

Utilizing mCustomScrollbar with jQuery UI dialog boxes. When attempting to initialize mCsutomScrollbar on $(window).load as instructed, it fails because the dialogs are not yet visible. As a workaround, I've had to initiate mCsutomScrollbar on the op ...

How come this 2-dimensional array is adding elements unexpectedly?

I just realized my error where the tempRndNumber was being reset in the inner loop. Although, I am still encountering an issue where "," characters are appearing in the array. The goal is to create a 2D array that is populated only when a random number me ...

What are some ways to remove scroll bars from an iframe?

I'm having trouble with scroll bars appearing in my iframe when inside a fancy box. I have tried everything to remove them without success. For example, you can view the issue here: http://jsfiddle.net/t4j3C/ No matter what I try, nothing seems to w ...

Using a callback function with jQuery in a focus event

Is there a way to ensure that a callback function inside a focus() is only played once while the element has focus? For example, in the code snippet below, the alert('ok') will continue to be triggered as long as the textarea maintains focus. Is ...

"MongoDB Aggregating Data with Nested Lookup and Grouping

I have 3 collections named User, Dispensary, and City. My desired result structure is as follows: { _id: , email: , birthdate: , type: , dispensary: { _id: , schedule: , name: , address: , phone: , u ...

Swap out symbols for pictures

To display the 3 icons, I am using https://boxicons.com/. You can find the code here. Additionally, I would like to download the icons and store them in a folder. Here is the result with uploaded images: https://i.sstatic.net/Qsu9k.png I encountered two ...

Fetch information from the input field and send it to the Redux state

Looking for a solution - I'm working on a simple todo app where I need to store user input value in the redux state. The input value is currently stored in local state until the user clicks the "add" button. The main issue : How can I pass this input ...

At what stage in the code does the loop conclude?

While researching Selenium Webdriver framework best practices on GitHub, I came across the following code snippet: async function waitForVisible(driver, locator, retries = 3) { try { const element = await driver.findElement(locator); ...

Issue in TypeScript: Property '0' is not found in the type

I have the following interface set up: export interface Details { Name: [{ First: string; Last: string; }]; } Within my code, I am using an observable configuration variable: Configuration: KnockoutObservable<Details> = ko.observable& ...

Is there a way to make images load only when the navigation buttons are clicked in a scrollable (jquery tools) rather than loading all images at once?

I came across this great demo tutorial that I'm currently following: The issue with the tutorial is that it loads all the images at once, which significantly impacts performance. My goal is to have it load a set of images each time you click the arro ...

Are your JavaScript scripts causing conflicts?

My bootstrap Carousel was working perfectly fine until I added a script to modify the navigation bars. The original script for the Carousel looked like this: <script> !function ($) { $(function() { $('#myCar ...

No options displayed in AngularJS select2 dropdown

I have implemented select2 in my code following the instructions provided at https://github.com/angular-ui/ui-select2 <div ng-controller="sampleController> <select ui-select2 ng-model="select2" data-placeholder="Pick a number"> < ...

Update with the string before it in a JSON list

Within a JSON file, I came across an array that requires the 'TODO' placeholder to be replaced with the entry above it. To elaborate, the initial "TODO" should be substituted with "Previous question" and the subsequent one with "Next question". ...

Issue with overriding font-family variable in Bootstrap 5 not resolving

I have configured Proxima+Nova font for my Angular application style.css @import url('https://fonts.googleapis.com/css?family=Proxima+Nova'); Attempting to change the root font using bootstrap variables as shown below $variable-prefix: ...