How to add unique custom CSS to ngx-smart-modals - html

I am currently building an application in Angular 6.
I am using ngx-smart-modal to handle all of my modals.
I have 20+ modals in my application.
How do I apply CSS to each one uniquely.
I have tried using the [customClass] parameter in their documentation, but I am relatively new to Angular/HTML/CSS/etc, and I could not get it working.
I can change the sizes of my modals globally using
/deep/ .nsm-dialog{ -insert style- }
But could not replicate for individual modals
HTML
<ngx-smart-modal #Create identifier="Create" customClass="'modal'">
CSS
.nsm-dialog.modal {
width: 50vw;
height: 50vh;
}
I would like to have each modal with unique CSS.
Ex.
* Modal1 size is 50vw x 50vh
* Modal2 size is 20vw x 40vh
* etc.

For using customClass directive with brackets, as [customClass], you must pass a string to the directive, like :
<ngx-smart-modal [customClass]="'my-custom-class'"></ngx-smart-modal>
Finally, you can style this and only this modal with my-custom-class.

I was having the same issue.
My resolution was making a ngx-modal.scss file and including it in style.scss after #import "~ngx-smart-modal/ngx-smart-modal";
I had to add !important to a few styles. Didnt love that but it worked.
HTML - in component
<ngx-smart-modal #modalName
identifier="modalName"
[customClass]="'confirmation-modal'">
</ngx-smart-modal>
scss - ngx-modal.scss
.confirmation-modal {
background-color: black !important;
border: 1px solid grey;
.modal-body {
color: white;
display: flex;
align-items: center;
justify-content: center;
}
.modal-footer {
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
border-top: 1px solid transparent;
border-bottom-right-radius: 0.3rem;
border-bottom-left-radius: 0.3rem;
top: 60px;
position: relative;
}
}

For normal way above told examples will work, but if you are creating modals in dynamic way you should do
const optionModel: INgxSmartModalOptions = {
closable: true,
escapable: false,
dismissable: false,
customClass: "signSowClass" };
let modal;
modal = this.ngxSmartModalService.create('signSow', SignSowComponent, optionModel).open()
You can pass the custom class through options as mentioned above

Related

CSS cursor property not changing when class is assigned to divs

Below is the CSS and HTML for the custom cursors I have, when I apply the classes to divs the cursors do not show.
If anyone wants to take a look at the SVG file as well I've linked it here
* {
cursor: url(../assets/cdefault.svg), auto;
}
.noclick {
cursor: url(../assets/cno.svg), 8 8, move !important;
}
.select {
cursor: url(../assets/cselect.svg), auto !important;
}
.text {
cursor: url(../assets/ctext.svg), 8 8, move !important;
}
.itemtext {
width: 40vw;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 12px;
color: white;
}
.item {
width: 40vw;
padding: 12px;
display: flex;
flex-direction: column;
align-items: center;
border-style: solid;
border-width: 0.1rem;
background-color: black;
border-color: white;
border-radius: 10px;
transform: scale(1);
}
.item img {
width: 40vw;
border-radius: 0.4rem 0.4rem 0rem 0rem;
}
<div class="item noclick" onclick="window.location = '/example/unavailable';">
<img class="noclick" src="example/example.png">
<div class="itemtext noclick">
<p class="title noclick">example<span> - example</span></p>
<p class="date noclick">example</p>
</div>
</div>
To clarify, the global cursor cdefault.svg, does show across the whole page, in this example the noclick class does not want to appear when hovering over the specified elements.
EDIT
Just as clarification, my cursors are all 16x16px and have worked when applied to classes individually. I have also tried using PNGs instead of SVGs but has not changed anything.
Please make sure the svg files are within 32 x 32px which is the size limit for most browsers. Otherwise the browser ignores your custom cursor file. There are similar answers for example here
Figured out what I was doing wrong! I shouldn't have been placing the comma after the svg url. Below is the fixed CSS
.noclick {
cursor: url(../assets/cno.svg) 8 8, auto;
}

Progress bar with 'text-inside' attribute CSS

Can someone help me with the following progress element of Element UI library:
Element UI - Progress link
I'm trying to reach for this result:
put the value at the end of each bar
Currently, having this:
with the following code:
HTML:
<el-progress :text-inside="true" :percentage="item.value" color="#6A7EC7" :stroke-
width="12"></el-progress>
CSS:
.el-progress-bar__outer {
background-color: transparent;
}
I've tried to do put the text div as relative like the following:
>>> .el-progress-bar__innerText {
color: $color-tremor-black;
position: relative;
left: 30px;
}
But the text is being cut when the value is close to the end.
What I'm missing? need to do?
Thank you.
I've decided to remove this component and build my own progress bar by using div and CSS.
Like the following:
HTML
<div class="newProgress">
<div class="progressBar" :style="{width:`${item.value}%`}"></div>
<span class="newProgressValue">{{item.value}}%</span>
</div>
CSS
.newProgress {
display: flex;
flex-direction: row;
width: 400px;
}
.progressBar {
width: 80%;
margin: 3px 0px 0px 10px;
background: #6A7EC7;
border: 1px solid #6A7EC7;
height: 12px;
border-radius: 50px;
}
.newProgressValue {
padding-left: 5px;
font-size: $font-size-small-plus;
}
I've couldn't find some information about Element UI library and its styles.

How to add a theme button, when clicked will change html background and buttons colour of that page

