So it looks like if I add style such as background color to LinkButton in my .cs code, it overrides any css I have that applies to it.
is there any way to add style rather than replace it in my code behind? Thanks!
I am using link button as a menu, so active linkButton should have different background color.
so my solution was when the user clicks on the link button in my event handler I do something like:
lnkView.BackColor = System.Drawing.Color.FromName("#369");
But then my hover style which I have in my css will no longer work:
.navlist a:hover
{
color: #fff;
background-color: #369;
text-decoration: none;
}
in my aspx:
<ul class="navlist">
<li><asp:LinkButton ID="lnkView" runat="server">view</asp:LinkButton></li>
<li><asp:LinkButton ID="lnkCreateNew" runat="server">create new</asp:LinkButton></li>
</ul>
EDIT: Your question is unclear, but you appear to be mis-understanding CSS. Adding background-color to the style property will not cause it to completely ignore any CSS rules. Rather, it will override any CSS rules for the background-color property, but will not affect any other rules.
If you don't want to override the background-color property from the CSS rule, add the !important flag to the CSS rule in :hover, like this:
background-color: #369 !important;
Also, change the color so that the change wil be noticable.
Alternatively, you could add a new CSS rule for .navlist a:link .Active with your background color, then add the Active class in code. (lnkView.CssClass += "Active")
By the way, instead of calling Color.FromName, you should write Color.FromArgb(0x33, 0x66, 0x99).
Any inline styles will always override any inherited styles from the head of a document or an external css file. The only other option would be to add a javascript function that overrides the style of the object after DOM ready or Window ready event.
Not sure of your use here, as your question isn't real clear. However this could be an option as well.
Have two css styles:
.navlistafteranaction a:link
{
color: #fff;
background-color: #123;
text-decoration: none;
}
.navlist a:link
{
color: #fff;
background-color: #123;
text-decoration: none;
}
Then in your code behind just switch your CSSClass:
lnkbtn.CssClass = "navlistafteranaction";
This would change the class to have whatever style you wanted after the fact.
If I understand what you want correctly, you want different styles applied based on whether the linkbutton is being hovered over? So, have the style you have but also have:
.navlist a:link
{
color: #fff;
background-color: #123;
text-decoration: none;
}
if you want a third color, for after a link is visited, define that with a:visited. Is that what you're after?
Related
How can I target the underlying html textarea of a vuetify v-textarea with css? In my case I want to change the line-height, font-family, color and more of the v-textarea. It doesn't work like this:
<v-textarea class="custom-textarea"></v-textarea>
.custom-textarea {
line-height: 1;
color: red;
}
I also tried several other selectors like v-textarea, .v-textarea, v-text-field__slot but none of these worked either. What is the right selector for the textarea?
In order to override a deep element, you need to access the element through deep selectors like
::v-deep .v-textarea textarea
More information about deep selectors
.custom-textarea textarea {
line-height: 1;
color: red;
}
Set id prop of text-area and apply css style by id.
<v-textarea id="input-7-2"></v-textarea>
#input-7-2 {
color:white;
background-color: green;
line-height:1;
}
Codepen demo
Here is my CSS
.button-1 {
background-color: #f7f1e3;
border: none;
color: #393939;
padding: 12px 12px;
font-size: 14px;
cursor: pointer;
font-family:Montserrat;
font-weight:400;
font-style:normal;
}
.button-1:hover {
background-color: #aaa69d;
color: #393939;
}
And here is the HTML
<button class="button-1">
Click Me
</button>
So, there's nothing at all complicated here but I have got stuck on the most efficient way to add a basic HREF tag for a link.
If I add a simple link in the text area of the button then I get the generic styles.
Now, of course, I can create a CSS A Class for the button but I have several of these and it is just going to create a lot more code.
My question is: what's the most efficient way? Can I not just add the Link Class to the button-1 CSS directly?
Thanks!
To be specific, you should make a new selector to <a> element inside the button:
.button-1 a{}
also, if you want to remove all "generic styles" from your <a> tags you can create generic selector for links.
a{
color:inherit,
text-decoration: none
}
or even a * selector for all elements
*{
color:inherit,
text-decoration: none
}
PD: If you add padding style to button element and inside of this a <a> element, the padding area won't be clickable for link, I recommend you to add padding to <a> element.
So, I need to remove a visited link coloring from my navigation bar, as it will look ugly.
I have tried to use text-decoration: none; and color: white; but that does not seem to help it.
CSS for navigation
Actual code
I removed the actual links from the code, in the real version there is link but for this question links are replaced with #
In addition to Bariock's answer, this will help reset your <a> links in all circumstances to your specified css.
a:visited, a:hover, a:active, a:focus {
color: yourColor !important;
text-decoration: none !important;
outline: none !important;
}
The !important signifies that it has a higher precedence than that of other rules declaring the same values for the same selectors. Note: you can still style them separately such like you would with :hover.
a:visited{
color: your-color;
}
I edited the <a> tag to go around the <button> so the text is back to white now and the button actually works. It is no longer just "click text to visit link" the whole button works.
<button class="dropbtn">Community</button>
Try adding a !important to the end of the css styles like so:
a {
color: white !important;
}
Hope this helps!
I recommend you first set the style of the link tag, for example:
.dropdown a{ color:#fff }
now your text links inside the container with the class .dropdown will be as white color. Then you don't need to set a visited link color, unless you want to set it.
If you want to get rid the underline in the link, your style will be like this:
.dropdown a{ color:#fff; text-decoration: none; }
Not sure what I did last night but now I get up this morning and chrome seems to be overriding my anchor and input styles. I wish there was a snippet of code I could post here but I have no idea what code could possibly be causing it. i don't want to put !mportant all over the place to fix it so I am hoping someone can look at the test site and figure out what chrome doesn't like.
The headerWidgets at the top of the page (email, phone, and search) should not have decoration and should change color on hover. I can't even place the cursor in the search input anymore. And the nav menu shouldn't have decoration, but the hover works. Go figure. chrome dev tools shows me this:
a:-webkit-any-link { user agent stylesheet
color: -webkit-link;
text-decoration: underline;
cursor: auto;
}
and a bunch of user style sheet entries for input
a:-webkit-any-link {
color: -webkit-link;
text-decoration: underline;
cursor: auto;
}
is the default styles of webkit for the a tag.
Add a css selector #email a,#phone a and put the styles you want inside. Like this:
#email a,#phone a{
text-decoration:none;
}
and for the hover:
#email a:hover,#phone a:hover{
color:red;
}
A better selector to target all anchor tags inside #headerWidgets
#headerWidgets a {
color: #F00;
}
#headerWidgets a:hvoer {
color: #CCC;
}
And the reason why you cant click on your search box anymore is that div#headerMenuWrapper is blocking the way. On dev tools hover on this element <div id="headerMenuWrapper" class="clearfix"> you will see it covering #headerWidgets
I want my links*** to change color when clicked, but also change color when hovered over.
I got a javascript function to change the color when clicked, but it requires inline CSS which is keeping my style sheet's hover from working.
Is there a way to have the inline CSS and CSS stylesheet not cancel out? Or is there another way to change the color of the link when clicked that wont cancel out the hover color?
*(These links are being used to show a hidden div using javascript)
script:
function toggle_link(select){
var color = select.style.color;
select.style.color = (color == "white" ? "yellow" : "white");
}
html:
<div id="gdtitle">
<a class="port" href="#" onclick="toggle('gdhide');toggle_link(this);" style="color:white">Graphic Design</a>
</div>
css style sheet
a.port{
text-decoration: none;
color: white;
}
a.port:hover{
text-decoration: none;
color: yellow;
}
You could use !important to override inline css
Better yet, don't but alter the behaviour of your toggle_link - would you rather add a class to the element and style it instead?
Use the :link, :visited, and :active pseudo-classes on the <a>.
CSS:
a.port, a.port:link, a.port:visited, a.port:active {
text-decoration: none;
color: white;
}