Equal the value of a CSS property based on another property - html

I have in my CSS:
body
{
font-size: 0.87em;
font-family: Calibri, Arial, Georgia, Verdana, Tahoma, Microsoft Sans Serif;
margin: 0;
padding: 0;
color: #666666;
}
a:link
{
color: rgb(124,71,111);
text-decoration: underline;
}
a:visited
{
color: rgb(41, 12, 36);
}
a:hover
{
color: rgb(91,25,79);
text-decoration: none;
}
a:active
{
color: #AB6D9C;
}
the question is to the latter tag ".remove-linkcolor"
.remove-linkcolor
{
}
I would like the links to 'a' that is associated with the class '.remove-linkcolor' the following attributes are changed:
The color is the same color of normal text
How to avoid duplication of code and put the same color of another tag?
Remove effects of active, hover normally would, but to continue as a link, so if you click the User, the same is executed.

Not sure I understand your question 2. However, I think this is the answer you need:
The only way to remove duplication of code in CSS is through combined selectors, something like:
body {
font-size: 0.87em;
font-family: Calibri, Arial, Georgia, Verdana, Tahoma, Microsoft Sans Serif;
margin: 0;
padding: 0;
}
body, .remove-linkcolor {
color: #666666;
}
But then you end up repeating the selector, often. The only other way is not to do CSS: use SASS or similar CSS compiler.

Related

Why is the 'initial' property not working for me?

I'm trying to create something like a native styling rule for the interactive html elements I use, therefor I'm using a type-selector, which if exchanged with the class-selector makes no visible difference at all - as far as I and the dev-tools can tell. I'm using the initial property to reset my custom to the browser's native styling. BUT whatever I try - it won't work out. My concern is that I'm doing something just slightly wrong, but I just can't tell. Please help me out! Thanks in advance!
I've posted an example of all my code I use so far below to make following along easier.
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
line-height: 1.5;
-webkit-text-size-adjust: 100%;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
font-size: 1rem;
}
ul a, ol a {
text-decoration: none !important;
}
a {
color: #2196f3;
background-color: transparent;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a[type="nativeStyling"] {
color: initial;
background-color: initial;
text-decoration: initial;
}
a[type="nativeStyling"]:hover {
text-decoration: initial;
}
I'm an anchor tag
The initial value is applying to your a element just fine, the problem is that it doesn't do what you think it does. It resets the value to the initial value for that property (which, in this case, is black).
This is not the same as the default value for that property plus the effects of the browser's default stylesheet.
You might want the revert value, but that is currently only supported by Firefox and Safari.
a { display: block; color: pink }
.i { color: initial; }
.r { color: revert; }
<a class="i" href="http://example.com/">One</a>
<a class="r" href="http://example.com/">Two</a>
<a class="x" href="http://example.com/">Three</a>

How to stop a:link from being applied to all links

I have the following css that is used to make one link coloured but it applies to all of the links I have. Is there any way to stop this.
This is my css that is getting applied to the links:
a:visited {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 14px;
font-style: italic;
font-weight: bold;
color: #FFF;
text-decoration: none;
background-color: #F00;
display: block;
border-radius: 5px;
z-index:10;
}
a:link {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 14px;
font-style: italic;
font-weight: bold;
color: #FFF;
text-decoration: none;
background-color:#F00;
display: block;
border-radius: 5px;
z-index:10;
}
a:hover {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 14px;
font-style: italic;
font-weight: bold;
color: #CCC;
text-decoration: none;
background-color: #C00;
display: block;
border-radius: 5px;
z-index:10;
}
This is the link that it is suppose to get applied to:
<td>Food</td>
This is the link that I don’t want it to get applied to:
<td class="footer"><b>Top Attractions</b>
You could select your a tag by the href like this:
JSFiddle - DEMO
a[href="Food.html"] {
color: red;
}
Updated: DEMO (with your codes)
Working JSfiddle: demo
I gave the link you wanted to style a class and gave the class a style.
a.food :visited
instead of a:visited
Try this
HTML
<td><a href="Food.html" class="colored>Food</a></td>
CSS
.colored{
color:red;
}
One thing you could do, would be to give the tag an id/class and then refer to that in your css.
You could add a class to the link you want different and style it separately.
HTML:
<td class="footer"><b>Top Attractions</b>
CSS:
a.rides {...}
Apply a class to the links you want to effect:
<a href='food.html' class='apply_to_this'>Food</a>
Then in your CSS:
a:link.apply_to_this{
// your styles
}
You can add a class to the links you wan't to apply this rule, or you can use this rule :
a:not(.footer):link {...}
Rather than stopping it being applied to one link, you need to add a class to that link with additional CSS that overrides the styles you want to change, or (though this is bad practice...) use inline styles on that one link.
Proper solution:
In your CSS
.exception {put css here that will override the general link css, using !important to override it ifnecessary}
In your html
Content here
Quick and dirty solution
Content
Though this way will work, it is rightly frowned upon for accessibility issues.
You can just create a class and apply it to that link like mentioned above or you can just follow through your selectors to tell CSS to apply that link code to only a:links within those selectors like I've posted below:
#mainContainer #footer #etc #etc a:link {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 14px;
font-style: italic;
font-weight: bold;
color: #FFF;
text-decoration: none;
background-color:#F00;
display: block;
border-radius: 5px;
z-index:10;
}
PS - Inline styles are very bad practice. It adds tons of extra code that will reduce your rankings for Google, Yahoo, MSN, etc. Not to mention it makes code harder to read and more clunky.

