Achieve full-width child elements within a flex parent using Angular

In my Angular application, I have a main flex container called main-container with a child element named box. The goal is to center the child element within the parent and make it take up 100% of the parent's width. However, due to padding settings, the width of the box is currently set to 80px. Below is a snippet of the code that demonstrates this behavior.

.main-container {
    width: 100%;
    min-height: 100vh;
    padding: 15px;
    background: linear-gradient(-135deg, #c850c0, #4158d0);
    display: flex;
    justify-content: center;
    align-items: center;
}
.box {
    max-width: 500px;
    width: 100%;
    padding: 40px;
    border-radius: 10px;
    background: #fff;
    text-align: center;
}
<div class="main-container">
  <div class="box">
  </div>
</div>

This image provides a visual representation of how the Angular page appears:

https://i.sstatic.net/vnj8Z.png

Your assistance is greatly appreciated!

Answer №1

Make a simple adjustment by changing width: 100% to max-width: 100vw in the main-container, and apply flex: 1 to the box container.

  • Using max-width will eliminate any horizontal scrollbars, ensuring the container remains visible at all times.
  • With flex: 1: a shortcut for flex-grow: 1, flex-shrink: 1, and flex-basis: 0px, the box will expand to fill all available space inside the container.
.main-container {
    max-width: 100vw; // Use this instead
    min-height: 100vh;
    padding: 15px;
    background: linear-gradient(-135deg, #c850c0, #4158d0);
    display: flex;
    justify-content: center;
    align-items: center;
}
.box {
    flex: 1;  // Add this line
    padding: 40px;
    border-radius: 10px;
    background: #fff;
    text-align: center;
}

https://i.sstatic.net/td64x.png

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

Looking to incorporate multiple accordion drop down menus on your website? Utilize a combination of HTML, CSS, and JavaScript to

I am experiencing a challenge with implementing multiple accordion menus on my website. Whenever I attempt to duplicate the code, the new accordion menu appears but clicking on the first bar simply scrolls me back to the top of the webpage. Below is the H ...

The Angular Spring Boot Assembly Problem Leading to a Whitelabel Error

I am currently working on a project that uses Spring Boot as the backend and Angular as the frontend. My packaging process involves building the Angular project and then copying the contents into the Spring Boot resource folder. In my Spring Boot Controlle ...

Displaying Table Headers on Page Breaks in Laravel PDF with Webkit Technology

Let me provide some context: I am utilizing Laravel to generate a view that is then converted to a PDF using barryvdh/laravel-snappy with the help of wkhtmltopdf, and everything is functioning as expected. However, I am encountering difficulties in stylin ...

List formatted in a table

Can a list be inserted into a table using markdown? I attempted to research this but came up empty-handed. An example of a Table: Fruit |Color ---------|---------- Apples |Red Pears |Green and an example of a list: List item 1 List item 2 ...

Pass a photo along with additional characteristics to the post endpoint in the API

Using the code snippet below, I am able to send an image to a post method and save it as a BLOB in the database successfully: Angular Code: public postUploadedFile(file:any){ this.formData = new FormData(); this.formData.append('file',fi ...

Tips for utilizing a bootstrap navbar and dropdown in conjunction with angular 7

Attempting to click on the Dropdown link in the menu, but nothing happens. <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-a ...

iPhone failing to interpret HTML entities

I am currently developing a website for a client, who is facing a bug that I have not been able to replicate... For reference, here is an example page: The issue my client is experiencing involves using an iPhone to navigate the website. It appears that ...

Align two lines of text in the center of a table

I need assistance with creating a table in HTML for an email. I would like to display a two-lined text, where the top line is formatted in bold. <table style="width:100%"><tr > <td style="background-color:#000000;color:#fff;font-fam ...

Can you reveal a table with the click of a button?

Hi there! I'm a newcomer to the world of Ruby on Rails and I’m currently working on creating a page that includes a date field. Once a specific date is selected, I’d like to generate a table displaying reports from that chosen date. controllers/r ...

The Bootstrap table is not adhering to the specified width when the display is set

I encountered an issue starting yesterday. I am utilizing Bootstrap 4 and tables. Whenever I set a width greater than 13.5vw, the table does not adjust accordingly. You can view the fiddle here Below is the code snippet: HTML <table cl ...

Custom navigation bar created using Bootstrap 4

My webpage was created using Bootstrap 4, but I am having an issue with the navbar toggler not aligning properly within the navbar on mobile view. You can see the problem in the screenshot below: https://i.sstatic.net/aBejI.png If you visit the url for t ...

Bidirectional Data Flow with rxjs in Angular

After adapting an Angular template and component from Angular Material's dashboard schematic, I wanted to manipulate the properties on the "cards" object using events and two-way data binding. Initially, it seemed like two-way data binding was working ...

I am looking to eliminate the right padding from a group of div elements

Is there a way to remove the right padding from the class "no-border"? I attempted some CSS adjustments, but so far nothing has worked. I tried using "padding-right:none" without success. #menu-bar-container-2 { border: 1px solid gray; } .menu-bar-2 a ...

Refresh a section of the webpage without any mouse interactions

After receiving many helpful replies to my previous question, I am looking to update only a portion of a page instead of the whole page (with id='#colorbox'). I attempted modifying Rory McCrossan's code: by changing: window.location.relo ...

Bootstrap / Blazor - no action when clicking on an image link

Having issues with adding a simple HTML link around an image in my Bootstrap 4.5 / Blazor app. When I click on the link, nothing happens. How is this possible? I've tried using the <a href"..."><img ...> pattern, as well as NavL ...

Smoothly scrolling to an element within a nested div with a scrollable area using JQuery

I need to smoothly scroll down to a specific div that is located within another div containing scrollbars. var div_terms = $('#div_terms').offset(); $("#scroll_to_accept").click(function (){ //$(this).animate(function(){ ...

Issue with TailwindCSS @apply not compiling in Angular v12 component styles

I am a computer science student working on a project for my studies. I am currently developing a component library for the Angular framework using Angular V12. To style the components, I have decided to use Tailwindcss as it simplifies some aspects like me ...

"Upgrade your website visuals by dynamically changing image sources using jQuery and adding a touch of flair with smooth loading

I am currently working on a page where I have an image that changes its source using JavaScript. However, I would like to enhance this by adding a beautiful sliding effect when the image changes. My goal is to create a seamless transition so that when a ...

Integrating AJAX functionality into a PHP webpage with various options selected

I'm a beginner coder looking for some assistance. Currently, I have a page with four select inputs, each with two options. When all selections are made and the submit button is clicked, a specific song out of 16 based on the choices will play in an a ...

Is there a way to modify the rounded corners of a checkbox in material-ui?

After importing material-ui into my react app, I was able to change the color and size of a checkbox as shown. However, I am having trouble changing the icon's border radius. How can I achieve this? import FormGroup from '@mui/materi ...