Help - Search - Members - Calendar
Full Version: CSS Border not working right
Invision Power Services > Community Forums > Community Web Design and Coding
Trel
I want a border on the left and right of something.
So I did this

CODE
border: 0px 2px 0px 2px solid #FFFFFF;


However, no borders showed up.

The only way I've gotten it to work is:
CODE
border-right: 2px solid #FFFFFF;
border-left: 2px solid #FFFFFF;


But that seems so repetitive.
IAIHMB
That is the only way to go about it. Well:

CODE
border-color: #FFF;
border-width: 0 2px;
=Charles
Or I suppose you could do:
CODE
border: 2px solid #fff;
border-top: 0px;
border-bottom: 0px;
Brendon Koz
QUOTE(Aka Tolken @ Aug 7 2006, 01:25 PM) *
Or I suppose you could do:
CODE
border: 2px solid #fff;
border-top: 0px;
border-bottom: 0px;

I think that'll give a redeclaration error in the W3C CSS validator because you declare a border in the first line, then redeclare it (thusly overwriting it) in the next two lines.
Trel
QUOTE(malikyte @ Aug 7 2006, 03:42 PM) *
I think that'll give a redeclaration error in the W3C CSS validator because you declare a border in the first line, then redeclare it (thusly overwriting it) in the next two lines.


There is no redeclaration error, that's what CSS means Cascading Style Sheets wink.gif
Brendon Koz
No, you misunderstand... Cascading is from one defined element/class/id to another. When you define a property that has already been declared in the same element/class/id, you're redeclaring it. Since the border attribute is a short-hand method for using border-width, border-style, and border-color, specifying any of those again is redeclaring it --- not using the cascade.

Since you made me double check myself to be sure I was right, here's the code:
CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>test</title>
<style>
body{
border: 2px solid #000;
border-top: 0;
border-bottom: 0;
}
</style>
</head>
<body>

Test the border problem thingy.

</body>
</html>


...and the resulting W3C's CSS Validator results:
QUOTE
Warnings
URI : file://localhost/webdeveloper__1154982860829.css

* Line : 5 (Level : 2) Redefinition of border-top-width : body
* Line : 6 (Level : 2) Redefinition of border-bottom-width : body

Valid CSS information

* body {
o border : 2px solid #000;
o border-top : 0;
o border-bottom : 0;
}

...so, although it's valid, it does throw an error (ok, a warning, I still think a warning IS an error). The 'o' before the CSS properties, it was a bulleted list from the validator.
James Mathias
The proper way to write this would be

border: solid #FFF;
border-width: 2px 0;

I hope that helps.
Trel
Yeah, thanks all, I got it working now original.gif
=Charles
QUOTE(malikyte @ Aug 7 2006, 08:42 PM) *
I think that'll give a redeclaration error in the W3C CSS validator because you declare a border in the first line, then redeclare it (thusly overwriting it) in the next two lines.

I didn't know about that. Thanks for pointing it out. original.gif
Brendon Koz
No problem, glad to help.

While I'm replying, I'd just like to point out that IAIHMB beat James to the punch, and did it properly; James isn't usually wrong, so pointing out that he should have said 0 2px rather than his 2px 0 is a bit of an ironically happy moment for me - though meant in jest since I know he understands CSS 20x more than I. tongue.gif
James Mathias
Although you are correct that I got the border-width: transposed, because I mis-read his original code.

David (IAIHMB) did not post the proper code, although his will work sorta, it's bad practice and mine, excepting the transposition is good practice. tongue.gif
Trel
All I know is that it's all good for me in the end tongue.gif

Not only do I get code that works, but I get the understanding of why it works and why it should be done that way.
IAIHMB
QUOTE(James Mathias @ Aug 8 2006, 10:19 PM) *
Although you are correct that I got the border-width: transposed, because I mis-read his original code.

David (IAIHMB) did not post the proper code, although his will work sorta, it's bad practice and mine, excepting the transposition is good practice. tongue.gif


Hrm, where will mine break? I know that I've omitted the border style and it's supposed to default to none, but everything since Internet Explorer 5 and Netscape Navigator 4 (Not first hand, from the CSS Pocket Reference.) defaults to solid once a width has been defined.
James Mathias
Didn't say yours would break, I said it's bad practice.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.