Is there any way to make the HTML underline thicker? - html

I have a centered div with a nested h1 inside. Is there any way to underline it with a thicker line than the html default?

This will give you control over the U tag's underline:
<style type="text/css">
u {
text-decoration: none;
border-bottom: 4px solid black;
}
</style>
In this case the underline will be four pixels.

No, there isn’t. The thickness of the underline is browser-dependent and cannot be affected in CSS (or HTML).
There was once a text-underline-width property suggested in the CSS3 Text draft. But there was insufficient interest in it, and it was removed from the draft in 2005. It was probably never implemented.
The usual workaround is to use a bottom border instead of an underline. However, note that it is a different thing. The bottom border is below the line box, whereas an underline is normally on the baseline of text and therefore cuts descenders of letters. Generally, a bottom border is better for legibility than an underline, but it deviates from typographic tradition.
The following example demonstrates the differences.
<span style="text-decoration: underline">jgq</span>
<span style="border-bottom: solid 1px">jgq</span>
<span style="border-bottom: solid 4px">jgq</span>

I am not recommending inline CSS but have used it here for brevity:
<h1 style="border-bottom: 5px solid black">

You may be able to achieve the same visual effect with border-bottom-width;
h2
{
border-bottom-color:black;
border-bottom-style:solid;
border-bottom-width:15px;
}

Since you don't always want border-bottom (eg, item may have padding and it will appear too far away), this method works best:
h1:after {
content: '';
height: 1px;
background: black;
display:block;
}
If you want a thicker underline, add more height
If you want more or less space between the text and the underline, add a margin-top:
h1:after {
content: '';
height: 2px;
background: black;
display:block;
margin-top: 2px;
}

Related

Is there a way to make the <hr> tag a different color? [duplicate]

