What is the reason behind CSS absolute positioning consistently being bound to the document body instead of the containing div?

Need help with HTML/CSS formatting.

The webpage size is set to 1000 pixels by 1000 pixels and enclosed within a box. To aid alignment, I've added a temporary solid black border around the elements that will be hidden later on. The layout consists of an image at the top left (#Logo), followed by a div box (#Upper_Left) positioned next to the logo.

I am looking to utilize absolute positioning to align content with the top or bottom edge of the #Upper_Left div. Specifically, I want the h1 title to be at the top of the box and some text ["Search:____________[drop][drop]" - as a placeholder for a search bar] at the bottom-left corner of the div box. However, in my code, the "Search:____________[drop][drop]" text appears at the bottom left of the browser window instead of inside the #Upper_Left div.

How can I ensure the text is positioned relative to the div box?

<!DOCTYPE html>
<html>
    <head>
        <title>Title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            * {
                margin: 0px;
                padding: 0px;

                -webkit-box-sizing: border-box;
                -moz-box-sizing: border-box;
                box-sizing: border-box;
            }
            * {
                border-style: solid;
                border-color: black;
                border-width: 1px;
            }
            #Entire_Page {
                max-width: 1000px;
                max-height: 1000px;
                min-width: 1000px;
                min-height: 1000px;
            }
            #Logo {
                float: left;
                width:104px;
                height:118px;
            }
            #Upper_Left {
                display: inline;
                float: left;
                max-width: 500px;
                max-height: 118px;
                min-width: 500px;
                min-height: 118px;
            }
            #Title {
                display: inline;
                font-size: 3em;
            }
            #bottom_left {
                position: absolute;
                bottom: 0px;
                left: 0px;
            }
        </style>
    </head>

    <body>
        <div id="Entire_Page">
            <img id="Logo" src="logo.png" alt="logo">
            <div id="Upper_Left">
                <h1 id="Title">Title (Up Top)</h1>
                <div id="bottom_left">
                    Search:____________[drop][drop]
                </div>
            </div>
        </div>
    </body>
</html>

Answer №1

Make sure to include position: relative;.

 #Top_Left {
   position: relative;
   display: inline-block;
   float: left;
   max-width: 600px;
   max-height: 130px;
   min-width: 600px;
   min-height: 130px;
  }

http://codepen.io/user/pen/yXbKlW

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Changing URL Links to Plain Text with Regular Expressions

When sending an email from my application, I am primarily using HTML format and applying a regex to remove the HTML tags for a plain-text alternative view. (using @"<(.|\n)*?>"). My goal is to substitute the <a> hyperlink tag with a plain- ...

The issue of the background image not displaying correctly within a Bootstrap container arises

I'm having trouble adding a background image to my website using Bootstrap 4 and external CSS (internal CSS isn't working for me either). I want the background image to be behind all rows in a container, not just behind one specific row. Could ...

Guide for using a CSS variable in a dynamic CSS class within a dynamic component

I'm working with library components and running into an issue with CSS when importing the same component multiple times within a parent component with different styles. import "../myCss.css" const CircleComponent = ({size , color}) => { ...

Employing forward slashes as the template delimiter in JavaScript for HTML

let a = 1.10; let html = '<div>'\ '<strong>' + a + '</strong>\ //error here </div>'; console.log(html) Can you identify the issue in the code above? The intention is to insert a variab ...

Guide to reactivating click functionality on a div using jQuery

Here is the code snippet in question: if ($selector.html().indexOf("radio") > 0) { if ($oldSelected != null) { // enable clicks on old selected radio button $oldSelected.children().bind('click', function ( ...

Tips on aligning text vertically within a Bootstrap table

My goal is to vertically align the text in the center of its row within a bootstrap table, regardless of its length. I've been trying to achieve this using vertical-align: middle; line-height: 90px;. Adjusting the line-height seems to work for center ...

Tips for redirecting a HTML page to two different pages by utilizing two separate buttons:

To link to another HTML page, you can use the code below triggered by a button click: <form action="where-you-want-to-go"><input type="submit"></form> However, I am encountering an issue. How can I direct two different buttons on the sa ...

Monitoring WooCommerce order submissions through AJAX

I'm exploring the world of Ajax for the first time. My goal is to submit an order tracking form and show the results using AJAX. I attempted to use Ajax to display the results within div track_result. The issue I'm facing is that the following ...

Guide on invoking a JavaScript function within a jQuery upon a specific event, such as clicking a hyperlink

I have a website page where I display some important information. However, I want to make this text hidden initially and only visible when a user clicks on a specific link or button. I attempted to achieve this functionality using the following code snippe ...

Something went awry when I tried to divide the HTML and CSS code

<div class="col-md-12" style=""> <div class="col-md-4 linkdetail" class="cursor"> <div class="col-md-12" style="margin-bottom:40px"> <img src="/img/product3.png" style="display:inline-block;width:100%;"> </div ...

Developing customized tools for twitch broadcasters

While exploring the world of streaming, I stumbled upon various widgets like chatboxes and follower goals that piqued my interest. Now, I'm eager to create my own versions. One standout example is the streamlabs widgets. You can tweak the HTML/CSS/JS ...

What causes Bootstrap 5 cards to malfunction when containing scrollable content?

To help explain the issue I'm facing, I created a demonstration on CodePen: https://codepen.io/ganakim/pen/jOKmByM Despite setting overflow-y: auto for column 1, it is not scrolling as expected. Instead, it is causing the footer to extend beyond the ...

Error encountered while attempting to execute query: SQLSTATE[23000]: Violation of integrity constraint: 1048 Unable to input data into column 'membersince' due to null value

I am facing an issue where my query failed to run due to an integrity constraint violation with the error message - "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'membersince' cannot be null." The problem occurred when I attempte ...

Using HTML5 and CSS to embed a video tag within a div container

I am currently using the Bootstrap modal plugin and I would like to incorporate a background animated mp4 video. How can I achieve this within the modal dialog where the video will be displayed from top to bottom? Below is the HTML code I have: <div cl ...

Convert the string to a time format of hours and minutes (hh:mm)

I am currently working with an input field that requires a time value to be entered. The format for the Time field is in hh:mm on the 24-hour clock format, such as 7:30, 11:45, 16:10, 19:11, or 22:43. <input id="szReminderTime" type="text" value="" max ...

Obtaining varied outcomes while printing filtered information

As a beginner in React.js using hooks, I prefer to learn through hands-on coding. My query revolves around fetching data from a specific URL like ksngfr.com/something.txt and displaying it as shown in the provided image (I only displayed numbers 1-4, but t ...

What is the best way to apply fading effects to three divs containing additional divs?

Looking at this HTML and CSS code: HTML <DIV class="newsPic"></DIV> <DIV class="newsPicTwo"></DIV> <DIV class="newsPicThree"></DIV> CSS .newsPic { width: 500px; height: 200px; } .newsPicTwo { width: 500px; height: 2 ...

Issues with Image Placement in Internet Explorer

My cat image on my website appears significantly lower than all the other images when viewed on Internet Explorer (v11). While it looks perfect in Chrome, I cannot figure out why this discrepancy exists. For the development of this website, I utilized pred ...

`Can you provide some tips on keeping the MetroCSS label continuously visible?`

Within the input-control, there is a label: <div class="input-control modern text" data-role="input"> <input name="salle_lib" id="salle_lib" type="text" maxlength="70" placeholder="libell&eacute;" data-validate-func="required" data-valida ...

Create a dynamic HTML page using JavaScript

When I click on the following links: How can I create a new page using JavaScript? Create and dynamically append elements I'm looking to dynamically add HTML elements with JavaScript within a div, but I don't want my code to become overly comp ...