Aligning a div within another div and organizing its elements

Hey everyone, I'm struggling with centering a div that contains two Tumblr posts columns, as shown in the screenshot linked below. I really want it to be centered on the page where there is no sidebar present. Additionally, I'm hoping to get the posts to display in two columns right next to each other without any space between them. Check out the image here: https://i.sstatic.net/VLkkr.jpg

CSS:

        body {
            margin: 0px;
            background-color: antiquewhite;
            text-align: center;
            word-wrap: break-word; 
        }
        body #content {
            width: 900px;
            display: inline-block;
            margin: 15px 15px 15px 15px;
        }
        body #content #wrapper {
            display: inline-block;
            max-width: 900px;
            margin-left: auto;
            margin-right: auto;
        }
        body #content #wrapper #posts {
            display: inline-block;
            background-color: white;
            width: 400px;
            margin: 0 15px 15px 0px;
            padding: 10px;
            float: left;
            text-align: left;
        }
        body .sidebar {
            display: table;
            width: 250px;
            height: 100%;
            position: fixed;
            top: 0px;
            right: 0px;
        }
        body .sidebar .sidebar-inside {
            display: table-cell;
            max-width: 250px;
            margin: 0 auto;
            vertical-align: middle;
        }
        /* etc */

HTML:
<!-- These two columns -->    
    <div id='content'>
    <div id='wrapper'>
    {block:Posts}
    <div id='posts'>
        {block:Photo}
            <!-- Here are posts. -->
    </div>
        {/block:Posts}
    </div>
    </div>
    
<!-- Sidebar -->
    <div class='sidebar'>
        <div class='sidebar-inside'>
        </div>
    </div>

I could really use some assistance, so if anyone has advice or tips, please help me out!

Answer №1

One potential solution using CSS3 Columns: (avoid repetitive use of the id attribute and utilize classes instead)

.content-wrapper {
    -moz-column-count:2;
    -webkit-column-count:2;
    column-count:2;
    -moz-column-gap:405px;
    -webkit-column-gap:405px;
    column-gap:405px;
}

.content-wrapper .posts {
    <strike>float: left;</strike> /*delete this one..*/
    -webkit-column-break-inside: avoid;
    -moz-column-break-inside: avoid;
    column-break-inside: avoid;
}

Edit: User requested additional information.

The reason is that the sidebar is positioned absolutely, so it does not factor into the available space for centering.

Place this just behind </div> from the wrapper
<div class="Gh2"></div>

.Gh2 {
    width: 250px; /*sidebar width*/
    float: right; /*position it to the right where the sidebar is located*/
    height: 1px; /*needs some height..*/
}

Then:

.content {
    /* width: 900px;  deleted those unwanted settings*/
    /* display: inline-block; deleted those unwanted settings*/
    margin: 15px 15px 15px 15px;
}

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 best location for storing buddypress css files?

Recently, I set up buddypress on a fresh WordPress installation and am interested in developing a child theme with personalized styles. Following advice from the buddypress codex, I copied the buddypress theme from plugins > buddypress > bp-template ...

Troubleshooting the issue with padding in CSS not working when using window.print()

I need help creating a footer for my printed pages, but the footer is overlapping the content. I've tried adding padding-bottom to the @page CSS rule with the height of the footer, but it's not making a difference. Any suggestions on how to prop ...

Understanding the distinction between assigning a value and setting text through JSE in Selenium using C#

Utilizing the IJavaScriptExecutor to set the attribute value can sometimes result in the text box containing the set value, but not displaying it as text. In some cases, the input is sent normally to certain text boxes, while for others, it is only setting ...

Utilizing Angular Material for Styling the Web

https://i.sstatic.net/GVcgu.png I am new to working with Angular and currently, I have a sidenav container with the content being a mat toolbar. My issue is that when viewed on a full-sized desktop, the background color of the toolbar stretches and fills t ...

In IOS 9.0, flex items do not wrap to new lines and result in overflow

