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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:17:27+00:00 2026-06-06T09:17:27+00:00

I have two divs one inside another. I have given some border to both

  • 0

I have two divs one inside another. I have given some border to both the divs and I want both the divs to be in the center with respect to the page both horizontally and vertically. I have seen the solutions to similar question but couldn’t solve my problem. Please also share good resources from where I can learn about the positioning i.e relative absolute in depth.

Below is my HTML code:

<!DOCTYPE html>
<style type="text/css">
    .outer {
        color:black;
        width: 400px;
        height:400px;
        border: 100px solid;
        border-radius:100%;
        border-color: red blue green yellow;
        position: static;
        margin: auto  auto auto auto;
        top:50%;
    }
    .inner{
        color:black;
        width: 100px;
        height:100px;
        border: 50px solid;
        border-radius:100%;
        border-color: red transparent green transparent;
        position: relative;
        top:50%;
        margin: -50px auto auto auto;
    }
</style>
<html>
    <body>
        <div class="outer">
            <div class="inner">
            </div>
        </div>
    </body>
</html>
  • 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-06T09:17:28+00:00Added an answer on June 6, 2026 at 9:17 am

    IF you know the sizes of both boxes, and they won’t change, you can use this:

    .outer {
      color:black;
      width: 400px;
      height:400px;
      border: 10px solid;
      border-color: red blue green yellow;
      position: absolute;
      margin: -200px  auto auto -200px;
      top:50%;
      left: 50%;
    }
    .inner{
      color:black;
      width: 100px;
      height:100px;
      border: 5px solid;
      border-color: red transparent green transparent;
      position: absolute;
      top:50%;
      left: 50%;
      margin: -50px auto auto -50px;
    }​
    

    Note I took out the border radius and narrowed the border size to make the point clearer.

    Basically, you can use absolute positioning with relative units (%), but use a fixed negative margin that is half the size of the box.

    See the JS Fiddle

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

Sidebar

Related Questions

I have two divs inside another div, and I want to position one child
I have two divs, one inside the other, and i want block the inside
I have two divs, both with position:absolute; , one inside the other. The parent
I have two divs one inside another, i would like to overlap one div
I have two divs one inside of the other, now i want to put
I have two divs inside a div, I want them both adjacent to each
I have a simple page layout with two divs--one on top, and one on
I have two divs, one nested inside of the other. The parent element has
I have two divs (one inside of the other) and am running into a
I have two divs inside a container div. One need to float left the

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.