Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Div border not showing

Tags:

html

css

I'm trying to add a border to a div element in HTML. Below is my code.

#container-border {
  border-width: 2px;
  border-color: red;
}
<div id="container-border">
  ...
</div>

For some reason, the border doesn't show up. I had a look on a similar question (here) but I couldn't figure out why the border doesn't show up. Any suggestions please?

Note: This snippet is a part of an HTML page. Additional code could be provided upon request

like image 443
Joseph Wahba Avatar asked Feb 27 '17 22:02

Joseph Wahba


People also ask

Why is border not showing in HTML?

If you've set the shorthand border property in CSS and the border is not showing, the most likely issue is that you did not define the border style. While the border-width and border-color property values can be omitted, the border-style property must be defined. Otherwise, it will not render.

How do I give a div a border?

This is a very simple thing to do. Just go to your stylesheet. css and type border: solid black 2px; in your div section.

How do I enable Borders in HTML?

Using Inline Style attribute Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the inline property for adding the border. Step 2: Now, place the cursor inside the opening tag of that text around which we want to add the border.


1 Answers

The default value of border-style is none. You need to set a different value for a border to appear.

#container-border {
  border-width: 2px;
  border-color: red;
  border-style: dashed;
}
<div id="container-border">
  ...
</div>
like image 97
Quentin Avatar answered Oct 02 '22 05:10

Quentin