How to keep active state on anchor links? - hyperlink

Preview: http://cssdeck.com/labs/w7bzvb5r
Is it possible to keep the navigation link active once clicked and inactive when not selected? I would like it to change color based on which link is selected. For example, on mouse-over it changes from black to blue. How can it stay blue when it is active and black when inactive?

If what you are after is to keep the text of the link on the active page in a certain style the answer is it is possible.
There are many ways to approach this. Based on the example provided replacing this:
#firstPage { color: #eee; }
#firstPage/slide2 { color: #ddd; }
#firstPage/slide3 { color: #aaa; }
#firstPage/slide4 { color: #ccc; }
with the following will work:
.fp-viewing-firstPage nav#main a:nth-child(1) { color: #eee; }
.fp-viewing-firstPage-slide2 nav#main a:nth-child(2) { color: #ddd; }
.fp-viewing-firstPage-slide3 nav#main a:nth-child(3) { color: #aaa; }
.fp-viewing-firstPage-slide4 nav#main a:nth-child(4) { color: #ccc; }
This is using CSS3 selectors referenced here: https://css-tricks.com/almanac/selectors/n/nth-child/
.fp-viewing-firstPage is a class applied to your <body> that changes on navigation.
Setting the id or class on each link is another option.

Related

Change colour of a menu option depend a value

My application have a menu options and I need to change the color of a menu option depend of the selection of a textbox.
In the controller file I wrote this:
[HttpPost]
public ActionResult Rise(int rise)
{
Session["Var1"] = rise;
if (rise != 0)
{
ViewBag.Var1= "class = active";
}
else
{
ViewBag.Var1 = "class = visited";
}
return View();
}
In my css file I wrote this:
a:visited
{
font-size: large;
color: green;
}
a:active {
font-size: large;
color: blue;
}
a:link {
font-size: large;
color: #ffffff;
}
a:hover {
background-color: lightblue;
}
And in my view I wrote this:
<li>Option1</li>
When I execute the application and I write a value in the textbox and click on the submit button I see that the menu option change the colour and change to Green colour again.

How can I change the placeholder color in Ant Design's Select component?

I want to change the placeholder color of Select component in Ant Design.
I've tried these below, but none of them work.
.ant-select-selection {
:placeholder-shown {
color: red !important;
}
&:placeholder-shown {
color: red !important;
}
:::placeholder {
color: red !important;
}
color: black !important;
&::-webkit-input-placeholder {
color: blue !important;
}
&:placeholder {
color: blue !important;
}
:placeholder {
color: blue !important;
}
::-webkit-input-placeholder {
color: blue !important;
}
}
::-webkit-input-placeholder {
color: blue !important;
}
I tried Hemanthvrm's suggestion, but it seems they changed the class name of the placeholder element to .ant-select-selection-placeholder in Ant Design 4. What worked for me was the following:
.ant-select-selection-placeholder {
color: #f0f0f0;
}
Please mind there's an opacity: 0.4; by default on the placeholder element, so whatever color you use will look faded out.
Also mind this placeholder styling behavior is not consistent across different Ant components. For example, to style the placeholder of the date-range picker I had to do the following:
.ant-picker-input input::placeholder {
color: #f0f0f0;
}
Bad news is, all these names might change again in a new major version. So better declare all the Ant related styles in one file, so your project becomes easily resilient to such changes.
This will work
.ant-select-selection__placeholder{
color : blue;
}
Working Sample
https://codesandbox.io/s/139lnkwwm3

angular 5 matsnackbar change action button color

