How to change color of <hr/> element? - html

I tried all ways to change color of <hr/>:
hr{
border-color: yellow;
background-color: yellow;
color: yellow;
}
but it appears like this in both Chrome and FF:
How can I change its color to pure yellow?

Give hr a style with:
hr{
border:0;
margin:0;
width:100%;
height:2px;
background:yellow;
}
or
border:1px solid yellow;
JsFiddle
You need to get rid of the border or change the border's properties for it work.
From #Darko Z in the comments:
In many browsers the default style for HR is to add some sort of shading to the border so this comes out as dirty #whateverColourYouWant. To get rid of it, setting border explicitly (and not just border-color) is necessary.

To change the color of your horizontal rule, in your <hr/> tag, type the html attribute color="". Then you can go ahead giving it the desired color.

Related

Take control over text-decoration: underline without using border property

Ingredients: just an input tag of type text.
Question: How can I control the size, color, position of text-decoration: underline styling the input tag?
I saw that text-decoration-color is available but only in the moz web interpreter and I want something cross-browser like.
[EDIT] I accept JS, CSS, HTML, doesn't matter, but not any workaround: my question is specific, I want control over this specific attribute.
the easiest way is to remove the text decoration as :
text-decoration: none;
in your css file and use
border-bottom: 1px solid #FF0000;
instead of that, you can now change the color and size :)
what if you use
text-decoration: none;
border-bottom: 10px solid black;
so you have control over the border properties
You can simply use the CSS3 text-decoration-color property, it works with Chrome too.
Demo:
a {
text-decoration: underline;
-webkit-text-decoration-color: green;
text-decoration-color: green;
}
This is just a link
Note:
Notice the use of -webkit-text-decoration-color to make it compatible with Chrome.
You can check text-decoration-color Cross browser cpompatibility for further details about its browser support.
editing the text-decoration like, as you told, the color is possible. but font-size, position and more is hard. What you could do is instead of using the text-decoration is adding on your lets say <p> tag a border-bottom. Of this border you are able to change size and color. If you want to change the position or other things you should think of maybe adding a <div> with a <style> to edit all sort of things.
Use
text-decoration-color: #E18728;
text-decoration: underline dotted red;
Ref links:
https://css-tricks.com/almanac/properties/t/text-decoration-skip/
https://css-tricks.com/almanac/properties/t/text-decoration-style/
https://css-tricks.com/almanac/properties/t/text-decoration-line/
https://css-tricks.com/almanac/properties/t/text-decoration-color/
Here is another advanced way to get this done
HTML
<div class="underline-text"> This is Underlined text </div>
CSS
.underline-text{
position:relative;
padding-bottom:5px;
display:inline-block;
}
.underline-text:after{
position: absoulte;
bottom: 0px;
content: " ";
width:100%;
background:red;
height:2px;
left:0px;
}
Here is codepen.
https://codepen.io/sajiddesigner/pen/QvgeGO
You can do experiments there.
I Hope This example Help You :
a {
outline: none;
text-decoration: none;
border-bottom: 2px solid orange;
padding-bottom: 5px;
}
Hello World!
text-decoration is shorthand property for text-decoration-color, text-decoration-style and text-decoration-line.
syntax{
text-decoration : text-decoration-line text-decoration-style text-decoration-
color;
}
a{
text-decoration : underline red double;
}
So you can simple use text-decoration or individually define each property.
text-decoration-line - Is a style assigned to element and that can be underline, line-through, overline and such.
text-decoration-color - Is a color assigned to element.
text-decoration-style - Behaves much like
border-style, so you could use double, solid, dotted and such property values.
You can read more on this site.
And for compatibility with browser check on caniuse as some properties are partially supported.
a{
text-decoration-line:underline;
text-decoration-color:red;
text-decoration-style:double;
}
Text Decoration
Color and style of text-decoration
Text decoration is limited in CSS. The specs in CSS3 says you have these settings but actually only firefox supports them:
text-decoration-line
text-decoration-style
text-decoration-color
Size of text-decoration
You have a little bit control of the size of the line with font-style attribute. So as you can see it is relative to the font-size.
p {
text-decoration: underline;
}
#test1 {
font-size: 14px;
}
#test2 {
font-size: 40px;
}
<p id="test1">test 1</p>
<p id="test2">test 2</p>
Position of text-decoration
There is the attribute text-underline-position. But as the other attributes it is mostly not supported by the major Browsers. So sadly it is not possible to control the position of the text decoration.

IE8 border using pseudo :after

Alright IE8 gurus (does such a thing exist?). I need some assistance in fixing an issue that is a result of using an :after pseudo selector. It's pretty straight forward - just trying to add a border (underline) after a span tag on hover. No, the easy solution isn't just using the text-decoration property because the element inside the span tag is an image (and some other reasons).
Here's the HTML:
<div class="cta">
Hover over me
</div>
And here's the CSS:
.cta { position:relative; z-index:1; display:inline-block; }
.cta:after { position:absolute; z-index:1; left:0px; right:0px; bottom:0px; content:''; border-bottom:1px solid transparent; }
.cta:hover:after { border-color:rgba(0,136,204,.6); }
And for those of you really interested in helping and want to play around with it, here's the fiddle.
Why on earth does that not work on IE8? Works on all other browsers. I've even tried just removing all of the hover nonsense, but I still can't get the border to appear. I've also tried adding a display:block and width:100% to the .cta div per some things I came across on the Internet. No dice.
Any ideas?
IE8 and lower do not support rgba, so try adding a fallback using rgb: DEMO
.cta:hover:after
{
border-bottom:1px solid rgb(0,136,204);
border-bottom:1px solid rgba(0,136,204,.6);
}
Source: http://css-tricks.com/rgba-browser-support/

