Aligning items in the center using the flex property is limited to just one element

#draggable-container {
    margin: 0 auto;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
}

.draggable-game-content {
    width: 100%;
    height: 40rem;
}

.draggable-game {
    position: relative;
    border: 1px solid black;
    border-radius: 25px;
    margin-left: 1.5rem;
    height: 38rem;
    text-align: center;
}

#menu-container {
    width: 4rem;
    height: 30rem;
    border: 1px solid #000;
    border-radius: 15px;
    position: relative;
}

.menu-list {
    position: absolute;
    left: 25%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.menu-item {
    display: block;
    margin-bottom: 1.5rem;
    border-radius: 50%;
    border: 1px solid #000;
    height: 2.5rem;
    width: 2.5rem;
}

.menu-item:nth-child(2) {
    margin-bottom: 7rem;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cdafa2a2b9beb9bfacbd8df9e3fbe3fd">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
    <div id="draggable-container">
        <div id="menu-container">
            <ul class="menu-list">
                <li class="menu-item"></li>
                <li class="menu-item"></li>
                <li class="menu-item"><a href="/draggable/gameinfo">info</a></li>
                <li class="menu-item"><a href="/draggable/gamesettings">settings</a></li>
                <li class="menu-item"><a href="/draggable/gameachievements">achievements</a></li>
            </ul>
        </div>
        <div class="draggable-game-content">
            <div class="draggable-game">test</div>
        </div>
    </div>
</div>

My React-generated page seems off as the 'test' div remains elevated while the menu shifts downwards.

I strive for them to be at equal levels, just like this: https://i.sstatic.net/vzSqh.png

My initial plan was to use align-items:center to vertically center both elements and have them start from the same point, however, it proves ineffective.

Why is my strategy flawed and what adjustments can I make to mirror the desired layout?

Answer №1

Your align-items property needs to be set as flex-start

#draggable-container {
    margin: 0 auto;
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
}

Answer №2

#draggable-container {
    margin: 0 auto;
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start; // modified this line only
}

.draggable-game-content {
    width: 100%;
    height: 40rem;
}

.draggable-game {
    position: relative;
    border: 1px solid black;
    border-radius: 25px;
    margin-left: 1.5rem;
    height: 38rem;
    text-align: center;
}

#menu-container {
    width: 4rem;
    height: 30rem;
    border: 1px solid #000;
    border-radius: 15px;
    position: relative;
}

