How do I style hyperlinks separately, using CSS? - html

I want to style different hyperlinks in different ways. Right now, I have a button that is a hyperlink, and I want to add a text that should act like a hyperlink too. How do I do this without styling both hyperlinks together. I want each hyperlink to have different colors, positioning etc.
CSS
.example2 {
text-decoration: none;
font-size: 14px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: bold;
background-color: #CC4A31;
color: #444;
border-radius: 9px;
position: absolute;
top: 16px;
left: 38px;
height: 50px;
width: 145px;
webkit-box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.125);
box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.125);
vertical-align: middle;
text-align: center;
line-height: 50px;
}
.example {
color: black;
}
HTML
<div class="example2">
GameTrade
</div>
<div class="example">
Sign in
</div>
Now how do I add another hyperlink, that is styled separately?

What you call styles, is, in case you don't know also called CSS, which stands for Cascade Style Sheets, this type of language allows you among other things to specify an hierarchy between rules.
Having said this, in CSS you can have 3 basic types of style rules, the ones that target the TAG of elements, the ones that target the class of elements (<a class="foo">my link</a>) and the ones that target elements by ID (<a id="btnSubmit">submit</a>), I obviously hide much information here with the intent to make it simple for you to understand.
So to achieve your end, you can create a rule that targets elements with TAG <a>, and in rule you specify the properties that are generic to all links.
This gives you what you already have, now to target different links you have two options or you give then diferente IDs and you target each separately, or you add one class to the class attribute so you can distinguish between both.
Here is an example:
HTML
<a class="link-trade1" href="">GameTrade 1</a><br/>
<a class="link-trade2" href="">GameTrade 2</a>
CSS
a {
text-decoration: none;
font-size: 14px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: bold;
background-color: #CC4A31;
color: #444;
border-radius: 9px;
webkit-box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.125);
box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.125);
vertical-align: middle;
text-align: center;
}
.link-trade1{
position: absolute;
top: 16px;
left: 38px;
height: 50px;
line-height: 50px;
width: 145px;
}
.link-trade2{
position: absolute;
top: 16px; /* other y position for the link 2 */
left: 38px; /* other x position for the link 2 */
height: 50px;
line-height: 50px;
width: 145px;
}
You can switch the class name for IDs if you don't intent to reuse the rules targeting that specific classes.
Anyway there is a very good book you can read, if you are new to CSS and HTML, by Freeman.
Happy Coding.
Update
The updated question is a good example, just watch this:
/* this rule targets all hyperlinks inside, elements (div in your case) with attribute class="example" */
.example a{
...
}
/* this rule targets all hyperlinks inside, elements with attribute class="example2" */
.example2 a{
...
}
So as you can see, remember the hierarchy I was talking about? Is because of this, in the example just above you first target specific div's the ones with example class or example2 class and then you specify which elements to style inside them. You can build more elaborated rules!

Using your HTML
<div class="example2">
GameTrade
</div>
<div class="example">
Sign in
</div>
I'm guessing the styling isn't working because there is CSS overriding yours. Try this CSS:
.example2 a {
color: #444;
}
.example a {
color: black;
}
If that doesn't work try adding !important tags.

Related

Change the style of a button from one page without affecting the other buttons from other pages

Any ideas on how i can execute this?
button {
background: #1c00b5;
width: 100px;
border: none;
outline: none;
color: #fff;
height: 35px;
border-radius: 30px;
margin-top: 20px;
box-shadow: 0px 5px 15px 0px rgba(28,0,181,0.3);}
i have tried to add "body .contact button" to let css file know it is the contact us page i am editing but it wont work it only goes to change the style on my other pages aswell so essentially.
body .contact button {
background:
but this doesnt work, any ideas how i can change the style of this button without affecting the others in my css file?
The .contact does not mean the contact page but instead refers to a class called contact.
You could give each of the buttons a different class for example if you wanted one to be red and the other blue:
HTML page 1:
<button class="button-red">This is a red button</button
HTML page 2:
<button class="button-blue">This is a red button</button
CSS file:
.button-red {
background-color: red;
}
.button-blue {
background-color: blue;
}
Just change the colours to your own styling.
Hope this helps.
You really need to search online for 'CSS selectors' and learn how and why to use them.
An example: create CSS rules that are true for all button and create exceptions to those rules using specific selectors. E.g. all buttons are green, except a contact button is red.
The generic rules can be put in a separate CSS file and <link>ed in a document. Create the specific rules in-document with a <style> block to override/modify/add to the linked generic rules.
There are many alternative ways to solve your issue, this is just one of them...
Tip: CSS rules are nothing more than an eleborate list of logical statements varying from easy to virtually unexplicable selectors to modify the style of your document:
if selector,
list-of-selectors,
very-special-selectors
what-does-this-one-do?!?-selector then { property: value }
example
/* put this in an external CSS file */
button { background-color: green }
/* put this in a <style> block */
button.contact { background-color: red }
<button>generic 1</button>
<button>generic 2</button>
<button>generic 3</button>
<br>
<button class="contact">contact</button>
Suppose we have a button
<button> your text </button>
and we ave to use this CSS/style
background: #1c00b5;
width: 100px;
border: none;
outline: none;
color: #fff;
height: 35px;
border-radius: 30px;
margin-top: 20px;
box-shadow: 0px 5px 15px 0px rgba(28,0,181,0.3);
so, we will add a id to button like
<button id="contact-btn"> your text </button>
and then add style using id selector
#contact-btn{
background: #1c00b5;
width: 100px;
border: none;
outline: none;
color: #fff;
height: 35px;
border-radius: 30px;
margin-top: 20px;
box-shadow: 0px 5px 15px 0px rgba(28,0,181,0.3);
}
it will work thanks