Border appearing the text color of an anchor on Google Chrome

On Google chrome, if I have a div within an anchor, randomly the border will change to the text colour. If I inspect the element, the colour switches back instantly to the proper colour. Is there a way I can get around this error?
This is the html: (it doesn't happen every time, spontaneously it will be the wrong colour)
<a href="/about"><div class="navc">
<div class="navt"><?php echo $lang['0']; ?></div>
</div>
</a>
this is the css:
#nav
{
float:left;
width:100%;
height:30px;
background:url('../images/nav.png') repeat-x;
border:1px solid #C2C1C1;
text-shadow:0 1px 0 white
}
#nav a
{
color:black;
text-decoration:none
}
.navc
{
padding:0 10px;
border-left:1px solid #C2C1C1;
border-right:1px solid #EEE;
float:left;
height:100%
}
.navt
{
padding-top:6px
}
As can be seen on the following image,the border of the About navigation button is wrong
Only took me 3 hours to solve this bug (on days like this I feel like Webkit is just as bad as Trident)... but here's the answer:
It only occurs when you have an inline elements inside an anchor (<a>) with a "href" value that has been visited. Such as:
<span>Button</span>
To fix the issue, I added the following CSS:
a {color: blue}
a span,
a:visited span /* Webkit will render a blue border unless this is explicitly specified */
{
border: 1px solid red;
}
I found a solution,
if I use a span instead of a div, the issue doesnt seem to occur.
edit - it occurred once since its been a span, refreshed and it hasn't occurred since.
I just ran into this with some markup like this:
<a href="http://www.google.com" class="outer-link">
<img src="http://google.com/gif.png" />
</a>
My styles looked like this:
img { border: 2px solid gray; }
The gray border was getting turned into the blue link color, here is how I fixed it:
.outer-link { color: gray; }
So even when the img is getting the wrong border, it's defaulting to the gray border color that I specified. I know it's a bit hacky but it works.

CSS hover on div doesn't affect anchor that sits inside?

<style>
.btn{
display: inline-block;
padding: 15px 10px;
background: gray;
}
.btn:hover{
background:lightgray;
color:red;
}
</style>
<div class="btn">
text
</div>
works nicely. However if we have that:
<div class="btn">
text
</div>
it wouldn't work exactly as the first one. The anchor's text wouldn't be affected. Okay what if we add to the CSS:
.btn a:hover{
background:lightgray;
color:red;
}
That will work, but only if you hover exactly on the anchor, but still hover on the div rectangle wouldn't affect the anchor's text.
How can I tweak that without any javascript, so both rectangles acted identically?
http://jsfiddle.net/vaNJD/
UPD: adding !important keyword wouldn't help
Because all web browsers set a default color (and text-decoration) for a elements, you need a more specific selector to override the default. Try this instead:
.btn:hover, .btn:hover a {
background:lightgray;
color:red;
}
If you really want the two boxes to be identical, you would also need to override the un-hovered button as well:
.btn a {
color: black;
text-decoration: none;
}
It may also be worth pointing out that IE6 only supports the :hover pseudo-class on a elements. You may want to work around this by setting the a to display: block and adding the background color there.
You can accomplish the same effect by getting rid of the container and applying the .btn class directly to the a element. See the third box in this updated fiddle: http://jsfiddle.net/mlms13/vaNJD/5/
.btn:hover{
background:lightgray;
color:red;
}
.btn:hover a{
color: red;
}
Change to:
.btn:hover,
.btn:hover a{
background:lightgray;
color:red;
}
http://jsfiddle.net/vaNJD/4/
Like this?
.btn:hover a{
color:red;
}
I found one way in which you should set height for div tag and use it again for anchor tag and set anchor's display properties as block
for example
<style>
.divest
{
height:120px;
}
.divest a
{
display:block;
height:120px;
}
</style>
<div class="divest">here is hyperlink text</div>

CSS Title with an horizontal line in the middle

I'm trying to make a horizontal rule with some text in the left.
for example:
my title -------------------------------------
I can do it by putting a background to the text but without the colored background, I can not
Is anybody has an answer ?
<style>
h1 {
font-weight:normal;
line-height:0;
height:0;
border-bottom:1px solid #000;
vertical-align:middle;
}
</style>
<h1><span>my title</span></h1>
Thanks
Your suggestion of putting a background color on the span seems to work reasonably well. See it here.
Alternately, you could use a background image in place of the border on the h1.
h1 { background: url(http://i.stack.imgur.com/nomLz.gif) repeat-x left center; }
h1 span {
background-color: #FFF;
padding-right: 3px;
}
Example.
(A 1x1 black image for the background.1)
without using the background you could try with:
<style>
span:after{
content:"-------------------------------------";
}
</style>
<h1><span>my title</span></h1>
In this case you are using the CSS :after pseudo class.
Have a look to this article to check cross-browser compatibility.
And here you will find a pre-coded example.
Hope it helps!