banner



How To Add A Home Page Background Understrap

In this tutorial we'll learn how to use a <div> container to structure the tiptop department of the webpage. We volition use the fashion attribute to specify the height of our <div> container, utilise a groundwork paradigm, and specify that the background prototype should cover the entire area of the <div> container.

Earlier we become started, nosotros'll need a background image. You lot may download and use our sit-in site'southward groundwork image for the purpose of the tutorial, or you can choose a new paradigm. (For a refresher on how to add images to webpages using HTML, please visit our tutorial HTML Images from earlier in this tutorial series).

One time you've called your background image, save the paradigm in your images folder as background-paradigm.jpg.

Next, paste the highlighted code snippet into your index.html file below the opening <torso> tag and to a higher place the closing </torso> tag:

          . . .                                          <body              >                                      <!--First section-->                                                                        <div                                  style                                                                              =                  "                                                                                                                        background-image                      :                                              url                        (                        'Image_Location'                        )                                                                                                                        ;                                                              groundwork-size                      :                      embrace;                      height                      :480px;                      padding-meridian                      :80px;                                        "                                                  >                                                                                      </div                >                                                                    </body              >                        ...                  

Brand sure to switch the text that says Image_Location with the file path of your image and don't forget to add the closing </div> tag.

Annotation that nosotros have added the comment <!--First section--> to aid organize our HTML code. A comment is a piece of code that is ignored by the browser. Comments are used to help explain or organize lawmaking to developers. They are created with the opening tag <!-- and the closing tag -->.

We take also specified the superlative to 480 pixels and padding-elevation to 80 pixels, which will create 80 pixels of space between the top of the <div> element and any content we place within. Note that you will not exist able to run across the furnishings of the padding-elevation value until nosotros place content inside in the adjacent step.

Salve the file and reload information technology in the browser. You should receive something similar this:

Background image in top section

Alternately, you can use a background color instead of a background image. To utilize a background color, replace the <div> element code snippet you only created with the following highlighted <div> element code snippet like this:

          . . .                                          <trunk              >                        <!--Start section-->                                                            <div                                  style                                      =                    "                                          background-color                      :                      #f4bc01;                      peak                      :480px;                      padding-pinnacle                      :80px;                                        "                                                  >                                                                                      </div                >                                                                    </body              >                        ...                  

Relieve the file and reload information technology in the browser to check your results. The background prototype should now be replaced with a container that is the aforementioned size but has a solid yellow color.

If you compare the <div> container on your site with the aforementioned <div> container on the demonstration site, you may discover that your webpage'southward <div> container is surrounded by a small margin of white space. This margin is due to the fact that all HTML pages are automatically gear up to accept a small margin by default.

To remove this margin, nosotros need to add a style attribute to the opening <body> tag that sets the margin of the <body> element of the HTML folio to 0 pixels. Locate the opening <body> in your index.html file and modify it with the highlighted code:

<torso style="margin:0;">

Save and reload the file in your browser. There should now be no white margin surrounding the top <div> container.

Yous should now know how to add a <div> container with a groundwork image to structure the height section of a webpage.

How To Add A Home Page Background Understrap,

Source: https://www.digitalocean.com/community/tutorials/how-to-add-a-background-image-to-the-top-section-of-your-webpage-with-html

Posted by: rossarishe.blogspot.com

0 Response to "How To Add A Home Page Background Understrap"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel