Is there a way to align a DIV within another DIV such that the space above and below it are evenly distributed?

I need help with the layout of this HTML code:

<div id="outer">
    <div class="content left"></div>
    <div class="content right">
       <div class="fill">
           <div class="blue">
             xxx <br> xxx
           </div> 
    </div>
</div>

This is the CSS used:

 body, html { height: 100%; }
#outer { position:absolute; margin:5%; bottom:0; top:0; left:0; right:0; overflow:hidden; }
.content { position:absolute; width:50%; height:100%; }
.content.left { background-color:yellow; }
.content.right { background-color:red; left:50%; }
.fill { padding: 2em; background-color: green; height: 100%;}
.blue { background-color: blue; }

You can view a live demo on JSFiddle.

My question is how can I adjust the spacing above and below the blue DIV to be equal in height?

Answer №1

Try using the code snippet below:

.blue { 
  position:absolute;
  top:50%;
  background-color: blue;
}

If you need more guidance on vertically aligning content, check out this helpful resource Link

Answer №2

Is your inquiry prompted by the unexpected results you're seeing or a lack of programming knowledge? My reason for asking is due to the oversight of closing the "fill" DIV tag.

If this isn't the issue, consider setting the position to absolute.

.blue{
    position: absolute;
    background-color: blue;
    padding: 10px;
}

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

What is the specified height for the AppBar and Toolbar components in Material-UI?

I'm trying to figure out the exact height being used in this scenario: <AppBar position="static"> <Toolbar> because I'll need that information for a calculation in another component. My current assumption is that it's 64px, b ...

The function of JQuery .click() is successful when used on a local machine, however it is not functioning

I am facing a puzzling issue. The code in question functions perfectly on my local server, but once I uploaded it to my hostgator server, a specific function no longer executes. When I set a breakpoint in the Firefox debugger, I noticed that the function i ...

Issue with spacing between Bootstrap boxes not functioning as expected

Looking to enhance my bootstrap skills, I've created these boxes based on the provided picture. However, I'm having trouble adding white spaces between the boxes as shown in the image. I've experimented with padding and margin but it doesn&a ...

Dynamically generate angular checkbox columns

Struggling to dynamically generate columns of checkboxes in a dropdown using Angular and Bootstrap. Each checkbox item may or may not have related children. The initial solution involved placing everything inside a div (.col-sm-4) from the Bootstrap grid ...

Incorrect implementation of Bootstrap CSS in Jade template

Currently, I am leveraging Express to construct a website. However, there seems to be an issue with my jade template not displaying the bootstrap grid system accurately. Despite double-checking that my app path is correctly set through app.use(express.stat ...

When data is sent to a function through ejs, crucial information becomes accessible on the html page sources

I have encountered an issue where sending data to a function through ejs makes it easily visible in the page source. Could this pose a security risk? Example of code: <a onclick="editDetail('<%=JSON.stringify(data[i])%>')">Edit</ ...

The concept of see-through backgrounds

I am trying to achieve a more transparent header-menu background, so that the YouTube video underneath it becomes more visible. You can check it out here Unfortunately, the trick mentioned above did not work as expected. .masthead:not(.mixed-header) { ...

What is the best way to reset an element to its default state upon clicking a div using jQuery?

I am working on a navigation menu that has a toggle for the drop-down feature. The default state of the toggle is blue, but when the drop-down menu is activated, it turns red. The issue I am facing is that when I click on one of the li items in the menu, ...

Incorporate a particular video directly into HTML code

I'm having trouble embedding a video into my html web page. The video I want to use is located at . I tried using the following code snippet based on the source code of another page where the video is currently embedded: <embed height="100%" width ...

turning every input field's border to red if none of them were filled out at least once

I struggle with javascript and need some help. I have a form with multiple input fields, and I want to ensure that the user fills in at least one of them. I found code that triggers an alert message if the user does not fill in any fields, but I would pref ...

A guide on retrieving values from programmatically created input elements in Java

Here's the HTML code that I am currently working with: <form method="get" action="#" id="startForm"> <input type="text" name="period" id="period" placeholder="The number of days"/> <input type="submit" name="submit" value="subm ...

Does applying a style to an element that already has the same value result in a decrease in performance? Alternatively, do all browsers simply overlook it?

Assuming I have an element with the style top: 5px, and then I execute element.style.top = "5px";, will the browser readjust its position and trigger a layout again? Or does it recognize that there is no need to change anything? (Is this behavior specified ...

Elements that possess identical class attributes yet exhibit dynamic behavior

I'm currently facing challenges with dynamically generated elements. I am working on a page for my website that will show a list of users (data provided by the controller). Each user is represented within a div, containing two h3 tags displaying the u ...

Can you explain how the CSS hack *+html works?

While working on a project, I have encountered multiple rules that look like this: * + html { /.../ } Although I understand the purpose of using * and +, I am unsure about the significance of this particular construction. Additionally, I came across ...

Sending PHP URL parameters results in a 404 error page

I'm facing an issue with an image that is meant to redirect to another page when clicked, along with sending two variables - s and n. echo "<a href='../?change-preference&s=up&n=".$element."'> <img src='..med ...

Deleting a row from a table when a similar element is found in another location

My webpage features a table list that showcases users linked to an organization: <script type="text/html" id="userListTemplate"> <div id="user_list_box"> <table class="list" style="margin-bottom: 15px;"> {{#Users} ...

Move the HTML5 range input arrow to the top left corner

Currently, I am utilizing the HTML5 input="range" feature. However, the default setting has the arrow positioned in the middle, and I would like it to start from the left instead. The code snippet that I am using is as follows: <input id="test" type= ...

I'm looking for a tool that can convert Flash/Flex AS3 TextLayoutFormat data into HTML and CSS

I have been tasked with converting a flex app into HTML and CSS. The existing app relies heavily on TextFlow for content layout, requiring precise positioning within a few pixels. The current data structure looks like this: <p paragraphstartindent="0" ...

What is the best way to make two divs appear side by side without causing the content below to shift as well?

I am trying to figure out how to position the Creams element underneath the "Name" section in my HTML setup. I have the following code: <h4 class="wrap-title">Name</h4> <button class="btn btn-primary btn-xs title-button" ...

The action of Document.write results in the page being overwritten only a single time

I have come across an issue while using document.write() to update html content loaded by AJAX. When used only once during a regular page load (without AJAX), it functions correctly, replacing the existing content. However, if used multiple times, it appen ...