Font size in css

I just want to make my text bigger. I tried em, px,% and pt, but it's still one size. What's wrong?
UPD:
Thanks everybody, but I don't need your help anymore. I did it. Also I can't delete this question.
body {
font-family: 'Trebuchet MS', Helvetica, sans-serif;
font-size: 2em;
color: #717171;
}
a {
color: #3298BA;
}
a:hover {
color: #D62C88;
text-decoration: none;
}
Your CSS is correct. It is working just fine. Here is your code. Which one I tested.
http://jsbin.com/ayihet/1
Change to:
body {
font-family: 'Trebuchet MS', Helvetica, sans-serif;
font-size: 2em !important;
color: #717171;
}
It's not the best solution, but given what we're presented with it's the only way I can think of solving the issue.

square bullet list wrong font size with body css

I have a list in my sidemenu, the settings don't seem to read past the css of the .body class in stylesheet -
ul.develop
{
list-style-type:square;
color: #FFF;
margin:0;
padding:0;
margin-top:0.6cm;
}
li.develop
{
font-family: 'Arial', sans-serif;
font-size: 11px;
font-weight: normal;
color:#fff;
}
My body class is -
body {
font-family: 'Arial', sans-serif;
font-size: 12px;
font-weight: normal;
}
The list then is defaulting to body class 12px, if I change body to 11px, the list is fine but I want to keep 12px for actual body of main content of copy on site.
I tried using !important but unsure that is correct?
Thanks
I think you may have .develop on ul not li, try putting your font rules on the ul.develop rule as they will apply to the li's underneath.
ul.develop
{
list-style-type:square;
color: #FFF;
margin:0;
padding:0;
margin-top:0.6cm;
font-family: 'Arial', sans-serif;
font-size: 11px;
font-weight: normal;
}
Put your 'body' related CSS above/ before the other styles. It reads it top down. Hope that works!

two conditions in one with css possible?

hello i have a question according css.
in my navigationbar i have 3 links. i use:
#p1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 45px;
font-weight: bolder;
color: #999999;
text-decoration: none;
}
for that status that shows on which site the user is located.
if the user rolls over the other two links i have these:
#p2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 45px;
font-weight: bolder;
color: #ECECEC;
text-decoration: none;
}
#p2:hover {
font-weight: bolder;
color: #999999;
cursor:default;
}
#p2:active {
font-weight: lighter;
color: #999999;
}
okay, the problem is that i would like to change the color from p1 when the user hovers p2. meaning something like:
#p2:hover {
font-weight: bolder;
color: #999999;
cursor:default;
#p1 {
color: #f23;
}
}
is that possible?
thanks a lot.
the html:
<div id="nav">
<div id="link"><p1>link1</p1></div>
<div id="link"><p2>link2</p2></div>
<div id="link"><p2>link3</p2></div>
<div id="link"><div id="login"></div></div>
</div>
This can't be done with pure CSS.
What you can do is to use javascript & change color of #p1 on the hover event of #p2.
OR you may use less css to set color of #p1 to a variable & change the value of that variable in #p2:hover, though I have not tried this method. But again less css is not pure css, it uses javascript too.
With javascript (using jquery library), your code will be:
$("#p2").hover(function() {
$("#p1").css('color', '#f23');
});