The container is not adjusting to the screen size correctly and the flex-direction: row is not functioning as

Struggling with setting up a basic layout in Angular for my application. While I have experience with Angular, the actual HTML/CSS design is new to me.

No matter what I try, I can't seem to get this container to take up the whole screen width. Various settings on the html and container CSS classes just won't make the container fit the screen horizontally, even though it fits vertically just fine.

Additionally, the flex-direction: row property doesn't seem to be working consistently. I'm attempting to make the "side" and "main" divs inside the header div sit next to each other but they keep displaying as columns instead of rows. Despite using nowrap and inline-block display properties, the alignment just won't work. I've also tried reducing the widths of side and main hoping they would align properly, but that hasn't helped either.

Screenshot: Full View

html {
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
}

.container {
  position: relative;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  border: 1px solid black;
  display: flex;
  flex-direction: column;
}

.header {
  margin-top: 15px;
  border: 1px solid red;
  height: 15vh;
  flex-direction: row;
  flex-wrap: nowrap;
}

.body {
  border;
  1px solid green;
  height: 80vh;
}

.side {
  width: 15vw;
  border: 1px solid yellow;
}

.main {
  width: 50vw;
  border: 1px solid blue;
}
<div class="container">
  <div class="header">
    <div class="side">
      <p>HI</p>
      <div class="main">
        <p>HI2</p>
      </div>
    </div>
    <div class="body">
      <p>I am the body</p>
    </div>
  </div>
</div>

Answer №1

Initially, there are numerous errors in your code. The side class and the main class have not been properly closed, and a closing div tag is missing for the side div.

Furthermore, once I corrected these mistakes, I noticed that you were applying display: flex; to the .container when it should be applied to the .header instead, as it serves as the parent element for the side and main divisions.

If you need assistance with flexbox, this resource is quite helpful: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Here is an updated version of your code:

html {
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
}

.container {
  position: relative;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  border: 1px solid black;
  display: flex;
  flex-direction: column;
}

.header {
  margin-top: 15px;
  border: 1px solid red;
  height: 15vh;
display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
 justify-content: flex-start;
}

.side {
  width: 15vw;
  border: 1px solid yellow;
}

.main {
  width: 50vw;
  border: 1px solid blue;
}

.body {
  border: 1px solid green;
  height: 80vh;
}
<div class="container">
  <div class="header">
    <div class="side">
      <p>HI</p>
</div>
    <div class="main">
      <p>HI2</p>
    </div>
  </div>
  <div class="body">
    <p>I am the body</p>
  </div>
</div>

Answer №2

central is located inside. in order for them to be next to each other, you will need to organize them as siblings within the flexbox.

you also missed adding display: flex in the header css.

give this a shot

html {
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
}

.container {
  position: relative;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  border: 1px solid black;
  display: flex;
  flex-direction: column;
}

.header {
  margin-top: 15px;
  border: 1px solid red;
  height: 15vh;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
}

.body {
  border: 1px solid green;
  height: 80vh;
}

.side {
  width: 15vw;
  border: 1px solid yellow;
}

.main {
  width: 50vw;
  border: 1px solid blue;
}
<div class="container">
  <div class="header">
    <div class="side">
      <p>HI</p>
    </div>
    <div class="main">
      <p>HI2</p>
    </div>
  </div>
  <div class="body">
    <p>I am the body</p>
  </div>
</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

displaying the information when we mouse over a specific row in the table

I need to display a pop-up with data from a table row, similar to the image at this URL for CS WHOLESALE GROCERS. I've implemented the following AngularJS code in my controller: app.directive('tooltip', function(){ return { res ...

Enhancing the Search Bar in Bootstrap 4 Dashboard Template: A Step-by-Step Guide

Recently got my hands on the Bootstrap 4 Dashboard template and decided to enhance it by adding a form to the top search bar. However, I encountered an issue where the search bar shrinks and loses its original design. If you want to check out the Bootstra ...

Why does this CSS ticker only display the first four posts?

Hello, I'm interested in adding a News Ticker to my Rails application. I came across this CSS ticker: I'm facing an issue where it only displays the first four posts. I believe the problem might not be with my data retrieval using the .each loop ...

"Implementing jQuery to dynamically set the href attribute for a link when

My website features a tabbed menu that displays content from various WordPress categories including Cars, Trucks, and Buses. The active tab is randomly selected each time the page is reloaded. However, there seems to be an issue with the "View More" button ...