Why is the "box-sizing" property throwing off display of my "i" icon?

I want to have one of those "i" icons appear next to a name on my site so people can click on it and look up more information. I have this HTML
<div id="personName"><h2>PersonA</h2> <div id="moreInfo">i</div></div>
and the below style
#personName {
display: block;
}
#moreInfo {
border-radius: 50%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
width: 36px;
height: 36px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
font-weight: bold;
font-style: italic;
display: inline-block;
}
The problem is I also have this style
* {
box-sizing: border-box;
}
which I need for a lot of other elements on my site and it seems to be throwing off the way my "i" graphic is appearing -- https://jsfiddle.net/ds9sqr0y/ . It also doesn't seem to be appearing next to the name, but maybe that's a separate issue.
That's because box-sizing: border-box includes both the border and the padding in the height computations.
Which means that if you create an element with height: 30px and padding-top: 5px, it will be 35px tall (height + padding) but with setting box-sizing: border-box, it will be 30px tall.
In your specific case, you can increase the height and width to the following to make it look like you want to:
width: 57px;
height: 57px;
As per Jesse de Bruijne's answer, you can set the padding property within the #moreInfo selector to 0. If you can, try and reduce the font size of the i, to better position it (I'm using Chrome). Setting it to 30px seems to show it better.
#moreInfo {
...
padding: 0;
font: 30px Arial, sans-serif;
...
}

Box with Fading Out Edge/Border

