Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7084831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:21:02+00:00 2026-05-28T07:21:02+00:00

I am stuck in a situation where I have a container with a single

  • 0

I am stuck in a situation where I have a container with a single line of text, perfectly centered. Occasionally, the text is longer, and it breaks onto a second line. This throws off the layout, so I need a solution. I am thinking of using jquery to say, “if the number of characters goes above 28 characters, then apply a margin-top of -10px to center the text.”

How would you go about this in jquery? That is, creating a conditional statement that applies rules based on the number of characters? Here is my html, the span class of redstrip needs a margin-top of -10 if the number of characters goes above 28 characters:

<a href="#">
    <img src="images/dummy3.jpg" alt="dummy">
    <span class="redStrip">Here is a bunch of dummy text that is a bit too long</span>
</a>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:21:02+00:00Added an answer on May 28, 2026 at 7:21 am

    While Anthony’s answer is spot on, it’ll only work for singular elements because of the behavior of .text() on jQuery wrapped sets with multiple elements. (i.e. if .redstrip selected more than one DOM element, a simple if wouldn’t cut it).

    Expanding on his answer, you may want to apply a callback filter, or an .each().

    // via filter
    var redStrip = $('.redStrip');
    redStrip
        .filter(function () { return $(this).text().length > 28 })
        .css('margin-top','-10px')
        ;
    
    // via .each()
    var redStrip = $('.redStrip');
    redStrip.each(function () {
        var $t = $(this);
        if ($t.text().length > 28) {
            $t.css('margin-top','-10px');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the situation: I have an ASP.NET MVC 4 application. When I run
I'm being stuck setting up my htaccess properly. Currently I have the following situation
I have been stuck in quite awkward situation in my program. The case is
Being stuck with a legacy database schema that no longer reflects your data model
Kinda stuck here... I have an application with lets say 5000 rows of data
I'm a bit stuck on this. Basically I want to do something like the
I'm kinda stuck with this one so I hoped someone could help me. I
We have a strange situation where we lose a Stateless SessionBean in a Bean
Here is my current situation: I have a web page containing a couple scrollable
I am stuck at the situation where I want the url, which contains a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.