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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:17:54+00:00 2026-06-17T06:17:54+00:00

I have create a jsFiddle to demonstrate my problem: http://jsfiddle.net/MXt8d/1/ .outer { display: inline-block;

  • 0

I have create a jsFiddle to demonstrate my problem:

http://jsfiddle.net/MXt8d/1/

.outer {
  display: inline-block;
  vertical-align: top;
  overflow: visible;
  position: relative;
  width: 100%;
  height: 100%;
  background: red;
}

.inner {
  overflow: hidden;
  height: 50%;
  width: 100%;
  margin-top: 25%;
  margin-bottom: 25%;
  background: blue;
  opacity: 0.7;
  color: white;
}

<div class="outer">
    <div class="inner"></div>
</div>

The thing is that when i need to horizontally center a div inside another.
I specify the height of the inner div in % (eg. 50%) and then the margin-top and margin-bottom to the remaining (eg. (100 – 50) / 2 = 25 %).

But as you see in the jsFiddle it’s not working as intended.

Calculating the margins from the Parent works, but it’s not possible for me, because I dont have access to the div’s parent, as the elements-style object is bound to the object via knockout.js and it’s not so simple as shown in the jsFiddle.

Hope anyone could help me 🙂

bj99

Update:

Just found out why this is actually happening, so I’ll post here for peaple with similar problems:

From http://www.w3.org/TR/CSS2/box.html#propdef-margin-top :

‘margin-top’, ‘margin-bottom’
Percentages: refer to width of containing block

And not as I tought to the height :-/

  • 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-17T06:17:55+00:00Added an answer on June 17, 2026 at 6:17 am

    To #inner element:

    1) Add position:absolute

    2) Remove margin-top and margin-bottom properties

    3) Add top:25%

    That’s it!

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

Sidebar

Related Questions

I have created a sample jsfiddle at http://jsfiddle.net/nair/bv3FG/19/ to demonstrate the problem I am
To explain my question I have created this http://jsfiddle.net/Jams/XNVB2/ here I want when div1
I have created a fiddle to test this : http://jsfiddle.net/Ninjanoel/X6ShS/ which works fine :(
I have created a little example,please have a look, http://jsfiddle.net/bWTwL/ I want to have
I have the following code which is created with a datalist control: http://jsfiddle.net/vmE2E/1/ But
Example to demonstrate the issue can be found here: http://jsfiddle.net/Byyu2/ As you can see
I have the following script: http://jsfiddle.net/oshirowanen/8mQ7x/1/ Which works fine, but as soon as I
I created the following slide show: http://jsfiddle.net/baumdexterous/V8fZr/ I have two questions: I would like
I have created a jsfiddle of my problem. Here is a link to the
Consider this jsfiddle: http://fiddle.jshell.net/maple/JbEJN/show/ (this is the result window, in order for replaceState to

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.