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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:09:42+00:00 2026-06-05T20:09:42+00:00

I am attempting to overlay the comments div element over the main div element

  • 0

I am attempting to overlay the comments div element over the main div element however am unsure of the following;

  1. Is this correct?
  2. Is there a better way to achieve it?

An example of the code can be found at http://jsfiddle.net/fTbP5/

CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type=" content="text/html; charset=UTF-8" />
    <meta http-equiv="content-language" content="en-us" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <meta name="copyright" content="&copy; 2012" />

    <title>sample layout</title>

    <base href="" />

    <link rel="stylesheet" type="text/css"  media="all" href="" />

    <style type="text/css" media="all">

        * {
            margin: 0px;
            padding: 0px;
        }

        body {
            background-color: #eeeeee;
            font-family: Arial, Verdana, sans-serif;
            color: #ffffff;
        }

        #content {
            width: 700px;
            margin-top: 10px;
            margin-right: auto;
            margin-bottom: 10px;
            margin-left: auto;
            border-width: 1px;
            border-color: #ffffff;
            border-style: solid;
            overflow: auto;
            padding-top: 40px;
            padding-bottom: 40px;
        }

        #header {
            font-size: 1em;
            color: #FFC700;
            margin-left: 100px;
            margin-bottom: 20px;
        }

        .main {
            float: left;
            width: 300px;
            height: 300px;
            background-color: #00ACED;
            margin-left: 100px;
            padding: 20px;
            position: relative;
        }

        .comments {
            width: 320px;
            background-color: black;
            position: absolute;
            top: 305px;
            left: 0px;
            padding: 10px;
        }

        .shoutbox {
            float: left;
            width: 100px;
            height: 100px;
            background-color: orange;
            margin-left: 50px;
            margin-bottom: 20px;
        }

        .border {
            border-width: 15px;
            border-color: #ffffff;
            border-style: solid;    
        }


    </style>

    <script type="text/javascript">


    </script>
</head>

<body>
    <div id="container">
        <div id="content">
            <div id="header"><h1>Title</h1></div>
            <div class="main border">
                Hi {Name}, <br /> Your details are.
                <div class="comments">comments</div>
            </div>
            <div class="shoutbox border">shoutbox1</div>
            <div class="shoutbox border">shoutbox2</div>
        </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-05T20:09:43+00:00Added an answer on June 5, 2026 at 8:09 pm

    As I said in the comments above, I think your solution is perfectly okay. Your comments div is nested into main, and absolutely positioned inside it. I see no hack here.

    But that is not the only way to achieve that, and I’ll show you another one, which is a little more flexible. Namely, it makes your main box and your comment box allow variable height contents (while with your current solution, text would overflow outside their containers).

    It’s based on two things:

    1. Another div with class main-contents to wrap the contents. It’s a child of .main
    2. The use of min-height on .main, .main-contents and .comments, to guarantee your original dimensions, but expand down if needed.

    HTML

    <div class="main border">
        <div class="main-contents">
            Hi {Name}, <br /> Your details are.
        </div>
        <div class="comments">comments</div>
    </div>
    

    CSS

    .main {
        width: 340px;
        min-height: 340px;
        background-color: #00ACED;
        margin-left: 100px;
    }
    
    .main-contents {
        padding: 20px;
        min-height: 262px;
    }
    
    .comments {
        background-color: black;
        padding: 10px;
        min-height: 18px;
    }
    
    .border {
        border-width: 15px;
        border-color: #ffffff;
        border-style: solid;    
    }​
    

    To demonstrate that, I have set up a live example showing both your original content, and another block with taller content below it.

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

Sidebar

Related Questions

I am trying to create an overlay for a div. I am attempting to
I am attempting to overlay images on top of a background image using the
I am attempting to draw a custom Drawable overlay on a MapView. I use
Attempting to use the data series from this example no longer passes the JSONLint
I want to try something different, and am attempting to display an overlay on
I am attempting to retrieve jpeg and jpg files using the following statement: string[]
Attempting to compile the following code under Qt SDK 4.7.4 for Desktop - MinGW
I am attempting to generate map overlay images that would assist in identifying hot-spots,
Is there any Lightbox-live or overlay library out there that only provides the basic
Attempting to find printers / shares in Active Directory using C#. This is my

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.