How to set a border for an HTML div tag

HtmlCssBorder

Html Problem Overview


I am trying to define a border around a div tag in HTML. In some browsers the border does not appear.

Here is my HTML code:

<div id="divActivites" name="divActivites" style="border:thin">
    <textarea id="inActivities" name="inActivities" style="border:solid">
    </textarea> 
</div> 

How do I set a border for an HTML div tag?

Html Solutions


Solution 1 - Html

Try being explicit about all the border properties. For example:

border:1px solid black;

See Border shorthand property. Although the other bits are optional some browsers don't set the width or colour to a default you'd expect. In your case I'd bet that it's the width that's zero unless specified.

Solution 2 - Html

can use

border-width:2px;
border-style:solid;
border-color:black;

or as shorthand

border: 2px solid black

Solution 3 - Html

As per the W3C:

> Since the initial value of the border styles is 'none', no borders will be visible unless the border style is set.

In other words, you need to set a border style (e.g. solid) for the border to show up. border:thin only sets the width. Also, the color will by default be the same as the text color (which normally doesn't look good).

I recommend setting all three styles:

style="border: thin solid black"

Solution 4 - Html

You can use:

border-style: solid;
border-width: thin;
border-color: #FFFFFF;

You can change these as you see fit, though.

Solution 5 - Html

I guess this is where you are pointing at ..

<div id="divActivites" name="divActivites" style="border:thin">
    <textarea id="inActivities" name="inActivities" style="border:solid">
    </textarea> 
</div> 

Well. it must be written as border-width:thin

Here you go with the link (click here) check out the different types of Border-styles

you can also set the border width by writing the width in terms of pixels.. (like border-width:1px), minimum width is 1px.

Solution 6 - Html

You need to set more fields then just border-width. The style basically puts the border on the page. Width controls the thickness, and color tells it what color to make the border.

border-style: solid; border-width:thin; border-color: #FFFFFF;

Solution 7 - Html

In bootstrap 4, you can use border utilities like so.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>

<style>
  .border-5 {
    border-width: 5px !important;
  }
</style>

<textarea class="border border-dark border-5">some content</textarea>

Solution 8 - Html

 .centerImge {
        display: block;
        margin-left: auto;
        margin-right: auto;
        width: 50%;
        height:50%;
    }
 <div>
 @foreach (var item in Model)
{
<span> <img src="@item.Thumbnail"  class="centerImge" /></span>
  <h3 style="text-align:center">  @item.CategoryName</h3>
}
 </div>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRKhView Question on Stackoverflow
Solution 1 - HtmlPaoloView Answer on Stackoverflow
Solution 2 - Htmluser5089931View Answer on Stackoverflow
Solution 3 - HtmlDisgruntledGoatView Answer on Stackoverflow
Solution 4 - HtmlAndoni HendererView Answer on Stackoverflow
Solution 5 - HtmlInfantPro'Aravind'View Answer on Stackoverflow
Solution 6 - HtmlJason Too Cool WebsView Answer on Stackoverflow
Solution 7 - HtmlPenny LiuView Answer on Stackoverflow
Solution 8 - HtmlMuhammad ArmaghanView Answer on Stackoverflow