Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a "div tag"? (Please explain with examples) [closed]

Okay so,

This might not be the best question but I am new to programming (I'm 12) I think I've pretty much gotten down HTML and CSS, and I've moved into JavaScript. But I do not understand "div tags" and what they do. Can you please explain this to me? :) Thanks

like image 979
OwenCraddock Avatar asked Jan 12 '23 01:01

OwenCraddock


1 Answers

The HTML <div> element (or HTML Document Division Element) is the generic container for flow content, which does not inherently represent anything. It can be used to group elements for styling purposes (using the class or id attributes), or because they share attribute values, such as lang. It should be used only when no other semantic element (such as <article> or <nav>) is appropriate.

Example

<div>
  <p>Any kind of content here. Such as &lt;p&gt;, &lt;table&gt;. You name it!</p>
</div>

Result

Any kind of content here. Such as <p>, <table>. You name it!

DIV - MDN

As for javascript, its an HTML element and it can be manipulated the same way any other html element can with the except of form elements. HTMLElement - MDN

With each HTML element you have browser default styling, like <b> and <strong> tags their default styling is to bold text or font-weight: bold. And <div> default styling is display: block which just means there is a line break before and after each div element, and of course you know you can change the default styling of that element with CSS

Example on how to change the default styling. this will change every <div> element's text color to red

 div {
  // change default styling here
  color: red;
 }

Looks like you'll need some CSS references too, don't use w3school btw. try MDN Learn CSS | MDN

like image 164
Jay Harris Avatar answered Jan 30 '23 07:01

Jay Harris