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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:19:01+00:00 2026-06-18T09:19:01+00:00

[edit: clarified that box-sizing: border-box doesn’t seem applicable, since I’m using absolute positioning] The

  • 0

[edit: clarified that box-sizing: border-box doesn’t seem applicable, since I’m using absolute positioning]

The following code illustrates my problem. I’m using absolute positioning, because I found this even trickier with flow-based layout, but I’m open to suggestions. What I want is borders around arbitrary elements, without the borders affecting the positioning of the nodes. (The borders may clip or be overwritten by the content, but that doesn’t matter.)

In particular, the borders of a parent must be able to overlap with the borders of its children, which is not the default behaviour. The CSS box-sizing attribute can be set to border-box to achieve the effect I want, but only (I believe) with inline elements. It has no effect on elements with absolute positioning (as I understand things).

So, my approach has been to use a negative margin to offset the positions of the children by the width of the border. This does indeed seem to cancel out the effect of the border’s presence, but unfortunately not in a way which is consistent across scaling factors. At large scales, things look ok. At the default browser zoom in Chrome, the element positioning goes a bit off (they appear too high); if I go smaller, then the element position goes off in the other direction.

But if I remove the borders entirely, the layout seems to scale ok.

So my question is: is there a reliable (scalable) way to have borders on HTML elements with no impact on the positioning of the elements?

[In the example, I’ve used different colours for some of the borders. I would like to see only black, but at some zooms I can see red and green borders, showing that the element’s position is being affected by the presence of the border.]

thanks
Roly

.bordered {
position: absolute;
height: 18px;
border: 2px solid;
margin: -2px;
}

<span class="bordered" style="width: 55px; left: 30px;">
  <span class="bordered" style="width: 8px; left: 0;">
    (
  </span>
  <span class="bordered" style="border-color: green; width: 47px; left: 8px;">
    <span class="bordered" style="border-color: red; width: 39px; left: 0;">
      <span class="bordered" style="width: 8px; left: 0;">
        5
      </span>
      <span class="bordered" style="width: 31px; left: 8px;">
        <span class="bordered" style="width: 23px; left: 8px;">
          Nil
        </span>
      </span>
    </span>
    <span class="bordered" style="width: 8px; left: 39px;">
      )
    </span>
   </span>
 </span>
  • 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-06-18T09:19:03+00:00Added an answer on June 18, 2026 at 9:19 am

    Try out CSS2 outline property:

    .bordered {
        outline:2px solid blue;
    }
    

    Outline does not affect element position.

    You can also use CSS3 outline-offset as seen here: http://www.css3.info/preview/outline/

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

Sidebar

Related Questions

Edit - clarified I'm trying to implement modular exponentiation in Java using lagrange and
See the following pseudocode snippet that approximates my situation: function foo () { for
I wrote the following pre-commit script for SVN to validate that a user has
I'm creating an application that launches the JVM (using a copy of the JRE).
I'm using the following mysql query to return some data from my database. Currently
I realise that this may seem like a stupid request but I'm going to
I was recently told that using mongodb _id fields in a URL is unsafe.
I'm writing a file translator for my company that grabs data from a source
I am used to using Tomcat/Log4J for my logging. My current project is deployed
I've noticed that some sites (including the old http://careers.stackoverflow.com 1.0) have query strings that

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.