Place 4 divs within 2 divs, with one aligned to the left and the other to the right

I'm currently working on a small project using Angular 2 for an experiment, where I need to place 4 divs, each containing an image, within 2 divs.

However, all the divs (with images) are stacked vertically instead of being placed next to each other, and wrapping to the next row when needed. I am expecting the 'guesser' and 'describer' divs to align as follows: 'guesser' to the left of the vertical divider and 'describer' to the right of the vertical divider, both above the horizontal divider. Unfortunately, they do not occupy the designated area and overflow vertically beyond the horizontal divider.

This is how the website currently appears:

Here's how I envision the website to look (I modified this using Paint, purely for demonstration)

Below is the HTML and CSS for my component:

div.describer {
    text-align: center;
    float: right;
    width: 50%;
    height: 80%;
}

div.describer div.container {
    margin: 1em;
}

div.describer div.container img.blocked {
    padding: 5px;
    border: 5px solid blue;
}

div.describer div.container img.target {
    padding: 5px;
    border: 5px solid red;
}

div.guesser {
    text-align: center;
    float: left;
    width: 50%;
    height: 80%;
}

div.guesser div.container {
    margin: 1em;
}

div.guesser div.container.blocked {
    background-color: black;
    display: inline-block;
}

div.guesser div.container.blocked img.blocked {
    opacity: 0;
}

div.guesser div.container img.selected {
    padding: 5px;
    border: 5px solid red;
    border-radius: 3;
}

div.vertical-divider {
    position: absolute;
    left: 50%;
    top: 10%;
    bottom: 20%;
    border-left: 1px solid gray;
}

hr.horizontal-divider {
    position: absolute;
    left: 5%;
    right: 5%;
    bottom: 19%;
}

div.commands-container {
    position: fixed;
    left: 50%;
    bottom: 10%;
    transform: translate(-50%, 0%);
}
<div class="describer">
    <h3>Describer</h3>
    <div class="container" *ngFor="let icon of icons">
        <img src="assets/icons/{{trialNum+1}}/{{icon}}" [ngClass]="{blocked: icon == blockedIcon, target: icon == targetIcon}">
        <p *ngIf="icon == blockedIcon">Blocked</p>
        <p *ngIf="icon == targetIcon">Target</p>
    </div>
</div>
<div class="vertical-divider"></div>
<div class="guesser">
    <h3>Guesser</h3>
    <div class="container" *ngFor="let icon of icons" [ngClass]="{blocked: icon == blockedIcon}">
        <img src="assets/icons/{{trialNum+1}}/{{icon}}" [ngClass]="{blocked: icon == blockedIcon, selected: icon == selectedIcon}">
    </div>
</div>
<hr class="horizontal-divider">
<div class="commands-container">
    <button (click)="startExperiment()" [disabled]="started">Start experiment</button>
    <button (click)="getNextSet()" [disabled]="!started">Next set</button>
</div>

Despite researching possible solutions on Stack Overflow and attempting to implement them, I haven't been able to resolve the issue.

Answer №1

To arrange the elements side by side, consider utilizing the style "display: inline-block".

Additionally, you can enclose the content in a div and implement a bottom border layout like the one shown below:

UPDATE Enclose the containers within a div using the style display: grid; grid-template-columns: 50% 50%;

        div.describer {
    text-align: center;
    float: right;
    width: 50%;
    height: 80%;
}

div.describer div.container {
    margin: 1em;
}

div.describer div.container img.blocked {
    padding: 5px;
    border: 5px solid blue;
}

div.describer div.container img.target {
    padding: 5px;
    border: 5px solid red;
}

div.guesser {
    text-align: center;
    float: left;
    width: 50%;
    height: 80%;
}

div.guesser div.container {
    margin: 1em;
}

div.guesser div.container.blocked {
    background-color: black;
    display: inline-block;
}

div.guesser div.container.blocked img.blocked {
    opacity: 0;
}

div.guesser div.container img.selected {
    padding: 5px;
    border: 5px solid red;
    border-radius: 3;
}

div.vertical-divider {
    position: absolute;
    left: 50%;
    top: 10%;
    bottom: 20%;
    border-left: 1px solid gray;
}

hr.horizontal-divider {
    position: absolute;
    left: 5%;
    right: 5%;
    bottom: 19%;
}

div.commands-container {
    position: fixed;
    left: 50%;
    bottom: 10%;
    transform: translate(-50%, 0%);
}
div.div-main {
        border-bottom-style: solid;
        overflow: auto;
}
div.grid-containers {
    display: grid;
    grid-template-columns: 50% 50%;
}
<div class="describer">
    <h3>Describer</h3>
    <div class="grid-containers">
    <div class="container" *ngFor="let icon of icons">
        <img src="assets/icons/{{trialNum+1}}/{{icon}}" [ngClass]="{blocked: icon == blockedIcon, target: icon == targetIcon}">
        <p *ngIf="icon == blockedIcon">Blocked</p>
        <p *ngIf="icon == targetIcon">Target</p>
    </div>
    </div>
</div>
<div class="vertical-divider"></div>
<div class="guesser">
    <h3>Guesser</h3>
    <div class="grid-containers">
    <div class="container" [ngClass]="{blocked: icon == blockedIcon}">
        <img src="assets/icons/{{trialNum+1}}/{{icon}}" [ngClass]="{blocked: icon == blockedIcon, selected: icon == selectedIcon}">
    </div>
    </div>
