How I change the thickness of my <hr> tag
I want to change the thickness of my horizontal rule in CSS. I know it can be done in HTML like so -
<hr size="10">
But I hear that this is deprecated as mentioned on MDN here. In CSS I tried using height:1px
but it does not change the thickness. I want the <hr>
line to be 0.5px
thick.
I am using Firefox 3.6.11 on Ubuntu
For consistency remove any borders and use the height for the <hr>
thickness. Adding a background color will style your <hr>
with the height and color specified.
In your stylesheet:
hr {
border: none;
height: 1px;
/* Set the hr color */
color: #333; /* old IE */
background-color: #333; /* Modern Browsers */
}
Or inline as you have it:
<hr style="height:1px;border:none;color:#333;background-color:#333;" />
Longer explanation here
Sub-pixel rendering in browsers
Sub-pixel rendering is tricky. You can't actually expect a monitor to render a less than a pixel thin line. But it's possible to provide sub-pixel dimensions. Depending on the browser they render these differently. Check this John Resig's blog post about it.
Basically if your monitor is an LCD and you're drawing vertical lines, you can easily draw a 1/3 pixel line. If your background is white, give your line colour of #f0f
. To the eye this line will be 1/3 of pixel wide. Although it will be of some colour, if you'd magnify monitor, you'd see that only one segment of the whole pixel (consisting of RGB) will be dark. This is pretty much technique that's used for fine type hinting ie ClearType.
But horizontal lines can only be a full pixel high. That's technology limitation of LCD monitors. CRTs were even more complicated with their triangular phosphors (unless they were aperture grille type ie. Sony Trinitron) but that's a different story.
Basically providing a sub-pixel dimension and expecting it to render that way is same as expecting an integer variable to store a number of 1.2034759349. If you understand this is impossible, you should understand that monitors aren't able to render sub-pixel dimensions.
Cross browser safe style
But the way horizontal rules that blend in are usually done using colours. So if your background is for instance white ( #fff
) you can always make your HR
very light. Like #eee
.
The cross browser safe style for very light horizontal rule would be:
hr
{
background-color: #eee;
border: 0 none;
color: #eee;
height: 1px;
}
And use a CSS file instead of in-line styles. They provide a central definition for the whole site not just a particular element. It makes maintainability much better.
I was looking for shortest way to draw an 1px line, as whole load of separated CSS is not the fastest or shortest solution.
Up to HTML5, the WAS a shorter way for 1px hr: <hr noshade> but.. The noshade attribute of <hr> is not supported in HTML5. Use CSS instead. (nor other attibutes used before, as size, width, align)...
Now, this one is quite tricky, but works well if most simple 1px hr needed:
Variation 1, BLACK hr: (best solution for black)
<hr style="border-bottom: 0px">
Output: FF, Opera - black / Safari - dark gray
Variation 2, GRAY hr (shortest!):
<hr style="border-top: 0px">
Output: Opera - dark gray / FF - gray / Safari - light gray
Variation 3, COLOR as desired:
<hr style="border: none; border-bottom: 1px solid red;">
Output: Opera / FF / Safari : 1px red.
链接地址: http://www.djcxy.com/p/89122.html上一篇: 大小:封面和包含图像元素?
下一篇: 我如何改变我的<hr>标签的厚度