Ways to horizontally align divs on the right and left sides with the CSS ghost element method for achieving vertical centering

My goal was to vertically center two divs within the header section of my website. Here is the code I used:

        <header>
            <div class="block">
                <div class="left">
                    <ul>
                        <li>Home page link</li>
                        <li>Music page link</li>
                        <li>Contact page link</li>
                    </ul>
                </div>
                <div class="right">
                    <ul>
                        <li> Facebook icon code</li>
                        <li> Twitter icon code</li>
                        <li> YouTube icon code</li>
                        <li> PayPal donate button code</li>
                    </ul>
                </div>
            </div>
        </header>

I also included CSS to achieve this:

.block {
    width: 100%;
    height: 90px;
}

/* ghost element */
.block:before {
    content: '';
    display: inline-block;
    height = 100%;
    vertical-align: middle;
    margin-right: -0.25em;
}

.right, .left {
    display: inline-block;
    vertical-align: middle;
}

.right {right: 0;}
.left {left: 0;}

.right li, .left li {
    display: inline-block;
}

.left li {
    font-size: 48px;
    margin-left: 12px;
    letter-spacing: -4.5px;
    text-transform: uppercase;
}

The source for this code can be found at:

http://css-tricks.com/centering-in-the-unknown/

While the code successfully centers one div, I encountered difficulties in getting two divs aligned properly. The current setup has them positioned next to each other on the right side:

Despite reading up on coding and attempting various solutions, I struggled with this seemingly simple problem. Is it possible to align the div with class "right" on the right and the div with class "left" on the left within the ghost element framework?

Answer №2

Give this a shot,... implement it your way

.right {align: right;}
.left {align: left;}

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

Obtain HTML tags from RSS CDATA section

Is there a way to extract HTML tags from a CDATA tag in an RSS feed? I have utilized a basic jQuery function to retrieve the JSON object from the RSS, below is my code: $.get("someURL", function(data) { console.log('InGet'); ...

Link to xpath concept

I am trying to create a hyperlink to a particular spot on a website that I do not have access to edit. Unfortunately, there is no identifiable ID near the location I want to link to, so using <a href="http://example.com/page.html#location"> will no ...

Modify the Calendly widget CSS with a media query to adapt it to different screen sizes

Hey there, I'm new to CSS and I'm struggling with getting rid of the vertical scroll bar that shows up on mobile for a calendly widget. Here's the embed code for the widget: <div class="calendly-inline-widget" data-url="https://cale ...

jQuery allows you to dynamically add a link that can remove a control in a unique

I am facing an issue with generating controls and removing them dynamically. I am trying to include a 'Link' that will trigger a function to remove the dynamically created control. The control and link are placed next to each other. Below is the ...

Utilize Wordpress TinyMCE to apply the underline decoration using the "U" tag instead of the style

Is there a way to modify the function of the button in the WordPress content textarea of TinyMCE? Specifically, I am referring to the "u" button for underline formatting. <span style="text-decoration-line: underline;">text underlined</span> I ...

How can I align 2 images side by side at the top and 1 beside them at the

I'm attempting to recreate an image using Bootstrap to minimize the need for additional CSS. The image I'm trying to replicate can be viewed https://i.sstatic.net/gBaVo.png. I've been struggling with the code and haven't been able to ge ...

Tips for implementing validation in JavaScript

I'm brand new to learning Javascript. Recently, I created a template for a login page and it's working perfectly fine. However, I am struggling with setting up validation and navigation. My goal is to redirect the user to another page if their us ...

Show schedule in an HTML chart

I'm currently working with a table that displays the current status of a request. An example of how the table looks in HTML is shown below: https://i.sstatic.net/daDHy.png The table itself is quite simple, but I am having trouble figuring out how to ...

Is it possible to utilize the onClick event while preserving the use of "this" within the function it triggers?

There is a project with specific needs that require implementation. The task involves adding points to the total score when a button is clicked, without making any changes to the provided HTML code. This requires writing unobtrusive JavaScript code by atta ...

How to effectively manage an overflowing navigation bar

I am currently facing a challenge with the main navigation bar on my website, specifically with how it handles an overflow of links on smaller screen resolutions. I have attempted to adjust the height of the navigation bar at smaller media queries, but I&a ...

Excessive iterations occurring in JavaScript for loop while traversing an array

After addressing the issues raised in my previous inquiry, I have made significant progress on my project and it is now functioning almost exactly as intended. The main purpose of this website is to iterate through the World Of Tanks API to generate cards ...

Retrieve data from a JSON object within an HTML document

How do I display only the value 100 in the following div? <div> {{uploadProgress | async | json}} </div> The current displayed value is: [ { "filename": "Mailman-Linux.jpg", "progress": 100 } ] Here is my .ts file interface: interface IU ...

Print the page becomes distorted when the print button is clicked

Whenever I click on the print button, the page style appears to be improperly formatted in the print view. You can check out the demo here: I've tried various codes found on the internet to solve this issue but none of them have worked for me... Her ...

Is it possible to remove content from a Content Editable container?

JSFiddle <div contenteditable="true"> <p>Trying out editing capabilities of this paragraph.</p> <figure> <img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/ima ...

Tracking mouse positions across an HTML document

I've been working on a project inspired by the voxel painter example on the three.js page. In this particular example, the mouse coordinates are utilized to move a roll-over helper that indicates where a box will be placed upon click. mouse.set((even ...

Explain the usage of Razor syntax when defining the name attribute in HTML

Currently, I am utilizing MVC 5 and Razor 3 to dynamically generate an attribute name in HTML using Razor syntax. Specifically, I am focused on creating a data-* attribute. This pertains to determining the name of the attribute rather than its value. Her ...

What is the best way to merge variable name in AngularJS?

How to combine variable name in HTML code: app.controller example $scope.name ='abc'; $scope.abc123 = response.data; HTML example <h1>{{name}}</h1> <h1>{{{{name}}123}}</h1> <!-- I want the value of abc ...

What is the best way to resize an image to fit a jumbotron in Bootstrap?

I need to fit an image of size 1800px by 200px into a jumbotron so that the jumbotron's size adjusts to fit the image. The jumbotron should also be responsive to different screen sizes. Here is my code: <style> .jumbotron1{ background- ...

The index.html file seems to be missing from the website's current files

I recently bought a Wordpress web template and hired a designer to work on it before uploading it to the site. Now, I want to make some modifications to the site myself. However, despite downloading all the files, I can't seem to locate any folders w ...

creating input type within an ng-repeat loop

I am currently working on a project where I have a series of input fields within different options. These input fields are being added dynamically to my page using ng-repeat. <input type="text"> Each option object contains the type of input field, ...