Exploring Various Alignments within Tailwind CSS

I am facing a layout challenge with three divs: a navigation bar, a webgl player, and a panel. I want the nav bar to be positioned at the top of the screen, the panel aligned to the right-hand side, and the webgl player centered both vertically and horizontally in the remaining space.

While items-center helps with vertical alignment, I have been experimenting with different options for horizontal positioning. justify-between works well for aligning the panel to the right edge, but it also moves the webgl player to the left edge which is not what I want.

Using justify-center centers both elements, but applying place-self-end to the right element did not produce the desired outcome.

Here is a minimal example of the code:

<div class="flex flex-col">
  <div class="bg-green-500 py-12 flex flex-col justify-center"></div>
  <div class="flex flex-row justify-center items-center">
    <div class="bg-blue-500 w-80 h-60 center"></div>
    <div class="bg-red-500 w-80 h-screen "></div>
  </div>
</div>

You can also try it out here: https://play.tailwindcss.com/y3uXkVYcWs

The desired result should look like this: https://i.sstatic.net/QD8qc.png where Green represents the navbar, Blue represents the first div, and Red represents the second div.

Answer №1

After researching extensively, I stumbled upon the solution: Why are "justify-items" and "justify-self" properties missing in CSS Flexbox?

The recommended approach is to remove any instances of justify and items-center, replacing them with margin: auto on the blue element.

HTML

<div class="flex flex-col">
  <div class="bg-green-500 py-12 flex flex-col"></div>
  <div class="flex flex-row justify-center">
    <div class="bg-blue-500 w-80 h-60 center" id="webglPlayer"></div>
    <div class="bg-red-500 w-80 h-screen" ></div>
  </div>
</div>

CSS

@tailwind base;
@tailwind components;
@tailwind utilities;

#webglPlayer {
    margin: auto;
}

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

The function is not functioning correctly for every element within the array

I am currently developing a shopping cart that populates data from local storage. Here is a snippet of the code: var arrayLength = cartarry.length; for (var i = 0; i < arrayLength; i++) { var id = cartarry[i].id; var name = cartarry[i].name; ...

What could be causing this JavaScript code not to run?

Help needed! I'm a student struggling to diagnose the issue in my code. Whenever I click the buttons, nothing happens at all. I've tried debugging by isolating each function, but still can't seem to figure it out. I've searched through ...

The blur function in jQuery is not functioning as expected

I'm facing an issue where only the first of my 3 .blur's is working. Here is the jQuery code snippet: <script type='text/javascript'> $(document).ready(function() { $("#user_name").blur(function() { if ($( ...

What is the best way to create a uniform appearance for all five columns in a bootstrap grid?

My goal is to create a layout with 5 columns on extra large screens, 4 columns on large screens, and 2 columns on small/extra small screens. Currently, my code looks like this: <div class="row mb-5"> {% for item in foobar %} <div ...

Dual scrollbars and a collapsing toolbar

Currently immersed in the development of a photo gallery using AngularJS and Angular Material (expand to fullscreen to observe the issue). var app = angular.module('app', ['ngMaterial']); app.controller('TitleController', f ...

issue with conditional statement in Vue.js

In my Vue.js code, I have implemented a v-if statement wrapped around a template tag that is supposed to display a specific message only when the signup type is a referral. Within this template tag, there are nested v-if statements for further conditions. ...

Animate the movement of a div

Within the given code snippet, the .logo element is initially hidden. The goal is to make it visible upon scrolling, while simultaneously animating the movement of the <ul> element to the right (e.g., sliding). Upon reviewing the demo provided, one c ...

The component next/image is experiencing issues when used in conjunction with CSS

I struggled to create a border around an image because the custom CSS I wrote was being overridden by the Image component's CSS. Despite trying to leverage Tailwind and Bootstrap to solve the problem, my efforts were unsuccessful. Now, I am at a loss ...

Is it possible to retrieve or modify the dimensions and position of an element set in a static position using only JavaScript?

Is it possible to access or modify the coordinates, width, and height of an element that is statically positioned using only JavaScript? If so, how can this be done in both pure JavaScript and jQuery? ...

Launching Website with Google Chrome Extension

As I am relatively new to creating extensions, I decided to start with something simple. However, despite my initial belief that it would not be too difficult, I am struggling to make my extension open new tab pages in incognito mode and normal mode. POPU ...

What is the best way to alter the background of a div when hovering over a button in a separate div?

Looking to change the background of one div when hovering over a button in another div? Hello, I have a task where I need to modify the background color of a specific div when a button below it is hovered over. The setup involves having an image (a tshir ...

There is no value inputted into the file

I'm facing a small issue while trying to retrieve the value from my input of type="file". Here is the code snippet: <tr ng-repeat="imagenDatos in tableImagenesPunto | filter: busquedaDatosPunto " > <td>PNG</td> <td>{{imag ...

Is there a way to collect multiple optional phone numbers dynamically using DOM manipulation?

I have a piece of code here where I am looking to dynamically add additional phone numbers as an optional field. Can anyone help me figure out how to achieve this? <div class="col-12 row border my-2 py-2"> <di ...

Rows with an ambiguous number of horizontal lines

I am looking to create multiple rows that are horizontally floated, as shown in the image. However, I am facing an issue with setting the width of the container because I do not know the exact number of rows that will be added. Currently, my code looks li ...

CSS fixed dynamically with JavaScript and multiple div elements placed randomly

Is it possible to dynamically change the position of multiple div elements on a webpage without reloading? I am looking for a way to modify the top and left positions of several divs, all with the same class, simultaneously. I want each div to have a diff ...

What is the best way to incorporate scripts into the HTML of my Google Apps Script or Google Sheets?

I'm having trouble getting my Apps Script-based HTML to include any scripts. My doGet function for the HtmlService is working fine: function doGet() { return HtmlService.createHtmlOutputFromFile('myhtmlfilename'); } Regardless of whether ...

Aligning the image at the center within a flex container

I am struggling with aligning an image and a link inside a div using the display: flex property. This is how my code looks: <div style="display: flex;"> <div class="site-title-container"> <img style="border-radius: 7px; width: 34px; h ...

Determine the height of the left div, which is set to auto, and apply the same height to the right div, which has overflow set

I am facing an issue that needs a solution. I need to ensure that two div elements have the same height. The left div should have 'auto' height while the right one must match it. Moreover, the right div contains 14 nested divs that need to be scr ...

Ways to assign the value of an alert to an element

Within this piece of code, my intention is to retrieve the alert value and apply it to an element. Description: The AJAX code I have written checks for values in a database, fetches new values from the database, and then displays these fetched values in a ...

A step-by-step guide to implementing Inline Linear Gradient in Nuxt/Vue

How can I create a linear gradient overlay on top of my inline background image? I attempted to add a CSS style but the class seems to be positioned beneath the image. <div class="header__bkgd" v-bind:style="{'background-image': 'url(&ap ...