I am trying to modify the primeng p-calendar, but it is not working properly.
For example:
I want it to be like this:required changes
But original it looks like this:original image
What i have tried so far:
HTML
<div class="nxui-form-group">
<label for="planEndDate">
<img src="assets/images/calendar.svg" class="nxui-icon-small nxui-icon-align-bottom">
{{ 'i18n.all-damage-reports.label.plan-end-date' | translate }}
</label>
<p-calendar formControlName="planEndDate"
class="calendar-control"
id= "planEndDate"
[title]="'i18n.all-damage-reports.label.plan-end-date' | translate"
[dateFormat]="'i18n.common.dateformat.shortdate-p-calendar' | translate"
[locale]="'i18n.common.dateformat.calendar' | translate"
></p-calendar>
</div>
CSS
p-calendar.calendar-control {
opacity: 1;
color: black;
background: #eeeeee;
}
looking forward to inputs.
Thanks
I think that you should use the special selectors of angular to change a component style like :host or ::ng-need, you can check that in the official documentation:
https://angular.io/guide/component-styles
::ng-deep body .ui-datepicker .ui-datepicker-header .ui-datepicker-title {
margin: 0;
padding: 0;
line-height: 1;
color: goldenrod;
}
::ng-deep .ui-datepicker .ui-datepicker-group {
background-color: cadetblue;
}
Hope that'll help you !
In my case, I want to style the calendar icon, html is below
<div class="main-container">
<p-calendar showTime="true" hourFormat="12" [showIcon]="true"></p-calendar>
</div>
Then I added style below but it is not working:
.main-container ::ng-deep .ui-datepicker-trigger.ui-button {
// add style here
}
Then I added p-calendar after ::ng-deep it worked
.main-container ::ng-deep p-calendar .ui-datepicker-trigger.ui-button {
// add style here
}
Did you try to change the styling classes?
See https://www.primefaces.org/primeng/#/calendar (section styling)
Like for example
.ui-calendar .ui-inputtext {
// place text styling here
}
Select element class via using Inspect then add ::ng-deep selector to force style on child components
::ng-deep .ui-inputtext {
/* Example */
opacity: 1 !important;
}
The code you see in the templates is not what actually is in browser's DOM. There are some other elements injected, like <input> for text input.
Try something like
p-calendar.calendar-control input {
border: 1px solid black;
background: #eeeeee;
}
And anyway, look at the actual elements in your browser with Inspect Element and write CSS according to the real situation.
Related
Here I'm trying to change the CSS variable's value (visibility) when the button is clicked on (using :focus) to show/hide the images, without using Javascript.
CSS
img {
width: 200px; height: 200px; margin-left: 40px; margin-top: 30px;
}
:root {
--c1-vsb: none; --c2-vsb: none;
}
a.c1-imgs {
visibility: var(--c1-vsb);
}
a.c2-imgs {
visibility: var(--c2-vsb);
}
#C1:focus {
background-color: red;
--c1-vsb: hidden;
}
#C2:focus {
background-color: red;
--c2-vsb: hidden;
}
HTML
<html>
</head>
<body>
<div id="left-panel">
<button class="lp-btn" id="C1">SEAL 1</button><br>
<button class="lp-btn" id="C2">SEAL 2</button><br>
</div>
<div id="right-panel">
<a class="c1-imgs"><img src="https://files.worldwildlife.org/wwfcmsprod/images/HERO_harbor_seal_on_ice/hero_full/87it51b9jx_Harbor_Seal_on_Ice_close_0357_6_11_07.jpg"></a>
<a class="c2-imgs"><img src="https://www-waddensea-worldheritage-org.cdn.gofasterstripes.download/sites/default/files/styles/inline_image_full_width/public/20-11-09_habour%20seals%20report_TTF_5200.JPG?itok=YZs9c_dH"></a>
</div>
</body>
</html>
But for some reasons, when I clicked on the button to set visibility to hidden, the images do not get hidden away.
Previously, I tried hiding the images with css pseudo classes and display:none, z-order... but got stuck. In the end, I thought this should have been the simple way out.
Could you suggest a solution to this problem I'm having? I'm not too sure if this is the correct approach.
Thank you!
When you declare #C1:focus { --c1-vsb: hidden; }, the new value of --c1-vsb only applies to #C1, not the entire HTML document.
As MDN states: "[...] the selector given to the ruleset defines the scope that the custom property can be used in".
With css, you can only Show/hide with mouse handle. You don't change 2 state (Show/Hide) when click into button.
I have virtually zero experience with HTML and CSS, and I'm trying to create a simple website.
I have buttons from Bootstrap, what I'm trying to achieve is, when a button is pressed, it's text would change it's color and will have no border.
This is what I tried:
.btn-secondary:active, .btn-secondary:focus {
color: aquamarine;
outline: none !important;
}
But that does not work.
This is the result:
The change in color does work, but I just can't remove this grey border. I tried looking in Bootstrap docs, but couldn't find anything.
Tried few different things too (such as outline-style etc.) but still, it remains the same.
Try border style like below code -
.btn-secondary:active, .btn-secondary:focus, .btn-secondary:hover {
color: aquamarine;
border: 0 !important;
}
You can use:
.btn-secondary:active, .btn-secondary:focus {
color: aquamarine;
outline: 0;
-moz-outline-style: none;
}
EDIT: CSS supports focus pseudoclass but it's not supported in all browsers. In couple of years when :focus is more supported pure CSS solutions are great but in this time and place I would highly recommend to use JS.
EDIT part 2: changed let to var.
EDIT part 3: Added support for multiple buttons.
This code includes some JS.
<style>
button {
border: 1px solid black;
color: white;
font-size: 18px;
}
.buttonClicked {
border: 0;
}
</style>
<script>
var clickedButtons = [];
function onButtonClick(buttonsId) {
var button = document.getElementById(buttonsId);
if (clickedButtons.includes(buttonsId)) {
button.className = '';
clickedButtons.splice(clickedButtons.indexOf(buttonsId), 1);
} else {
button.className = 'buttonClicked';
clickedButtons.push(buttonsId);
}
}
</script>
<button id="button1" onclick="onButtonClick('button1')">
Button 1
</button>
<button id="button2" onclick="onButtonClick('button2')">
Button 2
</button>
<button id="button3" onclick="onButtonClick('button3')">
Button 3
</button>
<button id="button4" onclick="onButtonClick('button4')">
Button 4
</button>
I'm using a ngx-bootstrap 'alert' component. And I'd like to style the alert message, but adding the styles to the compnents .css file doesn't do anything.
question - ngx-bootstrap says to style do this below but I'd like to know if it can be done from the component .css file?
https://valor-software.com/ngx-bootstrap/#/alerts#local-styling
styles: [
`
:host >>> .alert-md-local {
background-color: #009688;
border-color: #00695C;
color: #fff;
}
`
]
ex.
.alert {
border-radius: 0px !important; // doesn't do anything
margin-bottom: 0px !important; // doesn't do anything
}
<alert [type]="alert.type" [dismissible]="dismissible" [dismissOnTimeout]="alert.timeout" class="text-center" style="margin-bottom: 0px;">{{ alert.msg }}</alert>
You can use ng-deep for this. Though it is mentioned in the docs that it will be deprecated soon, there's a lot of discussion going on about a good alternate solution for the same. Here's the GitHub issue.
For now, ng-deep still works.
:host ::ng-deep .alert {
border-radius: 0px;
margin-bottom: 0px;
}
I'm new Angular, CSS and Html.
I have used MatTabsModule(import { MatTabsModule } from '#angular/material/tabs';) to create tabs but I'm able to adjust/change height, background etc. In short I'm not able to override default properties of MatTabsModule's classes. Please help me.
Below is my CSS and Html code. I hope Typescript code is not needed.
HTML: -
<mat-card>
<mat-card-content>
<mat-tab-group class="tab-group" dynamicHeight>
<mat-tab *ngFor="let obj of tags">
<ng-template mat-tab-label>{{ obj.name }}</ng-template>
<div class="tab-content">
{{ obj.name }}
</div>
</mat-tab>
</mat-tab-group>
</mat-card-content>
CSS: -
.tab-group {
border: 1px solid #e8e8e8;
margin-bottom: 30px;
.unicorn-dark-theme & {
border-color: #464646;
}
}
.tab-content {
padding: 16px;
}
mat-card{
padding: 0px;
}
.mat-tab-label .mat-ripple {
min-width: 0;
height: 30px;
}
I'm not able to change height width background colour of these tabs.. :(
You cannot access the styles of child components from your css-file as the ViewEncapsulation.Emulated prevents styles from leaking to the rest of the app (as it should, don't change it).
If you use the ng-deep-selector like this: :host ::ng-deep mat-tab { ... } you can override default material styles that cannot be configured in any other way. I say that because making css leak from a component is considered a bad practice and if possible you should use #Input to pass on styles.
By the way, the :host is there so the styles leak only to this components children and not to the rest of the app
To override default style of angular material elements you need to prefix ::ng-deep in CSS style.
This is how you can control height and width of tabs
::ng-deep .mat-tab-label{
height: 27px !important;
min-height: 0px!important;
margin: 3px!important;
}
I'm trying to create a HTML widget:
HTML:
<div>
<h1 class="title" data-bind="title">Title</h1>
<div>
<h1 id = "dc1" class="dc">DC1</h1>
</div>
<div>
<h1 id = "dc2" class="dc">DC2</h1>
</div>
<p class="updated-at" data-bind="updatedAtMessage"></p>
</div>
And I need to be able to set the background color of the id="dc1" and id="dc2" elements dynamically in CoffeeScript. I plan to do this by adding a class with a background color setting:
SCSS:
&.up {
background-color: green;
}
&.down {
background-color: red;
}
.dc {
background-color: orange;
font-size: 30px;
float: left;
width: 50%;
}
So far I have managed to set the whole widget background but not the child elements mentioned above:
I have been using:
CoffeeScript:
$(#node).removeClass('up down')
$('#dc1').removeClass('up down')
$('#dc2').removeClass('up down')
$(#node).addClass('down')
$('#dc1').addClass('down')
$('#dc2').addClass('up')
Note ultimately I will add the classes depending on some data rather than hard coding them to 'up' or 'down' in the coffeescript.
But nothing happends.. Am I getting selecting the id="dc#" elements correctly?
If it helps with context I'm doing this for Dashing
Your SCSS doesn't make sense so I'd guess that your missing an error from the SCSS-to-CSS conversion. An & in SCSS is a reference to the parent selector:
& will be replaced with the parent selector as it appears in the CSS
so have &.up at the top level makes no sense and should generate an error. If we fix the SCSS so that .up and .down apply only to .dc:
.dc {
/* ... */
&.up {
background-color: green;
}
&.down {
background-color: red;
}
}
then everything seems to work just fine.
Demo: http://jsfiddle.net/ambiguous/9y9uywm9/
You can use Sassmeister (and other similar online tools) to see what SCSS thinks of your original SCSS.