How can i do my <mat-card> doesn't expand when messages are displayed in Angular 9 - css

I have my <mat-card> that has one form for the login of my page, the problem is when the error messages are displayed they change the size of the <mat-card> vertically and i need it to stay in the same size.
How can i do that?
Below i will let my html file , the sass file of the error messages and pictures of what I have
html file
<div class="bg">
<div class="main-div color ">
<mat-card class="z-depth center col-sm-4 " flex="50" >
<mat-radio-group aria-label="Select an option" [(ngModel)]="radio_btn">
<mat-radio-button [value]="true" >User</mat-radio-button>
<mat-radio-button [value]="false">Admin</mat-radio-button>
</mat-radio-group>
<div class="row justify-content-center " *ngIf="radio_btn==true;else form2">
<form class="example-form " [formGroup]="loginForm" (ngSubmit)="sendUser()">
<mat-form-field class="example-full-width ">
<input matInput formControlName="Identifier" placeholder="Identifier" >
</mat-form-field><br>
<div class=" alert-danger space" *ngIf="identifier.invalid && (identifier.dirty || identifier.touched)">
<div class="container-error-message " *ngIf="identifier.errors.required">
Identifier required
</div>
<div class="container-error-message" *ngIf="identifier.errors.minlength">
Identifier must be at least 7 characters long.
</div>
</div>
<br>
<mat-form-field class="example-full-width">
<input matInput formControlName="Password" placeholder="Password" type="password" >
</mat-form-field><br>
<div class="alert-danger space" *ngIf="password.invalid && (password.dirty || password.touched)">
<div class="container-error-message" *ngIf="password.errors.required">
Password required
</div>
<div class="container-error-message" *ngIf="password.errors.minlength">
Password must be at least 5 characters long.
</div>
</div>
<br>
<button mat-raised-button [class.black]="!loginForm.invalid" [disabled]="loginForm.invalid" type="submit">Sign in</button>
</form>
</div>
<ng-template #form2>
<app-home-admin></app-home-admin>
</ng-template>
</mat-card>
</div>
</div>
SASS file
#import './../../variables_scss/variables.scss';
example-icon {
padding: 0 14px;
}
.example-spacer {
flex: 1 1 auto;
}
.down{
overflow-y: auto;
.colour{
//background: #141519;
background: $orange-bg;
.icons {
color: $black;
}
}
}
.container{
align-items: center;
}
.main-div{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
.center{
width: 75%;
margin: 10px auto;
.mat-radio-button ~ .mat-radio-button {
margin-left: 16px;
}
button {
display: block;
width: 100%;
margin: 2px;
text-align: center;
color: $orange !important;
border-radius: 8px;
}
}
}
.bg{
background: $black;
background: linear-gradient(to right, $dark_black,$light_black );
}
.behind{
z-index: 10;
}
.black {
background-color:$black !important;
}
.space{
margin: $margin-errors;
text-align: $text-align-center;
width: $width-erros;
border: 1px solid;
}
* scss_variables*
$dark_black: #1b1b1b;
$light_black: #424242;
$black: #141519;
$margin-left: auto;
$orange: #fc6407;
$colour_button :$black;
$orange-bg: linear-gradient(to right, #c43e00, #ff6f00);
$margin-errors: 0 auto;
$text-align-center: center;
$width-erros: 180px;

I am not able to replicate your issue with the code given by you. But i would suggest you to provide a constant height to mat-card which is sufficient to enclose all the items. Like i am taking 400px below:
mat-card {
height: 400px;
}

This is how i solve it
Adding this to the space class
max-height: 0px ;
margin-top: 0px !important;
Adding this to the center class
height: 290px;

You can add maximum height and minimum hight of card as same like this in your CSS file , it's worked for me, if you done like this then if the content size is height,automatically scroll will be apply without any size correction
.mat-card{
min-height: 230px ;
max-height: 230px ;
}

Related

Why Flex Basis 100% is not working in this case? What is the solution?

I am trying to build a contact form which has fields such as name, phone-number, email, message & submit button. My core agenda is to make Email & message fields acquire 100% width of the contact form. (irrespective of screen size). Name & Phone number fields are responsive & will stay in a single line or go one below the other based on the screen size.
The design is is responsive & have applied flexbox to the .field section & also to .form-container section.
I am applying the flex basis to .w-100 which is not working. By making it flex-basis 100% it should take 100% of container width. But why it is not happing?
What is the mistake I am doing & how to resolve it ?
HTML Section:
<section id="contact" class="contact">
<h2>Contact Me</h2>
<form action="#">
<div class="form-container">
<div class="field">
<label>Name: </label>
<input type="text" placeholder="Name"></input>
</div>
<div class="field">
<label>Phone Number: </label>
<input type="tel" placeholder="Phone Number"></input>
</div>
<div class="field w-100">
<label>Email: </label>
<input type="mail" placeholder="Email"></input>
</div>
<div class="field w-100">
<label>Message: </label>
<textarea cols="30" rows="3"></textarea>
</div>
</div>
<div class="submit-form">
<input type="submit" class="button" value="send" />
</div>
</form>
</section>
CSS Section:
form {
background-color: var(--grey);
padding: 2rem;
border-radius: 1rem;
}
.field {
display: flex;
margin-bottom: 1rem;
}
.field label {
flex: 0 0 90px;
color: var(--white);
}
.field input[type="text"],
.field input[type="tel"],
.field input[type="mail"],
.field textarea {
flex: 1;
}
.w-100 {/*this field not working*/
flex: 0 0 100%;
}
#media(min-width: 768px) {
form {
max-width: 800px;
margin: 0 auto;
}
.form-container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.field {
flex: 0 0 calc(50% - 1rem);
}
}
Current Output:
Expected Output:
Thank you #Termani Afif, The property flex: 0 0 calc(50% - 1rem); was overriding in the media query.
This property should be at the bottom for us to get proper output:
.w-100 {
flex: 0 0 100%;
}

