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

Angular - Automatically blur input field in a Reactive Form

I'm encountering a strange problem. Check out the demo .ts import { Component } from '@angular/core'; import { FormGroup, FormBuilder } from '@angular/forms'; @Component({ selector: 'my-app', templateUrl: './a ...

I require the ability to access a reference parameter with a dynamically changing name within a Vue template

<div v-for="x in 4" :class="(images[x] === null) ? 'not-removable' : 'removable'" class="img-container"> <input style="display: none" type="file" ...

arrange a div inside another div

I'm struggling to grasp the concept of how divs function in HTML. Below is a snippet of my HTML code: <div id="user_p"> <img src="img/pp/djbaptou.jpg"> <div class="followings"> djbaptou </br> Baptiste Arnaud </br> ...

Sharing API Results with All Components in Angular 7 using BehaviorSubject

My goal is to optimize an API call that fetches data about the current user (such as their username, full name, group memberships, email address, and more) by ensuring it's only made once per user session and that the data is shared across all compone ...

React - method for transmitting dynamically generated styles to a div element

As a newcomer to the world of React, I keep encountering an unexpected token error related to the ":". Can someone please assist me with understanding the correct syntax for including multiple styles within the Box component provided below? Additionally, h ...

Steps to retrieve the date of the selected item in a PrimeNG data table using Angular 2

I am currently working on an Angular 2 project that utilizes a Primeng table with multiple selection functionality. The selected values are stored in [(selection)]. I am trying to figure out how to access and utilize the [(selection)] value within the comp ...

Ways to adjust the border color when error helper text is displayed on a TextField

I am currently working with React Material UI's TextField element. What I aim to achieve is when the submit button is pressed, the helpertext displayed should be "Please enter the password." It should look like this: However, once the helpertext is ...

Implementing customized line breaks in PHP using custom fields

My knowledge of PHP is quite limited, so I prefer to seek advice from experts before attempting anything I find online. I recently installed a customized billing field plugin in order to collect additional billing information during the checkout process. ...

Sending binary information from a .net core web api to a typescript application

I currently have a .net core 3.0 web api application connected to an angular 8 client. While I have successfully transferred data between them using json serialization, I am now looking for a way to transfer a bytes array from the api to the client. After ...

Exploring Angular 4: Embracing the Power of Observables

I am currently working on a project that involves loading and selecting clients (not users, but more like customers). However, I have encountered an issue where I am unable to subscribe to the Observables being loaded in my component. Despite trying vario ...

Issue with alignment in the multiselect filter of a React data grid

In React Data Grid, there is a issue where selecting multiple filter options messes up the column headers. Is there a solution to display selected filter options above a line in a dropdown rather than adding them to the column header? The column header siz ...

"Enhance user experience with jQuery's text expansion and collapse

Figuring out how to collapse and expand text with a button click has been challenging for me. I managed to make the text collapse when the button is clicked, but now I also need it to expand back again. The goal is to have the text initially hidden, then e ...

List on the Left Side with Scroll Capability

In my ASP.NET web application that targets .NET 3.5 and utilizes an AJAX asp:UpdatePanel, I have structured the page layout using multiple div elements to divide the vertical space into sections - header, first content, second content, third content, and f ...

Stay Alert: Angular Observable Continuously Monitored for Promise Updates

I am currently working on an angular application that has a connection with a printer. The printer possesses its own status service that is implemented as a promise, providing the printer's current status as a response. However, I am facing an issue w ...

View does not display initial value selected in ReactJS

I'm having trouble setting an initial value for a select element that isn't displaying in the view. Here's my JSX: var SelectOKNO = React.createClass({ render() { return ( <div> <select className="selectpicker" ...

Is it advisable to incorporate multiple images onto a single canvas?

What is the best approach to handling multiple images in HTML5? Is it preferable to create a separate canvas tag for each image or is it equally effective to have multiple images in one canvas, and how would I go about doing that? Here is the code I have ...

Error encountered in onclick handler due to unterminated string literal in PHP and jQuery

Trying to utilize PHP to send variables into the onclick of an element is resulting in an "Unterminated string literal" error due to long strings. Below is a snippet of my PHP code: $query = $conn->prepare("SELECT Name, Image, Description, Link, Price, ...

Utilizing the 'input' method to modify the key of an array object within specified elements in a Vue.js application

i am looking to implement an input field that can be used to edit the title of the currently selected element component (the selection is made by clicking). The challenge here is to have a single input that works for each individually selected element. I h ...

Can the default Bootstrap classes in the ExtLib application layout control be modified?

I am currently using the responsive Bootstrap theme in combination with the application layout control in extlib, but I have been unable to locate any documentation on whether it is possible to modify the predefined Bootstrap classes. In the example below ...

What is the best way to obtain the file's pathway?

:image => StorageRoom::Image.new_with_filename(path) When trying to retrieve the image path, I initially specified it manually and it worked fine. However, after deploying to Heroku, an error message 'Load Error - No such file present' is dis ...