I want to change the color of my hr tag using CSS. The code I've tried below doesn't seem to work:
hr {
color: #123455;
}
I think you should use border-color instead of color, if your intention is to change the color of the line produced by <hr> tag.
Although, it has been pointed in comments that, if you change the size of your line, border will still be as wide as you specified in styles, and line will be filled with the default color (which is not a desired effect most of the time). So it seems like in this case you would also need to specify background-color (as suggested by #Ibu).
HTML 5 Boilerplate project in its default stylesheet specifies the following rule:
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
}
An article titled “12 Little-Known CSS Facts”, published recently by SitePoint, mentions that <hr> can set its border-color to its parent's color if you specify hr { border-color: inherit }.
border-color works in Chrome and Safari.
background-color works in Firefox and Opera.
color works in IE7+.
I think this can be useful. this was simple CSS selector.
hr { background-color: red; height: 1px; border: 0; }
<hr>
hr {
height: 1px;
color: #123455;
background-color: #123455;
border: none;
}
Doing it this way allows you to change the height if needed. Good luck. Source: How To Style HR with CSS
Tested in Firefox, Opera, Internet Explorer, Chrome and Safari.
hr {
border-top: 1px solid red;
}
See the Fiddle.
Only border-top with color is enough to make the line in different color.
hr {
border-top: 1px solid #ccc;
}
<hr>
This will keep the Horizontal Rule 1px thick while also changing the color of it:
hr {
height: 0;
border: 0;
border-top: 1px solid #083972;
}
hr {
color: #f00;
background-color: #f00;
height: 5px;
}
After reading all the answers here, and seeing the complexity described, I set upon a small diversion for experimenting with HR. And, the conclusion is that you can throw out most of the monkeypatched CSS you wrote, read this small primer and just use these two lines of pure CSS:
hr {
border-style: solid;
border-color: cornflowerblue; /* or whatever */
}
That is ALL you need to style your HRs.
Works cross-browser, cross-device, cross-os, cross-english-channel, cross-ages.
No "I think this will work...", "you need to keep Safari/IE in mind...", etc.
no extra css - no height, width, background-color, color, etc. involved.
Just bulletproof colourful HRs. It's that simpleTM.
Bonus: To give the HR some height H, just set the border-width as H/2.
I believe this is the most effective approach:
<hr style="border-top: 1px solid #ccc; background: transparent;">
Or if you prefer doing it on all hr elements write this on you CSS:
hr {
background-color: transparent;
border-top: 1px solid #ccc;
}
hr {
background-color: #123455;
}
The background is the one you should try to change.
You can also work with the borders color. I am not sure; I think there are cross-browser issues with this. You should test it in different browsers.
You can add bootstrap bg class like
<hr class="bg-light" />
if u use css class then it will be taken by all 'hr' tags , but if u want for a particular 'hr' use the below code i.e, inline css
<hr style="color:#99CC99" />
if it's not working in chrome try below code:
<hr color="red" />
Some browsers use the color attribute and some use the background-color attribute. To be safe:
hr {
color: #color;
background-color: #color;
}
It's simple and my favorite.
<hr style="background-color: #dd3333" />
I'm testing on IE, Firefox and Chrome May 2015 and this works best with the current versions. It centers the HR and makes it 70% wide:
hr.light {
width:70%;
margin:0 auto;
border:0px none white;
border-top:1px solid lightgrey;
}
<hr class="light" />
You should set border-width to 0; It works well in Firefox and Chrome.
hr {
clear: both;
color: red;
background-color: red;
height: 1px;
border-width: 0;
}
<hr />
This is a test
<hr />
Since i don't have reputation to comment, i will give here a few ideas.
if you want a css variable height, take off all borders and give a background color.
hr{
height:2px;
border:0px;
background:green;
margin:0px;/*sometimes useful*/
}
/*Doesn't work in ie7 and below and in Quirks Mode*/
if you want simply a style that you know that will work (example: to replace a border in a ::before element for most email clients or
hr{
height:0px;
border:0px;
border-top:2px solid blue;
margin:0px;/*useful sometimes*/
}
In both ways, if you set a width, it will always have it's size.
No need to set display:block; for this.
To be totally safe, you can mix both, 'cause some browsers can get confused with height:0px;:
hr{
height:1px;
border:0px;
background:blue;
border-top:1px solid blue;
margin:0px;/*useful sometimes*/
}
With this method you can be sure that it will have at least 2px in height.
It's a line more, but safety is safety.
This is the method you should use to be compatible with almost everything.
Remember: Gmail only detects inline css and some email clients may not support backgrounds or borders. If one fails, you will still have a 1px line. Better than nothing.
In the worst cases, you can try to add color:blue;.
In the worst of the worst cases, you can try to use a <font color="blue"></font> tag and put your precious <hr/> tag inside it. It will inherit the <font></font> tag color.
With this method, you WILL want to do like this: <hr width="50" align="left"/>.
Example:
<span>
awhieugfrafgtgtfhjjygfjyjg
<font color="#42B3E5"><hr width="50" align="left"/></font>
</span>
<!--Doesn't work in ie7 and below and in Quirks Mode-->
Here is a link for you to check: http://jsfiddle.net/sna2D/
You can use CSS to make a line with a different color, example would be like that:
border-left: 1px solid rgb(216, 216, 216);
border-right: medium none;
border-width: medium medium medium 2px;
border-style: none none none solid;
border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color rgb(216, 216, 216);
that code will display vertical grey line.
I like the answers setting border-top, but they are somehow still a little off in Chrome...
BUT if I set border-top: 1px solid black; and border-bottom: 0px; I end up with a truly single line (that also works fine with higher thickness).
Well, I am new in HTML, CSS and in Java but I tried my way which worked for me in all browsers. I have used JS instead of CSS which doesn't work with some browsers.
First of all I have given id="myHR" to HR element and used it in Java Script.
Here is the Code.
x = document.getElementById("myHR");
y = x.style.width = "600px";
y = x.style.color = "white";
y = x.style.height = "2px";
y = x.style.border = "none";
y = x.style.backgroundColor = "lightgrey";
Code Works For older IE
Tried For Many Colors
<hr color="black">
<hr color="blue">
Using font colours to modify horizontal rules makes them more flexible and easy to use.
The color property isn't inherited by default, so the following needs to be added to hr's to allow color inheritance:
/* allow hr to inherit color */
hr { border: 1px solid;}
/* reusable colour modifier */
.fc_-alpha { color: crimson;}
normal hr:
<hr>
hr with <span class="fc_-alpha">colour modifier</span>:
<hr class="fc_-alpha">
You could do this :
hr {
border: 1px solid red;
}
<hr />
This s a test
<hr />
You can give the <hr noshade> tag and go to your css file and add :
hr {
border-top:0;
color: #123455;
}
<hr noshade />
This s a test
<hr noshade />
As a general rule, you can’t just set the color of a horizontal line with CSS like you would anything else.
First of all, Internet Explorer needs the color in your CSS to read like this:
“color: #123455”
But Opera and Mozilla needs the color in your CSS to read like this:
“background-color: #123455”
So, you will need to add both options to your CSS.
Next, you will need to give the horizontal line some dimensions or it will default to the standard height, width and color set by your browser.
Here is a sample code of what your CSS should look like to get the blue horizontal line.
hr {
border: 0;
width: 100%;
color: #123455;
background-color: #123455;
height: 5px;
}
Or you could just add the style to your HTML page directly when you insert a horizontal line, like this:
<hr style="background:#123455" />
Hope this helps.
I took a bet each way:
hr {
border-top: 1px solid purple;
border-color: purple;
background-color: purple;
color: purple;
}

Printing a checked checkbox / tick box with HTML and CSS

I have the following problem: I have to use an HTML->PDF conversion service to render a piece of HTML. However, this service is a bit limited in it's functionality, so I need a way to "work around" it.
I'm mainly just printing text, so it's not a big deal, but the only problem is that I have to print some "unticked" and some "ticked" check boxes, my converter is failing at this. In particular I've tried:
Using the unicode ☐ ("☐") and ☑ ("☑") characters, but the converter doesn't render them (probably the font it's using doesn't
have them)
Using the WingDing characters þ and ¨ but again, the wingding font is not recognized
The converter doesn't support images, so can't just use an image
I was thinking, at this point, to "simulate" a checkbox by using spans with borders, something like:
<span style="border: 1px solid black; height: 12px; width: 12px;"></span>
However, I can't make it look correct (no fault of the converter this time, even browsers show the above as just one vertival line.
Can anyone help me "draw" checkboxes using just "basic" html elements? What would be the cleanest way?
PS: checkboxes need to be inline with the text.
You're on the right track.
Using HTML and CSS:
/* The standalone checkbox square*/
.checkbox {
width:20px;
height:20px;
border: 1px solid #000;
display: inline-block;
}
/* This is what simulates a checkmark icon */
.checkbox.checked:after {
content: '';
display: block;
width: 4px;
height: 7px;
/* "Center" the checkmark */
position:relative;
top:4px;
left:7px;
border: solid #000;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
<div class="checkbox"></div> Unchecked<br><br>
<div class="checkbox checked"></div> Checked
The reason YOUR code didn't work was because you were using a span element, which is an inline element. You can use a span for this, but you'll need to add the style of display: block to the element (making it act as a block element instead of an inline element).
The div tag is a block, so no need for setting it's display style. If you would like the div to display inline, set the display: inline-block
Try this :
<div style="border: 1px solid black;
width: 10px;
height: 10px;
display: inline-block;
margin-right: 4px;">
</div>
https://jsfiddle.net/8rt4dqfc/

space between text and border bottom

How do I create distance between the text and the border below the text as shown in the image attached using sass/css?
I want the distance to be 5px and the font-size of the text to be 15px.
I tried doing
.selected {
color: #284660;
}
.selected:after {
content: '';
position: absolute;
width: 100%;
height: 0;
left: 0;
bottom: 5px;
border-bottom: 2px solid #284660;
}
but that created a border that was too wide.
I feel couple of things which can be improved in the above snippet.
You may not need psuedo element for desired effect
You should not use absolute positioning for that , in case you want to use psuedo element
In any case you can try this out.
&.selected {
color: #284660;
border-bottom: 2px solid #284660;
padding-bottom:10px ; // this should give you some spacing.
}
Try a negative
{
bottom: -5px;
}
Besides the complete lack of knowledge of your DOM profile or what element the & refers to, if you just slap a border and padding on an inline element, you'll have the effect you want.
No need to play with pseudoelements.
<span style="padding-bottom:5px; border-bottom:2px solid black;">Some Text</span>
Obviously, you should put that styling info in the css file, I merely inlined it for the example.
Oh and next time, please include sample HTML with your sample CSS. Only reason I even bothered was because the solution was as simple as "What is padding for 15, Trebek?"

Why is my 'hr' in HTML displaying with an extra half pixel on it?

It's just a standard HTML 'hr' tag but the line is displaying with an odd extra pixel. My only CSS is:
hr {margin:0%;line-height: 100%;}
Apparently I don't have enough rep to include images of the issue, so you'll have to go off my description.
Use the height property instead of the line-height property and that should fix your issue. Here's some additional information on styling hr tags. Cross-Browser hr Styling
It's in the comments now, but here's the fix that worked for him.
hr { border:none; border-top:1px #CCCCCC solid; height: 1px; }
The HR uses a shadow on it in most browsers. You should override the style using css or something like:
<hr noshade size="1" />
Update:
noshade is deprecated... See http://www.electrictoolbox.com/style-html-hr-tag-css/
Css Solution:
hr {
border: none;
background-color: #000;
color: #000;
height: 1px;
}
Cross-browser solution with CSS:
hr { height: 1px; background-color: #000; border: 0 none; }
How I change the thickness of my <hr> tag
jsFiddle:
http://jsfiddle.net/6nXaN/
An hr tag is just rendered as a 1px tall empty element with a border style of inset (change the height of the hr a few pixels to see what I mean). The extra pixel comes on the left due the way the inset border is rendered. If you add:
hr { border-left: none; }
...then you can maintain the inset look of the default hr without the extra pixel. Making the border-style solid, or making it a black background colour may make your hr too dark. I prefer the subtlety of the above approach.

Changing the color of an hr element

I want to change the color of my hr tag using CSS. The code I've tried below doesn't seem to work:
hr {
color: #123455;
}
I think you should use border-color instead of color, if your intention is to change the color of the line produced by <hr> tag.
Although, it has been pointed in comments that, if you change the size of your line, border will still be as wide as you specified in styles, and line will be filled with the default color (which is not a desired effect most of the time). So it seems like in this case you would also need to specify background-color (as suggested by #Ibu).
HTML 5 Boilerplate project in its default stylesheet specifies the following rule:
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
}
An article titled “12 Little-Known CSS Facts”, published recently by SitePoint, mentions that <hr> can set its border-color to its parent's color if you specify hr { border-color: inherit }.
border-color works in Chrome and Safari.
background-color works in Firefox and Opera.
color works in IE7+.
I think this can be useful. this was simple CSS selector.
hr { background-color: red; height: 1px; border: 0; }
<hr>
hr {
height: 1px;
color: #123455;
background-color: #123455;
border: none;
}
Doing it this way allows you to change the height if needed. Good luck. Source: How To Style HR with CSS
Tested in Firefox, Opera, Internet Explorer, Chrome and Safari.
hr {
border-top: 1px solid red;
}
See the Fiddle.
Only border-top with color is enough to make the line in different color.
hr {
border-top: 1px solid #ccc;
}
<hr>
This will keep the Horizontal Rule 1px thick while also changing the color of it:
hr {
height: 0;
border: 0;
border-top: 1px solid #083972;
}
hr {
color: #f00;
background-color: #f00;
height: 5px;
}
After reading all the answers here, and seeing the complexity described, I set upon a small diversion for experimenting with HR. And, the conclusion is that you can throw out most of the monkeypatched CSS you wrote, read this small primer and just use these two lines of pure CSS:
hr {
border-style: solid;
border-color: cornflowerblue; /* or whatever */
}
That is ALL you need to style your HRs.
Works cross-browser, cross-device, cross-os, cross-english-channel, cross-ages.
No "I think this will work...", "you need to keep Safari/IE in mind...", etc.
no extra css - no height, width, background-color, color, etc. involved.
Just bulletproof colourful HRs. It's that simpleTM.
Bonus: To give the HR some height H, just set the border-width as H/2.
I believe this is the most effective approach:
<hr style="border-top: 1px solid #ccc; background: transparent;">
Or if you prefer doing it on all hr elements write this on you CSS:
hr {
background-color: transparent;
border-top: 1px solid #ccc;
}
hr {
background-color: #123455;
}
The background is the one you should try to change.
You can also work with the borders color. I am not sure; I think there are cross-browser issues with this. You should test it in different browsers.
You can add bootstrap bg class like
<hr class="bg-light" />
if u use css class then it will be taken by all 'hr' tags , but if u want for a particular 'hr' use the below code i.e, inline css
<hr style="color:#99CC99" />
if it's not working in chrome try below code:
<hr color="red" />
Some browsers use the color attribute and some use the background-color attribute. To be safe:
hr {
color: #color;
background-color: #color;
}
It's simple and my favorite.
<hr style="background-color: #dd3333" />
I'm testing on IE, Firefox and Chrome May 2015 and this works best with the current versions. It centers the HR and makes it 70% wide:
hr.light {
width:70%;
margin:0 auto;
border:0px none white;
border-top:1px solid lightgrey;
}
<hr class="light" />
You should set border-width to 0; It works well in Firefox and Chrome.
hr {
clear: both;
color: red;
background-color: red;
height: 1px;
border-width: 0;
}
<hr />
This is a test
<hr />
Since i don't have reputation to comment, i will give here a few ideas.
if you want a css variable height, take off all borders and give a background color.
hr{
height:2px;
border:0px;
background:green;
margin:0px;/*sometimes useful*/
}
/*Doesn't work in ie7 and below and in Quirks Mode*/
if you want simply a style that you know that will work (example: to replace a border in a ::before element for most email clients or
hr{
height:0px;
border:0px;
border-top:2px solid blue;
margin:0px;/*useful sometimes*/
}
In both ways, if you set a width, it will always have it's size.
No need to set display:block; for this.
To be totally safe, you can mix both, 'cause some browsers can get confused with height:0px;:
hr{
height:1px;
border:0px;
background:blue;
border-top:1px solid blue;
margin:0px;/*useful sometimes*/
}
With this method you can be sure that it will have at least 2px in height.
It's a line more, but safety is safety.
This is the method you should use to be compatible with almost everything.
Remember: Gmail only detects inline css and some email clients may not support backgrounds or borders. If one fails, you will still have a 1px line. Better than nothing.
In the worst cases, you can try to add color:blue;.
In the worst of the worst cases, you can try to use a <font color="blue"></font> tag and put your precious <hr/> tag inside it. It will inherit the <font></font> tag color.
With this method, you WILL want to do like this: <hr width="50" align="left"/>.
Example:
<span>
awhieugfrafgtgtfhjjygfjyjg
<font color="#42B3E5"><hr width="50" align="left"/></font>
</span>
<!--Doesn't work in ie7 and below and in Quirks Mode-->
Here is a link for you to check: http://jsfiddle.net/sna2D/
You can use CSS to make a line with a different color, example would be like that:
border-left: 1px solid rgb(216, 216, 216);
border-right: medium none;
border-width: medium medium medium 2px;
border-style: none none none solid;
border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color rgb(216, 216, 216);
that code will display vertical grey line.
I like the answers setting border-top, but they are somehow still a little off in Chrome...
BUT if I set border-top: 1px solid black; and border-bottom: 0px; I end up with a truly single line (that also works fine with higher thickness).
Well, I am new in HTML, CSS and in Java but I tried my way which worked for me in all browsers. I have used JS instead of CSS which doesn't work with some browsers.
First of all I have given id="myHR" to HR element and used it in Java Script.
Here is the Code.
x = document.getElementById("myHR");
y = x.style.width = "600px";
y = x.style.color = "white";
y = x.style.height = "2px";
y = x.style.border = "none";
y = x.style.backgroundColor = "lightgrey";
Code Works For older IE
Tried For Many Colors
<hr color="black">
<hr color="blue">
Using font colours to modify horizontal rules makes them more flexible and easy to use.
The color property isn't inherited by default, so the following needs to be added to hr's to allow color inheritance:
/* allow hr to inherit color */
hr { border: 1px solid;}
/* reusable colour modifier */
.fc_-alpha { color: crimson;}
normal hr:
<hr>
hr with <span class="fc_-alpha">colour modifier</span>:
<hr class="fc_-alpha">
You could do this :
hr {
border: 1px solid red;
}
<hr />
This s a test
<hr />
You can give the <hr noshade> tag and go to your css file and add :
hr {
border-top:0;
color: #123455;
}
<hr noshade />
This s a test
<hr noshade />
As a general rule, you can’t just set the color of a horizontal line with CSS like you would anything else.
First of all, Internet Explorer needs the color in your CSS to read like this:
“color: #123455”
But Opera and Mozilla needs the color in your CSS to read like this:
“background-color: #123455”
So, you will need to add both options to your CSS.
Next, you will need to give the horizontal line some dimensions or it will default to the standard height, width and color set by your browser.
Here is a sample code of what your CSS should look like to get the blue horizontal line.
hr {
border: 0;
width: 100%;
color: #123455;
background-color: #123455;
height: 5px;
}
Or you could just add the style to your HTML page directly when you insert a horizontal line, like this:
<hr style="background:#123455" />
Hope this helps.
I took a bet each way:
hr {
border-top: 1px solid purple;
border-color: purple;
background-color: purple;
color: purple;
}