{"id":174,"date":"2022-04-15T18:23:28","date_gmt":"2022-04-15T18:23:28","guid":{"rendered":"https:\/\/apaddedcell.com\/?p=174"},"modified":"2022-04-15T18:31:27","modified_gmt":"2022-04-15T18:31:27","slug":"what-div","status":"publish","type":"post","link":"https:\/\/www.apaddedcell.com\/what-div\/","title":{"rendered":"What is a Div?"},"content":{"rendered":"\n
There is a lot of material on the Internet about divs. So I decided to create an article that would contain everything about block layout. From this article you will learn how to create your first page using block layout. But the main focus of this article I still want to make on the various problems that ordinary users face, especially beginners who are just beginning their acquaintance with Divs. <\/p>\n\n\n\n
In this article we will look at the different ways of using divs, what you can do with them, how to modify them and how to use them in general. Under the article you will see comments, leave your comments, questions and I will definitely help solve your problem and even add your problem to the main article for other users.<\/p>\n\n\n\n
Previously, in the era of the formation of the Internet sites were made up using tables, which was quite ineffective, and to replace this outdated method came a new – block layout, using Divs. As you can see, even the names of the methods of making up sites reflect the tags that are used in the creation of the site. Previously, it was the tag <table> <\/strong>now tag <div>.<\/strong><\/p>\n\n\n\n If you look at almost any modern website, it is possible to note their certain similarity, namely the presence on these sites certain areas: menu (menu), content (content), the header (header), the bottom of the site (footer). These zones are almost any site. And they all look like this, as shown below<\/p>\n\n\n\n In the picture, I have indicated different colors for different areas of my site. In red – the header, green – menu, blue – content, black – bottom of the site. In the middle of the content I also added a block of article titles, and actually a block of the article (text). This is how 70% of sites on the Internet look like, maybe only blocks change places, but the essence remains the same.<\/p>\n\n\n\n The benefits of divine layout are as follows:<\/p>\n\n\n\n Naturally, we will start with a simple one, and our goal is to create the layout of the site, which is shown above. Yes, all the code that needs to be written on the pages I will include in the appropriate codes.<\/p>\n\n\n\n Let’s create a simple page template using divs. Please note that this code should be put after <body> and before<\/body>. Well, I hope you do not need to explain this.<\/p>\n\n\n\n What did I get? <\/p>\n\n\n\n On the page should appear the words: block 1, block 2, block 3<\/strong>, which are in a column, one after the other, with nothing else on the page. The same effect, by the way, can be achieved using the html tag <p><\/strong>. You ask, and then what. Now here comes the fun part. In order to manipulate our divs, change them and generally do with them everything your heart desires (not really everything, but this is at the end of the article), we must use the file CSS. I will not dwell on it here, because I think you know what it is. It is desirable to make a habit of attaching a styles file to your pages at once, rather than inserting styles into each file. As a result, we should have two files: index.html<\/strong> and style.css<\/strong> – these files should be created in any editor (even notepad will do), the main thing is to set the extension of the file when saving it.<\/p>\n\n\n\n Let’s now define a red separator bar for our divs. Attention, below is the code to specify in the css.<\/p>\n\n\n\n Insert the same code in the index.html<\/strong><\/p>\n\n\n\n By creating these two files (style.css and index.html) and opening index.html we will see the same thing as in the previous case, but each div will have a red border. We will “control” the blocks using CSS and assigning a specific div its own class. Immediately I say that writing something like style=”color: #a00;” (i.e. using inline styles) directly in the html page is considered bad form, and later will complicate your life too – it is difficult to debug such a page. (Imagine that you want to change something on the site, and you have thousands of pages, tired to change. Here you just need to change just one file.<\/p>\n\n\n\n Here we have created a selection of our blocks with a red line, but, as they say, we can’t go far on this. So let’s place our blocks horizontally. To do this, let’s use the great property CSS-float<\/strong>. This property is responsible for the alignment of our blocks, and with this property we can align our blocks as we wish. Now let’s place our blocks horizontally, one by one. <\/p>\n\n\n\n NOTE:<\/strong> You can set an alignment only on the left or on the right, there is no alignment, keep it in mind! Let’s write our code in CSS.<\/p>\n\n\n\n If we now open the page in our browser, the result is that our divs are one after the other. Their width depends on the content in those divs, and is calculated automatically by the browser. If you set float:right <\/strong>to the second div, you will see that the second div is nailed to the right side of our page. This way you can easily set the order of our divs and form menus or content. In the future, it is advisable to set the width of each div, so that you don’t get any unnecessary tinsel.<\/p>\n\n\n\n Important!<\/strong><\/p>\n\n\n\n I want to note right away, if you are new to css, get used to the good stuff right away, which is to use classes in css, not id’s. This will help you in the future, especially when you work with jQuery libraries. Also, it is highly recommended to write “talking” class names. For example, for content, it is advisable to name the diva class .content, and for the sidebar, .sidebar. If you want to emphasize some property for a certain element on your page, then use #id.<\/p>\n\n\n\n Important! <\/strong><\/p>\n\n\n\n In the code you may notice a strange notation in the html \u2014 <div style=\u00bbclear: both;\u00bb><\/div>. <\/strong>What is this obscure third div, you may ask? It’s simple, dear programmers, we have to tell the browser that after this command, all other divs should go below the previous ones. If this is not done, you can get a bad situation where the divs line up in one column or overlap each other. This is a command to the browser like the html tag<br>, but for divs.<\/p>\n\n\n\n Important features in block layout with divs. And knowing how to use them will help you in creating individual design solutions for your site. Initially, if you omit these properties of our divs (blocks), we get the following picture: all the divs are placed right next to each other, whether they are one after the other or one below the other. It is thanks to our properties like padding<\/strong> and margin <\/strong>that we can define the gaps between the divs, or within the divs themselves. For example:<\/p>\n\n\n\n With this code in CSS, we specified our divs the distance between them, as well as the distance of the internal content within the block itself.<\/p>\n\n\n\n If we want one of our blocks (div) to be at some special distance from its neighboring block, we need to use the margin property.<\/p>\n\n\n\n Important: <\/strong>The padding<\/strong> and margin<\/strong> properties have the following parameters. If we just set the number of pixels and that’s it, that’s what we did with padding, then all four sides<\/strong> will do this distance. If we set two values, for example margin: 10px 5 px. Then the top and bottom will be 10px, and the left and right will be 5px.<\/p>\n\n\n\n Important: <\/strong>There are also personalized gaps. These are specified by assigning the words bottom, top, left, right<\/strong> to our properties. In our example above we use the distance to the right.<\/p>\n\n\n\n Sometimes we need to set a distinct boundary to our blocks to clearly show the difference between them. In this case we need the border property. Thanks to this property we will be able to set a border to the diva of our choice. This property has three parameters, separated by spaces. The first parameter is the width (in pixels). Actually this is the width of our border. The second parameter is the style. There are a lot of styles, so it would take a whole article to describe them all. What styles are possible? For example, you can have a double border or a dashed one. And so on. In our example, we use solid – a single line of a given width. The third parameter is the color itself. It can be specified by a 16-character code, or by a word in English, such as black.<\/p>\n\n\n\n You can also specify a border for each side of our div, for this use the already mentioned top, bottom, left, right. Example code below.<\/p>\n\n\n\n Now we can set the width and height of our divs, which will make our divs more visible. Simply add in the properties of each class of our divs width:300px; height:500 px. Opening our page now, you’ll see that our blocks are much larger and now look fuller. I’ll go ahead and say that width and height can be specified in pixels or percentages. Keep that in mind. <\/p>\n\n\n\n You and I have reached a pretty important point in the layout of the site, namely the wrapper. It is up to you to choose whether to use it in the future, but I advise you to use it. But first, let’s understand what it is.<\/p>\n\n\n\n Usually, when we create a site, we want our site to be centered in our browser window. And we usually set our site to some fixed parameters, like width or height. So we would like it to look great and be visual. That’s why we created a div-block called Wrapper. It represents a container in which all the other blocks are located.<\/p>\n\n\n\n How to use it? To do this, we create our div wrapper right after the tag, then place all the other blocks of our site inside our wrapper, and then close the div wrapper.<\/p>\n\n\n\n In CSS we give our wrapper a fixed width (usually it is 990 px, but you can experiment here – this is because most users currently use a resolution of 1024\u00d7768, but the resolution is constantly growing, so in the future this value must be changed), and specify the following: margin-left: auto; margin-right: auto;<\/p>\n\n\n\n All this will make our site centered in the middle, and we must take into account that our tag has <body> also have their own indentations, so it’s advisable to remove them immediately. Insert the code below into our CSS file.<\/p>\n\n\n\n Also, please note that if we want to change the distance from the top or any other side, it is best to use the margin property of the wrapper.<\/p>\n\n\n\n Okay, well, now it’s time for us to finally lay out the entire site, which was shown in the picture above. Below I’ve listed the code that should be in index.html and in style.css.<\/p>\n\n\n\n CSS file:<\/strong><\/p>\n\n\n\n From the above code you can see that, thanks to block layout, we have reduced our code in the index.html to a minimum, but our page is very functional, it is easy to modify, editing just one file style.css. That’s all, you can use this code or make your own using this one as an example.<\/p>\n","protected":false},"excerpt":{"rendered":" There is a lot of material on the Internet about divs. So I decided to create an article that would contain everything about block layout. From this article you will learn how to create your first page using block layout....<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,11],"tags":[],"_links":{"self":[{"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/posts\/174"}],"collection":[{"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/comments?post=174"}],"version-history":[{"count":4,"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":181,"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/posts\/174\/revisions\/181"}],"wp:attachment":[{"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/media?parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/categories?post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.apaddedcell.com\/wp-json\/wp\/v2\/tags?post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}Advantages of block div layout<\/h3>\n\n\n\n
Start coding using <Div><\/h3>\n\n\n\n
<div> block 1 <\/div>\n<div> block 2 <\/div>\n<div> block 3 <\/div><\/code><\/pre>\n\n\n\n
div{\nborder: 1px solid red;\n}<\/code><\/pre>\n\n\n\n
<html>\n<head>\n<link href=\u00bbstyle.css\u00bb rel=\u00bbstylesheet\u00bb>\n<head>\n<body>\n<div> block 1 <\/div>\n<div> block 2 <\/div>\n<div> block 3 <\/div>\n<\/body>\n<\/html><\/code><\/pre>\n\n\n\n
Float property for Divs<\/h3>\n\n\n\n
.div{\nborder: 1px solid red;\nfloat: left;\n}<\/code><\/pre>\n\n\n\n
Padding and margin for divs<\/h3>\n\n\n\n
.div{\nborder: 1px solid red;\nfloat: left;\npadding: 10px;\nmargin-right: 10px;\n}<\/code><\/pre>\n\n\n\n
The border property – set the borders of our divs<\/h3>\n\n\n\n
.div{\nborder: 1px solid red;\nfloat: left;\npadding: 10px;\nmargin-right: 10px;\nborder: 1px solid red;\n}<\/code><\/pre>\n\n\n\n
Width and height property for divs<\/h3>\n\n\n\n
Wrapper. What is it and why?<\/h3>\n\n\n\n
body, html{\nmargin: 0px; padding: 0px;\n}<\/code><\/pre>\n\n\n\n
Div layout – Coding block layout TOTAL<\/h3>\n\n\n\n
body, html{\nfont: 12px tahoma;\nmargin: 0px;\npadding: 0px;\n}\n\ndiv{\ntext-align: center;\n}\n\n.wrap{\nwidth: 990px;\nmargin-left: auto;\nmargin-right: auto;\nbackground: #ddd;\npadding: 10px;\n}\n\n.header{\nbackground: #e25e5e;\nheight: 100px;\nmargin-bottom: 10px;\npadding: 10px;\n}\n\n.sidebar{\nfloat: left;\npadding: 10px;\nwidth: 300px;\nbackground: #5ee28d;\nheight: 700px;\n}\n\n.content{\nfloat: left;\npadding: 10px;\nmargin-left: 10px;\nbackground: #5e86e2;\nwidth: 640px;\nheight: 700px;\ntext-align: left;\n}\n\n.bottom{\nbackground: #141926;\nheight: 60px;\nmargin-top: 10px;\npadding: 10px;\n}<\/code><\/pre>\n\n\n\n