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

  • SEARCH
  • Home
  • 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 949017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:20:14+00:00 2026-05-15T23:20:14+00:00

The only solution i have found is ($(this).innerHeight() – $(this).height()) / 2 But /

  • 0

The only solution i have found is ($(this).innerHeight() - $(this).height()) / 2

But / 2 is not right option, because user can have padding-top:0px and padding-bottom:20px.

Is there a way to make more accurate padding values?

I was thinking about css('padding-top') and then parse it, by taking only int part, but value can be in “em” for example and not in “px”

Then make switch statement for each value type? For em one, for px another?

It’s all a bit complicated and takes more space in code…

  • 1 1 Answer
  • 1 View
  • 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-15T23:20:15+00:00Added an answer on May 15, 2026 at 11:20 pm

    One of the main strengths of jQuery is that it is so pluggable, so if you have a need that is not immediately satisfied by the library, there’s a vast landscape of plugins to search. And if there is none that does what you want, it’s really easy to roll your own.
    I think the right way to go here, if you can’t find a plugin that does what you want, is the last one: to write your own.

    However, make sure that you are clear with yourself on the specs of your plugin. What should it return if the element has no css setting for padding? Should it return the styling on this element, or the computed style? What happens for invalid css (say ‘padding-top: 10 unitsThatDontExist;’ or ‘padding-left: two;’)?

    To get you started – this is what using your own plugin could look like in your code:

    var topPadding = $('#anElement').padding('top');
    

    To make that available, just write a plugin like this:

    $.fn.padding(direction) {
        // calculate the values you need, using a switch statement
        // or some other clever solution you figure out
    
        // this now contains a wrapped set with the element you apply the 
        // function on, and direction should be one of the four strings 'top', 
        // 'right', 'left' or 'bottom'
    
        // That means you could probably do something like (pseudo code):
        var intPart = this.css('padding-' + direction).getIntegerPart();
        var unit = this.css('padding-' + direction).getUnit();
    
        switch (unit)
        {
            case 'px':
                return intPart;
            case 'em':
                return ConvertEmToPx(intPart)
            default:
                // Do whatever you feel good about as default action
                // Just make sure you return a value on each code path
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched for a general solution to this but only find answers to
I have only found one other solution but it was incomplete so I need
I've been tasked with maintaining a Visual Studio 2005 solution but I only have
I can only think of a client-side solution using jQuery, but is it possible
The recommended solution is this: config.active_record.whitelist_attributes = true But this only works if you
Is there a method like isiterable ? The only solution I have found so
been doing some research, but haven't found a solution for me. Basically, I have
So far the only working solution I have found is to use: [NSApp setApplicationIconImage:
This issue only exists under IIS5.1. I have found a way of resolving the
How do you create rounded corners with Paperclip? I have found this solution which

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.