I use HTML DIV tag to format my header with border like this:
<h3 style="background-color:red; padding:2% 0 2% 0; border:5px solid green"> This is a header </h3>
However, I would like to have the border appears only on top and bottom, but not on left and right. I would like border in the same way as padding for top left bottom and right, but border does not have this feature(or I don't know?). Is there any way in CSS style to do that?
You can use the border-left , border-right , border-top and border-bottom properties to give different border styles to each side of your container. In your case, you want to apply your style to border-top and border-bottom .
You can use: border-style: solid; border-width: thin; border-color: #FFFFFF; You can change these as you see fit, though.
For future reference, the following is a an alternative method that avoids having to define border properties (colour, width) more than once and allows declarations similar to those used for margin and padding (as requested).
border: 5px green; border-style: solid none;
As with margin or padding, border-style
is defined in order of top, right, bottom, left. The above case applies a solid border to top and bottom of an element and no border to the left or right of the element.
Using this method avoids creating redundancies in the declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With