How to restrict the number of items in flexbox according to screen size

I am new to grid designing on website design
In my react project, I have a row showing 3 components. One is Leverage type dot selection, Two of them are input box, Loan amount and Loan Rate.
Right now, every things seems fine in full screen, but when I shrink it, you can see that Loan Rate is placed on the next line while Loan Amount was still on above line
But what I want is, when I shrink it, it is either like this(1), or like (2) when it is super small
In(2), basically its been achieved with my existing css, when the screen is super small
Q: How could I either showing everything in the same line or showing one line with leverage type and one line with Loan Amount and Loan Rate?
Here is my code
.setting {
display: flex;
justify-content: space-between;
margin-top: 50px;
}
There are many ways we can break flex item in flexbox layout the one I have used here is flex-direction:column, this property sets every flexitem to vertically..
#media(max-width:576px) {
.flexBox {
flex-direction: column;
/*set all flexItem to vertically*/
align-items: stretch;
/* stretch will foce to take full width*/
}
}
Meaning of media(max-width:979px) means, CSS inside of that code block will only apply to screen size lessthan or equal to 979px. Means the CSS will not affect for screensize bigger than 979px.
Speaking about below code,
.flexBox .flexItem {
flex: 1 0 calc(100%/var(--number-of-items-for-midium-screen) - var(--gap-val)*2)
}
calc(100%/var(--number-of-items-for-midium-screen) - var(--gap-val)*2) here we divide 100% width with the number of items we want per row and we minus var(--gap-val) twice because we have applied gap:10px, which applied both side of .flexItem so we minus it 2 times.
And just to make CSS more friendly I have created CSS variables for
--number-of-items-for-midium-screen <= Number of items in a row
--gap-val <= gap between flex items in a row
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--number-of-items-for-midium-screen: 2;
/*Number of items you want in medium screen(below 979px)*/
--gap-val: 10px;
/*Gap you want between flex items*/
}
.flexBox {
display: flex;
align-items: center;
gap: var(--gap-val);
margin: 10px;
}
.flexBox .flexItem {
flex: 1;
border: 2px solid #d6d6d6;
padding: 10px;
}
#media(max-width:979px) {
.flexBox {
flex-wrap: wrap;
}
.flexBox .flexItem {
flex: 1 0 calc(100%/var(--number-of-items-for-midium-screen) - var(--gap-val)*2)
}
}
#media(max-width:576px) {
.flexBox {
flex-direction: column;
/*set all flexItem to vertically*/
align-items: stretch;
/* stretch will foce to take full width*/
}
}
<div class="flexBox">
<div class="flexItem">
<p>Leverage type</p>
<label for="static">static</label>
<input type="radio" value="static" id="static" name="gp1" />
<label for="dynamic">dynamic</label>
<input type="radio" value="static" id="dynamic" name="gp1" />
</div>
<div class="flexItem">
<label for="loanRate">Loan Rate</label>
<input id="loanRate" type="text" />
</div>
<div class="flexItem">
<label for="loanAmount">Loan Amount</label>
<input id="loanAmount" type="text" />
</div>
</div>
Understanding how to break layouts in flexbox
const btn1 = document.querySelector("#btn1"),
btn3 = document.querySelector("#btn3"),
btn4 = document.querySelector("#btn4");
const flexBox = document.querySelectorAll(".flexBox")[0];
const flexItems = document.querySelectorAll(".flexBox .flexItem");
const preview = document.querySelectorAll(".preview")[0];
btn1.onclick = () => {
flexBox.style.flexDirection = "column";
preview.style.display = "block";
preview.innerHTML = `.flexBox{flex-direction:column;}`;
}
btn3.onclick = () => {
flexItems.forEach(flexItem => {
flexItem.style.flex = "1";
})
preview.style.display = "block";
preview.innerHTML = `.flexItems{flex:1;}`;
}
btn4.onclick = () => {
const numberofItems = +document.querySelector("#numberofItems").value;
if (numberofItems && numberofItems >= 1 && numberofItems <= 6) {
flexBox.style.flexFlow = "initial";
flexBox.style.flexWrap = "wrap";
flexItems.forEach(flexItem => {
flexItem.style.flex = `1 0 calc(100%/${numberofItems})`;
})
preview.style.display = "block";
preview.innerHTML = `.flex{flex-wrap:wrap;}</br>.flexItems{flex:1 0 calc(100%/${numberofItems});}`;
} else {
alert("Please enter number of items you need from 1 to 6");
}
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.flexBox {
display: flex;
}
.flexItem {
display: inline-block;
height: 100px;
}
.bg-red {
background-color: red;
}
.bg-blue {
background-color: blue;
}
.bg-green {
background-color: green;
}
/*Just for styling*/
.buttons {
margin-top: 10px;
}
.buttons button {
padding: 10px;
border: 2px solid #000;
background: #fff;
text-transform: capitalize;
margin: 10px;
}
.textInput {
display: flex;
gap: 5px;
margin: 10px;
}
.textInput input {
flex: 1 0 75%;
}
.textInput button {
padding: 5px;
margin: 0;
}
.preview {
width: 100%;
border: 2px solid #000;
display: none;
padding: 30px;
}
<div class="flexBox">
<div class="flexItem bg-red">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-blue">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-green">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-red">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-blue">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-green">
<h5>This is flex box item</h5>
</div>
</div>
<div class="buttons">
<button id="btn1">Apply flex-direction to column</button>
<button id="btn3">set all box equal size</button>
<div class="textInput">
<input type="number" id="numberofItems" placeholder="Enter the number of items you want in a row" min="1" max="6">
<button id="btn4">set items in a row</button>
</div>
</div>
<div class="preview">
<h2>Applied css</h2>
</div>

CSS - How to make a dynamic bootstrap list scrollable

I have this code in my vue app
<form class="d-flex me-auto" id="searchBar">
<div class="input-group">
<input class="form-control" type="text" placeholder="Cerca professionista" #keyup="search" aria-label="Search" v-model="searchInput">
<button class="btn btn-outline-success" #click.prevent="search">
<i class="fa-solid fa-search"></i>
</button>
</div>
</form>
<div class="list-group" v-if="searchResults.length > 0" id="searchResultsList">
<a href="#" class="list-group-item list-group-item-action" v-for="(result, index) in searchResults" :key="index" id="searchResult" #click.prevent="showUserProfile(result.username)">
<div class="d-flex w-100 justify-content-between">
<p class="ps-2 me-auto mb-1">{{ result.name }} {{ result.surname }}</p>
<!-- <img :src="result.propicUrl" id="searchResultThumbnail"> -->
</div>
<small class="ps-2 me-auto">{{ result.category }}</small>
</a>
</div>
I will have a list that will contain the results of a search, since there are a lot of results, how I can make it scrollable? At the moment I have added this css rules but not working
<style lang="scss">
#menu {
height: 75px;
.navbar-brand {
padding-top: 0;
#logo {
width: 60px;
height: 60px;
}
}
#searchBar {
width: 420px;
}
#searchResultsList {
position: absolute;
top: 3.8em;
left: 5.4em;
width: 420px;
overflow-y: scroll;
#searchResult {
overflow-y: scroll;
#searchResultThumbnail {
height: 40px;
width: 40px;
border-radius: 50%;
}
}
}
}
</style>
You need to set either height or max-height to a value that results in a concrete size (e.g: 40vw, 200px, 20pt) for overflow-y: auto | scroll to have any effect.
Without setting the (max-)height, the element will grow to match the height of its children and will never display an active scrollbar.
Side note: considering the element has position: absolute, height: 100% will likely delegate the height request to the closest positioned ancestor but, again, you do need a positioned ancestor with a concrete height for overflow-y: auto | scroll to work.
Generic example:
Vue.createApp().mount('#app')
#app {
max-height: 100px;
overflow-y: auto;
border: 1px solid red;
}
<script src="https://unpkg.com/vue#next/dist/vue.global.prod.js"></script>
<div id="app">
<div v-for="n in 20">test</div>
</div>
Playground:
const { createApp, reactive, toRefs } = Vue;
createApp({
setup: () => ({
...toRefs(reactive({
setHeight: false,
setMaxHeight: true,
listLength: 20
}))
})
}).mount('#app')
#app {
display: flex;
}
#app>* {
flex: 0 0 50%;
}
.scroller {
overflow-y: auto;
border: 1px solid red;
}
.controls {
padding: 0 1rem;
display: flex;
flex-direction: column;
}
* {
box-sizing: border-box;
}
<script src="https://unpkg.com/vue#next/dist/vue.global.prod.js"></script>
<div id="app">
<div class="scroller" :style="{ height: setHeight ? '100px' : '', maxHeight: setMaxHeight ? '100px': ''}">
<div v-for="n in listLength">test</div>
</div>
<div class="controls">
<div>
Items: <input type="number" v-model="listLength">
</div>
<label>
<input v-model="setHeight" type="checkbox">
Set height
</label>
<label>
<input v-model="setMaxHeight" type="checkbox">
Set max height
</label>
</div>
</div>
The difference between setting height and max-height is that with height the element will have the specified height even when it doesn't have enough content to fill it, while with max-height, when you don't have enough content, the element will shrink all the way down to 0 (unless something else gives it a soft min-height: e.g: a flex container).