.menu-list {
    position: absolute;
    left: 25%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.menu-item {
    display: block;
    margin-bottom: 1.5rem;
    border-radius: 50%;
    border: 1px solid #000;
    height: 2.5rem;
    width: 2.5rem;
}

.menu-item:nth-child(2) {
    margin-bottom: 7rem;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9dfff2f2e9eee9effceddda9b3abb3ad">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
    <div id="draggable-container">
        <div id="menu-container">
            <ul class="menu-list">
                <li class="menu-item"></li>
                <li class="menu-item"></li>
                <li class="menu-item"><a href="/draggable/gameinfo">info</a></li>
                <li class="menu-item"><a href="/draggable/gamesettings">settings</a></li>
                <li class="menu-item"><a href="/draggable/gameachievements">achievements</a></li>
            </ul>
        </div>
        <div class="draggable-game-content">
            <div class="draggable-game">test</div>
        </div>
    </div>
</div>

Answer №3

To adjust the alignment of your items in Flex, make sure to utilize the align-items property.

If you want to learn more about Flex and its various properties, check out this informative guide.

#container-drag {
    margin: 0 auto;
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
}

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

How to Change Background Color to Black for a PNG Image Using CSS in Ionic

When applying CSS in Ionic, I encountered an issue with the background image causing the background to turn black. Without the image, everything looks fine. ion-content { --background: url("/assets/product_background.png") 0 0/100% 95% no-re ...

Tips for designing a search bar using Angular

search : ____________ I am interested in designing a search bar functionality that automatically triggers when the user inputs 8 or more characters. The input text will be stored in a variable, the search bar will be reset, and the backend API will be che ...

What could be causing bootstrap to suddenly stop working?

Running bootstrap on React and using Storybook to view it has been a smooth process until today. The code that worked flawlessly on Friday is suddenly not working at all. Despite trying it on Jsfiddle and onecompiler, the carousel component copied from the ...

Leveraging $this in conjunction with a jQuery plugin

I'm experimenting with a code snippet to reverse the even text in an unordered list: $(document).ready(function () { $.fn.reverseText = function () { var x = this.text(); var y = ""; for (var i = x.length - 1; i >= 0; ...

How about using a circle inset clip path technique?

Can a unique inset circle clip path be created to cut a hole through the center of a div instead of just showing the center? The entire div should be visible except for a hole cut out in the center to achieve a design similar to this: https://i.sstatic.n ...

In Bootstrap 4, the positioning of :after is different compared to Bootstrap 3

Our bootstrap nav-tabs have a unique default look with an 'indicator' icon below the selected tab. This is achieved by styling the active anchor element as follows: https://i.sstatic.net/UQos5.png However, when migrating to bootstrap 4, we noti ...

Enhance the CSS styling for the React-Calendly integration in a React project

I am trying to customize the CSS of an Inline Widget called React Calendly. I have attempted to use React Styled Component Wrapper, Frame React Component, and DOM javascript but unfortunately, the design changes are not reflecting as desired. Specifically, ...

How can I remove HTML tags from a string using .NET?

Does anyone know of an efficient way to strip HTML tags from a string of HTML text? ...

Creating a clickable link that dynamically updates based on the span and id values, and opens in a new browser tab

I am attempting to create a clickable URL that opens in a new window. The URL is being displayed and updated on my HTML page in the following manner: Python Code: def data_cb(): return jsonify(waiting=await_take_pic()) Javascript Code: jQuery(d ...

Tips on aligning two divs horizontally on the same line

doc.html .column { background-color: orange; width: 75%; vertical-align: top; display: inline-block; height: 200px; } .nav { vertical-align: top; display: inline-block; width: 25%; background-color: lightgreen; height: 200px; } * { ...

Incorporate zoom feature into the jQuery polaroid gallery

Currently, I am utilizing a jQuery and CSS3 photo gallery found on this website. My goal is to allow the images to enlarge when clicked, however, the method provided by the author isn't very clear to me, as I'm not an expert in jQuery. I attempt ...

Automatically set the margin for the initial element with flex-grow

In the scenario presented, there is a navigation structure utilizing two flexbox containers. The flex-grow property allows the navigation to stretch and fit the main wrapper, which in this case has a width of 100%. Here is the HTML code: <!DOCTYPE htm ...

Can you provide an example of JSON for a MultiStep Form that includes a variety of control types for viewing

Could someone please provide me with JSON examples of multi-step forms that include various types of controls such as radio buttons, checkboxes, dropdown menus, and calendars? I am in need of JSON for both the view and edit forms. Your help would be grea ...

Is it possible to rotate a group within an SVG without altering the orientation of the gradient fill it contains?

In my search on SO, I came across a lot of information about rotating gradients. However, my issue is the opposite. I have an icon created from multiple paths that I want to fill with a vertical gradient. I have successfully done this and it works well. ...

Error displayed inline

I am facing an issue with a hidden textbox that I need to make visible based on a certain condition. Despite checking that the control is being triggered by the change event, I am unable to get it to display. I have experimented with different methods with ...

Trouble arises when trying to define the style for an element generated through the Document

I'm having trouble setting the style for a 'tr' element created using DOM within JavaScript. Here's the code snippet: var tr = document.createElement("tr"); tr.onmouseover=function(){this.style.backgroundColor='#fbf9e0';}; ...

R: Extracting data from web pages: The content appears to be formatted in XML but is not recognized as such; employing HTML

Working on scraping data from multiple years which are represented by different webpages. I have successfully extracted the 2019 data as expected, but encountering an error while attempting to preprocess the 2016 data in a similar manner. url19 <- &apos ...

Having trouble applying CSS to SVG icons from defs file in Webkit Browser

I've been tinkering with a project that incorporates SVG icons, hoping to style them using CSS for various scenarios and hover effects. However, my attempts are falling short in Webkit, while Firefox is displaying the icons as intended: http://codepe ...

How to use AJAX to pass a JavaScript variable to a PHP script for storage in a database

My Objective: I currently have an HTML5 game integrated into my website. You can check out the game here. Now, I want to add a feature that records and displays high scores for this game on the same page. For instance, let's say I play the game as "C ...

After the automation is finished, I am interested in outputting the IMDB rating of a movie or series to the terminal

I prefer using Google search to find the element because I find it easier to navigate compared to IMDB. import selenium.webdriver as webdriver print("This script is designed to retrieve the IMDb rating of a movie or TV series!!!") def get_results(search_ ...