I'm using MatSnackBar for my angular 5 project, and I cannot seem to change the color of the 'action' button.
I've injected the snack bar to my HttpInterceptor:
this.snackBar.open('Invalid Login', 'Ok', {
duration: 2000,
panelClass: ['my-snack-bar']
});
my css:
.my-snack-bar {
background-color: #E8EAF6;
color: #3D5AFE;
}
How can I change the 'Ok' action button color?
Version: "#angular/material": "^5.2.4",
You can access the colors with the panelClass option + the generated class ".mat-simple-snackbar-action".
My example:
snackbar.component.ts
private configSuccess: MatSnackBarConfig = {
panelClass: ['style-success'],
};
private configError: MatSnackBarConfig = {
panelClass: ['style-error'],
};
public snackbarSuccess(message) {
this.snackBar.open(message, 'close', this.configSucces);
}
public snackbarError(message) {
this.snackBar.open(message, 'close', this.configError);
}
snackbar.component.css
.style-success {
color: $primary-text;
background-color: $primary;
}
.style-success .mat-simple-snackbar-action {
color: $primary-text;
}
.style-error {
color: $warn-text;
background-color: $warn;
}
.style-error .mat-simple-snackbar-action {
color: $warn-text;
}
Extra info If using a mixin for custom themes you can do something like this to get all the colors:
#mixin snackbar($theme) {
$primary: mat-color(map-get($theme, primary));
$primary-text: mat-color(map-get($theme, primary), default-contrast);
$warn: mat-color(map-get($theme, warn));
$warn-text: mat-color(map-get($theme, warn), default-contrast);
.style-success {
color: $primary-text;
background-color: $primary;
}
.style-success .mat-simple-snackbar-action {
color: $primary-text;
}
.style-error {
color: $warn-text;
background-color: $warn;
}
.style-error .mat-simple-snackbar-action {
color: $warn-text;
}
}
As mentioned above one can customise the style of the snack bar using the panelClass configurationn.
this.snackBar.open(message, action, {
duration: 40000,
panelClass: "success-dialog"
});
The key here is to override via CSS the mat-simple-snackbar-action. This will do the trick of changing the action button text color.
.success-dialog {
color: white !important;
background-color: $success !important;
.mat-simple-snackbar-action {
color: white !important;
}
}
This worked for me:
.my-snack-bar button {
background-color: gray;
color: white;
}
Use this
.my-snack-bar {
background-color: #E8EAF6;
}
css in your style.css(or .scss) file. It will not work if you put anywhere else.
please add the following in app style.css
.mat-simple-snackbar { font-weight: 600; } // text
.mat-simple-snackbar-action > button { color: red } // action
enjoy!
For me, below code is worked.
::ng-deep snack-bar-container simple-snack-bar .mat-simple-snackbar-action {
color: black;
}
Steig's answer is correct but if that doesn't work then you should add /deep/ in front of your class:
/deep/ .my-snack-bar button {
background-color: gray;
color: white;
}
You can use this:
let mysnackbar: any = document.querySelectorAll('.my-snack-bar')[0];
mysnackbar.style.cssText += "color: #3D5AFE;backgroundColor: #E8EAF6";
it works for me.

Styling ionic 2 toast