While it functions properly in other browsers, the issue arises in Safari. I require the flex items to occupy the entire width on screens smaller than 768px. Currently, they are taking up the full width of their container but remaining in a single line, wh ...

Empty area beneath the body in Chrome Device Mode

Can anyone explain why there is a strange blank space under the body tag in mobile view on Chrome (other browsers like Firefox and Internet Explorer display it correctly)? Here is the simple code that I am using: <html> <meta name="viewport" con ...

Is nesting possible with the &:extend function in LessCss?

I've recently been exploring the Less &:extend feature. My goal is to nest multiple extends - essentially extending a class that itself extends another class. However, after testing it out, I'm not sure if it's working as expected. It ...

Center the p tag vertically

To ensure the text inside the p tag aligns vertically in the middle, I've set a specific height for the tag. While this works perfectly for single-line text, it shifts to the top of the p tag when there are two lines of text. It's important to k ...

Revolutionizing Zen Cart with slimMenu

Is there a smarter person out there who can help me understand why the slimMenu is breaking when I add these files to the bottom of the page? <link href="includes/templates/westminster_new/css/age-verification.css" rel="stylesheet"> <script src=" ...

What is the best way to assign a URL to an image source using a JavaScript variable?

I am working on a script that displays different image URLs based on the time of day using an if-else statement. I want to dynamically load these images in an img src tag so that a different picture is loaded for each time of day. I have defined variables ...

Open the iframe link in the main window

As a newcomer to this platform, I am trying to figure out how to make a link open in the parent page when clicking a button within an iframe. Currently, my code opens the link in a new window. <html> <body> <form> <div class ...

What's the best way to enable touch scrolling for items within a div container?

I am in the process of creating a code snippet that will allow users to scroll through items within a div, similar to a spinning wheel or slot machine. While I am aware of an existing solution for iPhone and iPod, I want to develop a simpler, more streamli ...

The troubleshooting of compatibility issues between TailwindCSS and HTML Input and Button tags

Recently, I decided to switch from using plain CSS to TailwindCSS for styling the navbar component that I obtained from the Bootstrap website. While TailwindCSS has helped me style most parts of the navbar successfully, I have encountered a challenge with ...

Angular: Discovering and retrieving all images within a div container

I am on a quest to locate all image tags within a specific div. These image tags are nested within paragraph tags inside the div. I attempted to create a plunkr to accomplish this task, but unfortunately, I haven't had any success yet. If anyone is ab ...

What is the best way to conceal a parent element with jquery?

Let's say we have the following HTML structure: <li class="fooli"> <a class="foo" href="javascript:foo(this);">anchor</a> </li> <li class="fooli"> <a class="foo" href="javascript:foo(this);">anchor</a> ...

Is there a technique I could use to create a visual effect like zooming, but without altering the dimensions of the image?

I'm currently working on a project to develop a photo gallery. let img = document.createElement('img') img.src = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/07/Wikipedia_logo_%28svg%29.svg/1250px-Wikipedia_logo_%28svg% ...

Having trouble retrieving the content within an HTML tag using jQuery?

I'm facing some challenges when it comes to extracting the content of an html tag using the Chrome console. I've been trying different methods for about half an hour, but nothing seems to work. That's why I need some help :) The code I want ...

The username index is not defined in the file path C:xampphtdocsAppX1signin.php on line 6

Experiencing some challenges with a php script I recently created. As a beginner in php, I understand that my code may not be optimal. These error messages are displayed when the form is submitted: Notice: Undefined index: username in C:\xampp&bsol ...

What could be causing my media query to not function properly?

I've been experimenting with some basic media queries but am encountering an issue with the div element that has the class "container." Whenever I adjust the screen size to be between 992px and 1200px, the div disappears from the page. It's perpl ...

Need to adjust the layout of PHP form

Snippet of code: echo "<form method ='post' action='NextFile.cgi'>"; echo "<table>"; echo "<tr><td>Date: </td></td> <input type='date' name='Date' value =".$record['Date& ...