How to add a theme button, when clicked will change html background and buttons colour of that page. I have made some searches here but lots of Background colour change answers are there. I request some one to tell me how to change the button color also, with another button click.
With javascript you can create this function that takes two target colors and compares with actual colors, changing the body background, then the button background if the body had changed already.
working solution here
or run the snippet below
function changeColor ( bodyTargetColor, buttonTargetColor ) {
var firstClick = document.getElementsByTagName('BODY')[0].style.backgroundColor != bodyTargetColor ? true : false;
if (firstClick) {
document.getElementsByTagName('BODY')[0].style.backgroundColor = bodyTargetColor;
return false;
}
document.getElementById('changeColors').style.backgroundColor = buttonTargetColor;
}
body {
background-color: rebeccapurple;
display: flex;
height: 100vh;
width: 98%;
align-items: center;
justify-content: center;
font-family: sans-serif;
}
#changeColors {
width: 350px;
height: 100px;
color: white;
font-size: 2rem;
background-color: orangered;
border-radius: 8px;
border: 0;
outline: 0;
}
<button
id="changeColors"
onclick="changeColor('darkslategray','olive')"
>Change Colors</buton>

Button Elements are slipping out (chrome)

Im working on a little project where I want to add a button which opens a menu. The button looks great on Firefox, but when I check on brave or chrome the button elements seem to slip out and I cant pinpoint what it is...
Button on Firefox
Button on Chrome
This is the button with the elemens inside.
<button id="add-menu">
<img src="plus.png" height="40px" id="plus-minus-icon"><p>Add New Menu</p>
</button>
This is the CSS code, hope you can help me.
#add-menu {
grid-area: 5 / 1 / 5 / 3;
height: 100%;
width: 80%;
background-color: #333333;
border-radius: 25px;
justify-self: center;
display: flex;
align-items: center;
border: 1px solid black;
z-index: 1;
}
#add-menu img {
margin-left: 5px;
}
#add-menu p {
color: white;
font-size: 24px;
line-height: 50px;
}
Use -webkit- and -moz- to solve this problem.
Please take a look here: what-are-moz-and-webkit
Be aware of some known issues with buttons, fieldset and some more when having display flex or grid. You can have a glimpse of this issue here.
Maybe in newer versions of chrome they addressed this issue, this is why it looks fine to #sumeshsn1.
So, in order to solve this issue, wrap the button content on a span element and add the flex properties there:
<button class="button">
<span class="button__wrapper">
<img class="button__image" aria-hidden="true" src="https://cdn2.iconfinder.com/data/icons/free-basic-icon-set-2/300/7-128.png">
<span class="button__label">Add New Menu</span>
</span>
</button>
Some notes:
I remove the id and add classes instead, as this would help you maintaining your code and would enable you to use multiple buttons on your html while being a valid document (you are supposed to have only one id in the document).
As the image purpose is just a visual hint for the button function, lets add an aria-hidden=true attribute to the image element.
Remove inline styles (the height attribute you have on your image tag).
Now, let's review the CSS:
.button {
height: 100%;
width: 80%;
background-color: #333333;
border-radius: 25px;
border: 1px solid black;
}
.button__wrapper {
display: flex;
flex-flow: row nowrap;
align-items: center;
}
.button__image {
margin-right: 5px;
height: 40px;
}
.button__label {
color: white;
font-size: 24px;
line-height: 50px;
}
Some notes:
Remove the grid-aria declarations, as this property only makes sense when using a display: grid element, which you don't.
Remove the z-index as well, you need to mess with this property for your issue.
I also wrote this snippet using BEM. You might want to have a look at how this methodology works and how it can help you here.
You can find the updated pen here.

Overwrite primary Bootstrap 4 color with internal CSS

I need to change the default primary Bootstrap 4 color (after the Bootstrap stylesheet has been loaded) to a custom color (choosed by user) for a dynamic Bootstrap component with an internal CSS stylesheet.
I could do, for example, .btn-primary { background-color: red; } but this works just for buttons and, however, it doesn't change the other btn-primary states like ":hover", ":active" and "disabled". It also doesn't change the "primary" color throughout the entire CSS for .alert-primary, .text-primary, .bg-primary, .btn-outline-primary, .badge-primary, etc...
What's the possible solution?
You need to download the Bootstrap Sass files. You can do so from this link.
Once you have them you can open the main bootstrap .scss file and search for:
$theme-colors: (
"primary": #0074d9,
"danger": #ff4136
);
Change "primary" to what you need and then recompile to CSS. If you don't have Sass installed on your machine you can use various online tools to accomplish this. Example.
Source: https://getbootstrap.com/docs/4.3/getting-started/theming/
You can do so by using the variables concept(https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties)
Bootstrap 4 also works on the variables
You can try changing the variable values at run time as mentioned below:
:root {
--main-bg-color: brown;
}
.one {
color: white;
background-color: var(--main-bg-color);
margin: 10px;
width: 50px;
height: 50px;
display: inline-block;
}
.two {
color: white;
background-color: black;
margin: 10px;
width: 150px;
height: 70px;
display: inline-block;
}
.three {
color: white;
background-color: var(--main-bg-color);
margin: 10px;
width: 75px;
}
.four {
color: white;
background-color: var(--main-bg-color);
margin: 10px;
width: 100px;
}
.five {
background-color: var(--main-bg-color);
}
// get variable from inline style
element.style.getPropertyValue("--main-bg-color");
// get variable from wherever
getComputedStyle(element).getPropertyValue("--main-bg-color");
// set variable on inline style
element.style.setProperty("--main-bg-color", "red");
There are different ways do it. I am describing one of them.
Import below lines to your scss file.
#import '~bootstrap/scss/bootstrap.scss';
After that write below code to override it.
$primary = 'red';
$gray = 'gray';
.btn {&.btn-primary {
#include button-variant($primary, $primary, $primary, $primary);
&.disabled,
&:disabled {
border: $gray;
background-color: $gray;
}
&:hover {
opacity: 0.85;
}
}
}
Check the link to use sass mixins to override bootsrap classes.