I am trying to create a box that has a 'highlight' down the sides of it, and at the top.
The CSS for the box was pretty simple, however, now that I introduced this 'highlight' to the design, it has added another level of complexity to the CSS...
I have tried a lot of things, not sure if they will help but here is my most recent:
/* Define the Main Navigation Drop Downs */
#mn_navigation .dd {position:relative;width:226px;padding:29px 0 0;background:transparent url("//beta.example.co.uk/_images/_global/dd_handle.png") no-repeat;z-index:1000;}
#mn_navigation .dd nav {padding:30px 0;background:#3E5032 url("//beta.example.co.uk/_images/_global/dd_bg.png");border-radius:3px;}
#mn_navigation .dd nav a {font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#fff !important;height:25px;line-height:25px;}
Please note I have posted the above to show that I have actually tried to sort this myself. The above code will probably not even help as a starting point as a restructure of the HTML may be necessary!
Here is the current HTML (probably needs to be restructured):
<div id="dd_foo" class="dd">
<nav>
LINK
</nav>
</div>
Here is a possible restructure (something like):
<div id="dd_foo" class="dd">
<div class="handle"><!-- Dropdown Handle --></div>
<nav>
LINK
</nav>
</div>
This is what I need the box to look like (notice the faint white border at the top and half way down the sides):
I have also included the box split into its separate elements (handle and background)
I think I can see how this can be done with clever overlaps and nested divs, but ideally I don't really want to resort to this... Can anybody suggest an alternative solution?
Simplest approach
You can try achieving this using a simple box shadow:
.plaque {
box-shadow: inset 0 1px 1px 0 rgba(255, 255, 255, 0.32);
/*...*/
}
An Example
Here's an example using 1 class and a div on jsbin.
Copy paste code
This code is only for modern browsers; it might cause ie < 9 and other non supporting browsers to explode.
.plaque:after {
top: -9px;
content: " ";
height: 11px;
width: 30px;
position: absolute;
pointer-events: none;
left: 50%;
margin-left: -15px;
display: block;
background-repeat: no-repeat;
}
.plaque {
width: 250px;
height: 100px;
display: block;
border: 0;
outline: 0;
padding: 12px 16px;
line-height: 1.4;
box-shadow: inset 0 1px 1px 0 rgba(255, 255, 255, 0.32);
border-radius: 5px;
border: 1px solid transparent;
font-family: sans-serif;
color: white;
font-size: 1.2em;
text-overflow: ellipsis;
position: relative;
top: 6px;
}
/* Use whatever background you want */
.plaque { background-color: green; }
.plaque:after { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAALCAYAAACZIGYHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAcJJREFUeNqMUktPU0EU/mZuL6Up1RCjC4oRau4t4FJ84EKID/ZAjI9/6Mo/4MadG5dqJGjBatpyuY+2UNreeXDOBE0MNHGSSWZyzvnOd77zicdbd+EVJKyxGPSHmC4XIYSAMQYCoJhn81wJKSnHWhR8D1oZl69yhamiD8GBSefpywc2XKzjy7fP+PDuk5iUJxnksvvkxX1buxkgThOEt5exvr1qJ+XKy5CfvXpow9oSsn6GdqeF40EPK+GKY/ZfTNa3Vm1AI6TdFAeNfQgp0CKgrJehVg1AGl5gJLTWfxGfv15zI3BBnB5CehJGG5Cw8EjY6tw8KjNXsfv9K96//SguMOERgoU6+ic9NH8eQClNGzDQBMLb4FU1fzdxFB+hev0WNnbu2X802TxnkGQJoriNymwZHrFgAbhdidbOK+YTxR0ojLEc3sHmm0dOI8Gq10n9OI1xGLVcMvuGGYyHOYqlKcfK9wvOF3/i12ZvoFK+gsavPUgGSLsJkm4En4xDTqMi45iUZqZdd34zJY7L8was2enoGMHCEmS3l6LxYx9qrJ2I7FTNelBxPlKuYDgYu9nzUe6cenoygqF/J2o7AmcCDACumSjtgWp8aAAAAABJRU5ErkJggg==); }

Windows 8: Creating AppBar Style Buttons with HTML5/CSS

For a Windows 8 Application, I can create AppBar style buttons using 'Segoe UI Symbol' but they have drawn in a rectangle area therefore has a rectangle background. Since I want to set their background to a different color during hover, I need to get rid of this rectangle.
As pointed out in below question, the button and the style are defined like shown.
Please give a direction how this can be accomplish.
create image from character
HTML:
<button id="myAppBarIcon" class="normal-size-icon"></button>
CSS:
.normal-size-icon {
margin-top: 400px;
margin-left: 630px;
position: relative;
font-size: 24px;
font-family: 'Segoe UI Symbol';
color: rgb(255, 255, 255);
background: none;
border: none;
}
Update:
Below code does the trick but font is not properly aligned. Probably because it is not made to align properly. Image below shows the layout.
.normal-size-icon {
font-size: 24px;
font-family: 'Segoe UI Symbol';
color: rgb(555, 255, 255);
min-width: 0;
min-height: 0;
border-radius: 50%;
border-style: solid;
padding: 0;
text-align: center;
}
For this point you need to set border-radius:50%; so you your button will change shape to circle then add min-width:0; min-height:0; and text-align:center; here is the full css :
.normal-size-icon {
font-size: 24px;
font-family: 'Segoe UI Symbol';
color: rgb(555, 255, 255);
min-width: 0;
min-height: 0;
border-radius: 50%;
border-style: solid;
padding: 0;
text-align: center;
}
if you don't need border you can set border:none;. Sorry for my bad english
This behavior is driven by the CSS hover selector, and the default CSS there for a button will provide something that aligns with the light or dark theme, e.g.,
button:hover, input[type=button]:hover, input[type=reset]:hover,
input[type=file]::-ms-browse:hover {
background-color: rgba(255, 255, 255, 0.13);
border-color: rgb(255, 255, 255);
}
You could override this very specifically with something like:
.normal-size-icon:hover {
background-color: red;
}
but there are likely additional states and objects for which you'd want similar treatment.
Take a look at the ui-light.css and ![ui-dark.css][1] that's included in your References; all the answers are in there :)

Text on top of image works without Z-index, why?

I want to display a subtitle text, running over the top of an image, aligned to the bottom (of the DIV containing the image).
I was expecting I'd need to use Z-Index but for some reason it works without. I'd really like to understand why.
Here's the HTML:
<div class="latest-item">
<img src="images/latest-image-placeholder.png" alt="latest-image-placeholder"/>
<div class="latest-item-copy">Bad schools, flawed justice create crime. Test Bad schools, flawed justice create crime. Test </div>
</div>
And here's the corresponding CSS:
.latest-item {
height: 130px;
background-color: fuchsia;
margin-bottom: 20px;
overflow: hidden;
position: relative;
}
.latest-item-copy {
width: 220px;
/* Fallback for web browsers that doesn't support RGBa */
background: rgb(0, 0, 0);
/* RGBa with 0.6 opacity */
background: rgba(0, 0, 0, 0.6);
bottom: 0px;
position: absolute;
padding-left: 5px;
padding-right: 15px;
padding-top: 2px;
padding-bottom: 4px;
box-sizing:border-box;
-moz-box-sizing:border-box; /* Firefox */
-webkit-box-sizing:border-box; /* Safari */
font-family: Georgia, Times New Roman, serif;
font-size: 14px;
line-height: 18px;
color: #F1F1F1;
font-weight: bold;
}
And here's what it outputs: http://i.stack.imgur.com/Hdl9l.png
When you position an item absolutely, it pulls the element out of the document flow. It's the same thing that happens when you float an element. They automatically get placed in a different "layer" that has a higher z-index.
Because you're using position: absolute