Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set a default border color/size in CSS?

Tags:

html

css

border

I'd like to set a global default size and color for all my borders using css. I'm having an issue where my css for setting a default border width and color is being overwritten the moment I try and use it. Basically I have something like this:

My.css

* { 
  border-width: 1px;
  border-color: #222;
}

#streak {
  border-bottom: solid;
}

My.html

<html>
<div id="streak">
  WOOOOOOOO!
</div>
</html>

The problem is that the moment I set the bottom border to solid, it defaults the width to 3px and the color to black. In the developer console it shows that the css for * {...} was applied, but then it was crossed out and now it is currently at a width and color of initial, which it got from the "border-bottom: solid;" rule.

I've found that if I use !important in the * {...} css rules, it'll work, but I'm really not a fan of using !important if I don't have to.

Is there a better way?

like image 658
Seph Reed Avatar asked Nov 28 '25 14:11

Seph Reed


1 Answers

What you're doing with the * rule is fine. What you're trying to do on individual elements is set the border style. You will need to use the border-style component property for that, rather than the border shorthand as the shorthand will override the width and color with their initial values (which are medium and currentColor respectively):

#streak {
  border-bottom-style: solid;
}

Of course, this means you can continue using the shorthand in situations where you do want to override the global width and color with other values.

like image 197
BoltClock Avatar answered Dec 01 '25 05:12

BoltClock