Utilize duplicate named CSS grid rows as a reference

Summary; This method currently works, but it requires adding multiple nth-child selectors for each new person and their answer. I am seeking a solution that can dynamically handle any number of rows using an even and odd selector to simplify the process. ...

Updating CSS class within a div tag utilizing ASP.NET (C#)

How can I dynamically update the properties of a CSS class using C#? I need to change the background image, font size, font style, and font based on user input through an interface. Once the changes are saved, I store them in a database. However, when the ...

Tips on verifying the binding of a mat-checkbox in Angular

I am working with an Angular 6 application and want to ensure that the binding of a mat-checkbox is functioning correctly. Here is the template: <div style="text-align:center"> <mat-checkbox id="singleCheckBox" [(ngModel)]="isChecked">Check ...

What is the best way to display text from a header box across multiple line boxes in real time on an HTML page?

Looking to enhance an HTML layout with a header box and line comment boxes. <textarea name="order[header_comments]"></textarea> The line comment boxes are structured as follows: <textarea name="line_comments[0][line_comments]"></tex ...

Exploring the concept of Server-Side Rendering in AngularIO

Exploring the fundamentals of SSR and AngularIO (latest version) has been quite enlightening. The distinction between CSR and SSR seems obvious based on their names. CSR carries out all the logic in the client side - for example, <app-route> remains ...

Send data from a PHP form with various input types using JavaScript and AJAX

I need to submit a form with various fields, including multiples checkboxes selection and some hidden input fields via AJAX and then replace the HTML content with the response. I decided to use JavaScript/AJAX for this process, but did I make any mistakes? ...

Styling an unordered list with CSS in HTML is a powerful

I am working with an unordered list where each list element contains two spans: span A and span B. My goal is to style these elements so that they are displayed horizontally on the screen, with span A above span B in each set. Example: spanAItem1 sp ...

unselect the button using jQuery

I want to trigger a popover when a variable exceeds a certain value, triggered by clicking a button: $(function () { $('[data-toggle="tooltip"]').tooltip({ trigger: 'manual', placement: 'top', titl ...

Regular expression patterns for authenticating and verifying passwords

Currently, I am working on a JavaScript program to validate passwords using regex. Here are the requirements: The password must consist of at least seven characters. It should include at least one of the following: an uppercase letter (A-Z) a lowercas ...

Exploring Angular4: Utilizing HttpClient with HttpParams for Passing Object Values in httpParams.set()

I'm facing an issue with handling a more complex key value pair. What if I need to set a value as an object? This is the problem I am encountering: const includeStr = JSON.stringify({include: 'match-timeline-events'}); const params: HttpPa ...

The div element nested within the button is not visible

Fiddle I am trying to create a unique social button design that resembles the custom Google+ sign-in button: However, I encountered an issue where the second div element (to hold the right part of the button) is not displaying as expected: Here is the c ...

Submit Angular form with only the updated field values, not the entire form data

Upon submitting my Angular form, I noticed that only the values for the changed fields are being captured. Is this behavior correct, or should I be getting the full form values instead? // Profile.html <form [formGroup]="profileForm" (ngSubmit)="submit ...

Is it possible to utilize the $ symbol within the ngOnInit or constructor functions?

I recently encountered an issue while trying to use the dollar sign ($) in my constructor function, specifically within ngOnInit() and translate.instant. Here is a snippet of the code that caused the problem: declare var $: any; { var SelectedDevice = ...

I am encountering an issue regarding the 'endpoint' property within my environment.ts file while working on an Angular 17 project

My goal is to incorporate the property endpoint from my environment.ts file into my service: export const environment = { production: false, endpoint: 'http://localhost:3000/api/cabin/' }; This snippet showcases my service: import {Injectabl ...

Unable to find a solution to Angular response options

I'm having trouble saving an item to local storage when receiving a 200 response from the backend. It seems like the request status is not being recognized properly. options = { headers: new HttpHeaders({ 'Content-Type': &apos ...

Is there a way to create triangles on all four corners of an image using canvas in JavaScript?

In my code, I am currently working on drawing rectangles on the corners of an image using JavaScript. To achieve this, I first extract the image data from a canvas element. // Get image data let imgData = ctx.getImageData(0, 0, canvas.width, canvas.height) ...