Fill the page entirely with background color

How can I extend the color green up to bottom? And how can I move the CRUD in left too
So as you can see it can't fill the page entirely.
Here's my code in VueJS
<template>
<div class="container-fluid">
<h1>CRUD</h1>
<div class="my-form col-xs-1">
<b-card class="box">
<b-form-group id="input-group-1">
<b-form-input
id="input-1"
required
placeholder="Username"
></b-form-input>
</b-form-group>
<b-form-group id="input-group-2">
<b-form-input
id="input-2"
type="password"
required
placeholder="Password"
></b-form-input>
</b-form-group>
<div class="btn">
<b-button variant="primary" >Login</b-button>
<b-button variant="success" #click="$router.push('/register')">Register</b-button>
</div>
</b-card>
</div>
</div>
</template>
<script>
export default {}
</script>
<style scoped>
.container-fluid {
background-color: green;
height: 100%;
}
.my-form {
display: block;
margin-top: 120px;
margin-bottom: 120px;
}
.box {
padding: 10px;
margin-bottom: 20px;
}
.btn {
margin: 5px;
}
</style>
What is my mistake with this? I tried using flex a while ago but didn't understand why it always fits the content to itself.
By the way sorry for my bad English.
THanks
just write in your body tag it will solve your problem
bgcolor="green"
Use CSS to get the background color changed, and ensure the body (document) is at least 100% of the viewport height :
body {
background-color: green;
min-height: 100vh;
}
To align "CRUD" to the left, use the Bootstrap utility class "text-left":
<h1 class="text-left">CRUD</h1>
https://getbootstrap.com/docs/4.3/utilities/text/
https://bootstrap-vue.js.org/docs/reference/utility-classes

Get UIKit - Append form with email address

On UIKit, How do you create an email form with an inline text so the user can input text and the form has #example.com after it.
You can do this in bootstrap here: https://getbootstrap.com/docs/4.0/components/input-group/
But I am unable to recreate this on UiKit?
Just "borrow" the concept from bootstrap. Wrap the elements within grid, group them with the class name, and inside the group add element with the flexbox display, it will fit automatically. From what I've seen in sources - they give him 1% width - maybe there's a case for that, but anyway works with only display:flex.
Here's my proposition:
HTML
<form class="uk-grid-small" uk-grid>
<div class="uk-width-1-2#s input-group">
<input class="uk-input" type="text" placeholder="50">
<div class="input-group-append">
<div class="input-group-text">
#email
</div>
</div>
</div>
</form>
CSS
.input-group {
display: flex;
}
.input-group-append {
display:flex;
align-items:center;
}
.input-group-text {
display: flex;
align-items: center;
font-weight: 400;
height:38px;
color: #495057;
padding: 0 10px 0;
text-align: center;
white-space: nowrap;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-left:none;
}
I've also made a codepen for the reference https://codepen.io/arysom/pen/QzGjyo

Resources