</div>
</div>
<div class="commands-container">
    <button (click)="startExperiment()" [disabled]="started">Start experiment</button>
    <button (click)="getNextSet()" [disabled]="!started">Next set</button>
</div>

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

Transfer information from the ajax success event to an external else/if statement

I am encountering an issue when trying to transfer the appropriate result from my ajax success function to an external function for further use. Currently, I am using user input to query a data source via ajax and receiving the object successfully. The re ...

Updating Variable Values in PHP

Currently, I am working on a project about online shopping using PHP. However, I have encountered an issue regarding changing the currency value. I need to convert the currency to another based on the exchange rate provided. <select onchange=""> ...

Utilize the toString function along with the substring method within an ejs template

I am attempting to showcase an employee's ID by displaying only the last four digits in a table on an EJS page. The data is stored in MongoDB and I am using Express for handling routes. Here is my Express route: app.get('/routehere', async ...

Choosing Nested TypeScript Type Generics within an Array

I need help with extracting a specific subset of data from a GraphQL query response. type Maybe<T> = T | null ... export type DealFragmentFragment = { __typename: "Deal" } & Pick< Deal, "id" | "registeringStateEnum" | "status" | "offerS ...

Pager made the bold decision to transition from a horizontal layout to a vertical format

I've been feeling frustrated lately. After being sick for a while, my customer called to inform me that the gallery pager on their website is broken. Although I managed to fix most of it and restore the original style, I'm struggling to get it t ...

Angular 14 - Issue with passing values through props - Error: Uncaught (in promise): InvalidCharacterError occurs when attempting to set attribute with 'setAttribute' method

I am a beginner with Angular and encountering an issue when trying to pass props from a parent component to a child component. The specific error I am facing is related to an invalid attribute name while using Angular version 14.2.5. core.mjs:7635 ERROR ...

Plot the components of an array and calculate the instances that JavaScript executes

I have an array containing information about PDF files stored in a buffer. Let's imagine this array holds ten PDF files structured like this: [{ correlative: "G-22-1-06", content: <Buffer 25 50 44 46 2d 31 2e 34 0a 25 d3 eb e9 e1 0a ...

SignalR error: A type conversion issue has occurred where it is not possible to directly convert a task returning an object to a string

I'm encountering an issue with my C# hub class where the JavaScript code is returning a System.Threading.Tasks.Task instead of a string. I need help modifying the JavaScript method to return an actual string. Below is the hub class: public String ge ...

Component does not support camelCase names

My current challenge involves creating a navbar component where I need to share some data from the main page to the component. After spending several hours researching how to use components, I have been unable to find an explanation as to why camelCase var ...

Error alert: TypeScript typings issue - Naming conflict with Promise / Failure to locate name Promise

I am currently working on a client/server JavaScript application and I am facing a significant issue with Promises. It appears that they are either undefined or duplicated, and this problem seems to be related to the @types package. npm install --save @ty ...

Call getElementById upon the successful completion of an AJAX request

In the process of constructing a mini quiz, I am utilizing a variable quizScore to store the score. Each question in the quiz is displayed using AJAX. An individual AJAX call captures the ID of the button pressed (for example, on question 2, the button ID ...

Uncovering the Secret to AngularJS Form Validation: Retrieving Controller Values

This is my unique HTML code: <form name="userForm" ng-submit="submitForm()" novalidate> <!-- NAME --> <div class="form-group" ng-class="{ 'has-error' : userForm.name.$invalid &a ...

Transfer the information from dropped files in a div to a separate page

document.getElementById('drag_drop').ondrop = function(event) { event.preventDefault(); var form_data = new FormData(); var drop_files = event.dataTransfer.files; for(var count = 0; count < drop_files.length; count++) ...

Customize the CSS styling of third-party components in different pages using NextJS

When working with third-party components, you can include their styles by importing their stylesheet into your component or _app.tsx file. For detailed instructions on how to do this, you can refer to Next.js documentation. Another option is to add the sty ...

Karma-coverage not detected: however, it is already installed

I utilized the following guide when configuring my Karma-coverage plugin. Additionally, it was locally installed through the package.json file which appears like this: { "name": "myApp", "version": "0.1.0", "devDependencies": { "karma ...

AngularJS approach to binding window scroll

Hey there, I'm a newcomer to AngularJS with a background in jQuery. I'm trying to create a fixed-top navbar using AngularJS that has a background which changes from transparent to opaque as the window is scrolled. Unfortunately, I'm struggli ...

What is causing this code to not produce the expected result of 8.675?

Recently, I encountered a challenge on freecodecamp I managed to write the code successfully, but unfortunately, my browser crashed and I lost all the progress. When I attempted to rewrite the code, it was returning an incorrect answer (a value of 2). I& ...

When using create-react-app, the value of 'process.env.NODE_ENV' can be accessed as either a string or a process object during runtime

Have you come across code that looks like this: if(process.env.NODE_ENV === 'development') { // Perform operations specific to DEVELOPMENT mode } Similarly, you might see process.env.NODE_ENV === 'production. When we run npm run ...

Underline Rows in CSS

When designing my website, I decided to organize the content into rows using CSS instead of tables. To create a line separating each row, I used height:px; for each row manually. However, this method resulted in the line jumping around inconsistently acr ...

Can you incorporate a custom JavaScript function into an ASP.NET AJAX function?

Creating a dynamic webpage, I have incorporated four buttons that toggle the visibility of specific div elements. As part of my design, I want to invoke a custom function before initiating an AJAX request. This function will smoothly animate the current ...