Is there any way to style the text message within an ionic 2 toast?
I have tried this:
let toast = Toast.create({
message: "Some text on one line. <br /><br /> Some text on another line.",
duration: 15000,
showCloseButton: true,
closeButtonText: 'Got it!',
dismissOnPageChange: true
});
toast.onDismiss(() => {
console.log('Dismissed toast');
});
this.nav.present(toast);
}
But clearly you can't use html in the text so I am guessing the answer to my question is no?
You must add 'cssClass: "yourCssClassName"' in your toastCtrl function.
let toast = Toast.create({
message: "Some text on one line. <br /><br /> Some text on another line.",
duration: 15000,
showCloseButton: true,
closeButtonText: 'Got it!',
dismissOnPageChange: true,
cssClass: "yourCssClassName",
});
than you can add any feature to the your css class. But your css feature went outside the default page'css. Exmp:
page-your.page.scss.name {
//bla bla
}
.yourCssClassName {
text-align:center;
}
I was able to achieve a toaster color change by adding a custom class on the toaster create
let toast = this.toastCtrl.create({
message: 'Foobar was successfully added.',
duration: 5000,
cssClass: "toast-success"
});
toast.present();
}
In that pages scss file i then went outside the default nested page name ( because the toaster is NOT inside the root of ion page name thing). And all though this is a bit hacky i just explicitly targeted the next div element after the custom class that i added
.toast-success {
> div{
background-color:#32db64!important;
}
}
I say its hacky because you have to use the !important on it. You can avoid the !important by wrapping the .toast-success with .md,.ios,.wp{...
You can override the style default by overriding the main toaster variables in the theme/variables.scss file.
$toast-ios-background:(#32db64);
$toast-md-background:(#32db64);
$toast-wp-background:(#32db64);
This will only override the default value though and not a custom value. there are a few more variables that can be styled as well.
First, import toast controller from ionic-angular and make object of that in constructor.
import { ToastController } from "ionic-angular";
constructor(private _tc: ToastController) {
}
After that wherever you want to show your toast message write that.
let options = {
message: "Your toast message show here",
duration: 3000,
cssClass: "toast.scss"
};
this._tc.create(options).present();
Here is my scss:
.toast-message {
text-align: center;
}
Or you can check best example from this link. I think it will help you. :)
Or else check the answer on this link.
If you define your own css class in app.scss (not in page.scss)
you can style it with .toast-wrapper and .toast.message
No need to use > div{
Example:
.yourtoastclass {
.toast-wrapper {
background: blue;
opacity: 0.8;
border-radius: 5px;
text-align: center;
}
.toast-message {
font-size: 3.0rem;
color: white;
}
}
in theme/variables.scss you can make a default
Example (red and little transparent):
$toast-width: 75%; /* default 100% */
$toast-ios-background: rgba(153, 0, 0, .8);
$toast-md-background: rgba(153, 0, 0, 0.8);
Ionic 2 provide a very useful way to override their component style you can override the toaster SASS variable in src/theme/variables.scss by adding
$toast-ios-title-color: #f00 ;
$toast-md-title-color:#f00;
this will override the default style please refer to this Overriding Ionic Sass variable
You can accomplish, however you need to modify the toast component template itself.
Via explorer:
\node_modules\ionic-angular\components\toast\toast.js
Change line 194 (template):
{{d.message}} to <div [innerHTML]='d.message'></div>
You should be able to change any of the message styling in the css using .toast-message selector:
.toast-message {
font-family: Helvetica,
color: red
}
Or, if you look at the docs (http://ionicframework.com/docs/v2/api/components/toast/Toast/) there is a cssClass property you can use to assign your toast a specific class and then style that.
Change toast background color and opacity:
let toast = this.toastCtrl.create({
message: msg,
duration: 3000,
position: 'bottom',
cssClass: 'changeToast'
});
and add app.scss:
.changeToast{.toast-wrapper {opacity: 0.6; border-radius: 5px !important; text-align: center; background: color($colors, primary);}};
It's used with .toast-message
I tried all above, still didn't work, therefore I come across a new solution, you need cssClass outside of page css declaration:
let toast = this.toastCtrl.create({
message: msg,
duration: 3000,
position: 'bottom',
cssClass: 'toastcolor'
});
post-list.scss like this
page-post-list {
}
.toastcolor .toast-message {
background-color:skyblue;
}
Not sure about old Ionic versions, but in Ionic 5 you can't directly change inner CSS since it's encapsulated in the shadow
<ion-select>
#shadow-root
<div class="toast-container" part="container">
...
</div>
</ion-select>
so, to change .toast-container (for example) in your cssClass you should use:
.my-custom-class::part(container) {
flex-direction: column;
}
.my-custom-class {
.toast-container {
flex-direction: column; // will not work
}
}
I'm using ionic v5 with angular and
according to: https://ionicframework.com/docs/api/toast#css-shadow-parts
you can do something like this:
::ng-deep{
ion-toast::part(container) {
...
}
ion-toast::part(message) {
...
}
}

Using Bootstrap to Change Button Color

I'm using RoR to make a one-month rails website. This is the code from the styles.css.scss sheet. It utilizes bootstrap. I am unsure as to why but the button color does not change despite the $btnPrimaryBackground: green text. Does anyone have any ideas or thoughts on why the button color doesn't change? Thanks.
$baseFontFamily: Oxygen;
#import url(http://fonts.googleapis.com/css?family=Oxygen);
$navbarBackgroundHighlight: white;
$navbarBackground: white;
$btnPrimaryBackground: green;
#import 'bootstrap';
body{
padding-top: 60px;
}
#import 'bootstrap-responsive';
.navbar-inner{
#include box-shadow(none !important);
border: 0;
}
.footer{
margin-top: 50px;
color: $grayLight;
a{
color: $gray;
}
}
If you are using Bootsrap with LESS, you can simply do:
.btn-primary {
.buttonBackground(#yourColor, #yourColorDarker); //(button, hover)
}
If not then you simply override the button class which you want to change color:
.btn-warning { background-color: Your color; } //button
.btn-warning:hover { background-color: Your color; } //hover
Furthermore, since it appears you want to change the button color to green why dont you use the .btn-success class like so:
<%= button_tag "Hello", :class => "btn btn-success" %>
Source: Styling twitter bootstrap buttons
In Bootstrap 3 buttonBackground doesn't work anymore, you have to use button-variant(#color; #background; #border) like this:
.btn-custom {
.button-variant(#custom-color, #custom-color-bg, #custom-color-border);
}
You can also make your own and inherit from .btn-default. In SCSS like this:
.btn-custom { #extend .btn; #extend .btn-default; color: #6EA81A; }

Resources