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 6027849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:39:08+00:00 2026-05-23T04:39:08+00:00

I have the following code to generate some spans using cakephp’s helper <div id=numberRow>

  • 0

I have the following code to generate some spans using cakephp’s helper

<div id="numberRow">
    <?php echo $this->Paginator->numbers(array('class' => 'numbers', 'separator' => '', 'before' => '', 'after' => '', 'first' => 1, 'last' => 1)); ?>
</div>

This generates the following code:

<div id="numberRow">
    <span class="current">1</span><span><a href="/posts/show/barter/page:2" class="numbers">2</a></span>
</div>

The problem is that the browser renders a space after the <span> which I do not want.

My solution so far is to write the cake as follows:

<div id="numberRow">
            <span class="current">1</span><span><a href="/posts/show/barter/page:2" class="numbers">2</a></span></div>

with the closing tag on the same row as the <span> but that breaks up the format and makes the source harder to read.

Is there a better way?

  • 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-23T04:39:09+00:00Added an answer on May 23, 2026 at 4:39 am

    Good news! There is a CSS style which is aimed at solving this exact problem. It’s called white-space-collapse, and it looks like this in your stylesheet:

    #numberRow {white-space-collapse: discard;}
    

    In browsers which support it, this will cause white space between tags within the <div> to be dropped if there aren’t any other characters around them.

    Now for the bad news… there isn’t a single browser which supports it yet. 🙁

    The faster moving browsers will probably support it very soon — I’d be willing to bet it’ll be in Chrome at least by the end of the year — but that’s not going to be enough support to make it worth using for some time to come.

    In the meanwhile, this is a common problem which plagues a lot of site designers.

    The most common solution is simply to remove the white spaces from your source code, as per the example you gave in the question. Its not ideal, but it does solve the problem, and without any messy hacks.

    If you’re determined to keep your source code tidy (or you simply can’t avoid it due to a framework you’re using, or whatever), there are a few more hacky solutions:

    First is to use a Javascript string replacement when the page loads to trim out the unwanted spaces. This is messy, but does work, except in the rare occasion when the user has disabled javascript. You may get some page refresh problems as it loads first with the one layout and then immediately resyncs itself to the correct layout, but it’ll probably be minimal (depending on the browser speed and the scale of the problem).

    An even messier solution, but undoubtedly a clever hack, is to set font-size:0; for the parent element (in your case, the <div>), and then set font-size back to the correct size for the content elements. eg:

    #numberRow {font-size:0;}
    #numberRow>span {font-size:12px;}
    

    (replacing ’12px’ with whatever size you happen to want them to be, of course)

    The disadvantages of this are: Firstly, it’s a horrible hack; secondly, it’s a horrible hack; and thirdly, it can make your font sizing difficult to control if you’re using and em-based size layout rather than fixed pixel sized fonts. But it does work.

    All in all, my recommendation is to go with the easy answer, and remove the spaces in your PHP code. At least until the proper CSS solution is in place in most people’s browsers.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used the following code to generate some dynamic checkboxes. This works for
I have some JS code which generates the following object, return { type: some
I have an HTML along the following lines: <div class=hiddenClass> // this implies display:none
I have the following HTML (excerpt from larger code-base) <div class=diary-event ui-corner-all title=[title]> <span
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS site.
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have the following code snippet. $items['A'] = Test; $items['B'] = Test; $items['C'] =

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.