首页 > 其他分享 >HTML 20 - Backgrounds

HTML 20 - Backgrounds

时间:2024-05-18 17:52:54浏览次数:28  
标签:repeat 20 Background color image Backgrounds HTML background

 

The background of a webpage is a layer behind its content, which includes text, images, colors and various other elements. It is an essential part of web design, that improves the overall look of a web page as well as user experience. HTML offers multiple attributes and properties for manipulating the background of elements within a document.

By default, our webpage background is white in color. We may not like it, but no worries. HTML provides the following two good ways to decorate our webpage background.

  • HTML Background with Colors

  • HTML Background with Images

Setting Background Color

An elementary method to modify the background is by altering its color. The background-color property facilitates the specification of a color for an element's background. This can be accomplished by incorporating the following style attribute within the opening tag of an HTML element −

Example

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Styled Div Example</title>
</head>
<body>
   <div style=" color: #4bb354; background-color: #3498db;">
      <h1>Welcome to My Website</h1>
      <p>This is an example of a styled div with a background color and text color.</p>
      <!-- Additional content goes here -->
   </div>
</body>
</html>

 

 

 

In the above example, the background-color property is assigned the hexadecimal color code #3498db, representing a shade of blue. Simultaneously, the color property is utilized to set the text color within the element.

 

Setting Background Image

HTML allows us to specify an image as the background of our HTML web page or table. The background and background-image are used to control the background image of an HTML element, specifically page body and table backgrounds. We simply need to pass the path of an image as a value to both properties as illustrated in the next example −

Example

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>HTML Background Image</title>
   <style>
      /* Add any additional styles here if needed */
      body {
         margin: 0;
         padding: 0;
      }
      .custom-background {
         background-image: url('tp-background.jpg');
         background-repeat: no-repeat;
         background-position: center;
         /* Add any additional styles for the container here */
         height: 100vh;
         /* Adjust the height as needed */
         display: flex;
         justify-content: center;
         align-items: center;
         color: #000000;
      }
   </style>
</head>
<body>
   <div class="custom-background">
      <!-- Content goes here -->
      <h1>Hello, World!</h1>
      <p>This is an example of a background image.</p>
   </div>
</body>
</html>

 

In the above example, the background-image property is assigned to the body of web page.

Background Repeat and Position

HTML offers options for controlling how background images repeat and their positioning. The background-repeat property specifies whether the image should repeat horizontally, vertically, both, or neither. Furthermore, the background-position property empowers developers to determine where the background image should be positioned within the element.

Example

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>HTML Background Repeat</title>
   <style>
      /* Add any additional styles here if needed */
      body {
         margin: 0;
         padding: 0;
      }
      .custom-background {
         background-image: url('logo.png');
         background-repeat: repeat-y;
         background-position: center;
         /* Add any additional styles for the container here */
         height: 100vh;
         /* Adjust the height as needed */
         display: flex;
         justify-content: center;
         align-items: center;
         color: #000000;
      }
   </style>
</head>
<body>
   <div class="custom-background">
      <!-- Content goes here -->
      <h1>Hello, World!</h1>
      <p>This is an example of a background pattern applied using HTML and CSS.</p>
   </div>
</body>
</html>

 

The above HTML program creates a webpage with a centered content div having a repeating vertical background pattern from the specified image. The background color of the container is set to white by default, and the text within the container is styled with a black color, creating a visually appealing and cohesive design.

 

Patterned & Transparent Backgrounds

You might have seen many pattern or transparent backgrounds on various websites. This simply can be achieved by using patterned image or transparent image in the background.

It is suggested that while creating patterns or transparent GIF or PNG images, use the smallest dimensions possible even as small as 1x1 to avoid slow loading.

Example

Here is an examples to set background pattern of a table −

<!DOCTYPE html>
<html>

   <head>
      <title>HTML Background Images</title>
   </head>
    
   <body>
      <!-- Set a table background using pattern -->
      <table background = "pattern1.gif" width = "100%" height = "100">
         <tr>
            <td>
               This background is filled up with a pattern image.
            </td>
         </tr>
      </table>

      <!-- Another example on table background using pattern -->
      <table background = "pattern2.gif" width = "100%" height = "100">
         <tr>
            <td>
               This background is filled up with a pattern image.
            </td>
         </tr>
      </table>
   </body>
   
</html>

 

标签:repeat,20,Background,color,image,Backgrounds,HTML,background
From: https://www.cnblogs.com/emanlee/p/18190443

相关文章

  • HTML 21 - Colors
     HTMLColorsareawayofspecifyingtheappearanceofwebelements.Colorsareveryimportantaspectsofwebdesign,astheynotonlyenhancethevisualappealbutalsoinfluenceuserbehavior.Theyarealsousedtoevokeemotionsandhighlightimportan......
  • HTML 19 - Text Links
     Awebpagecancontainvariouslinksthattakeusdirectlytootherwebpagesorresourcesandevenspecificpartsofagivenpage.Theselinksareknownashyperlinks.HyperlinksallowvisitorstonavigatebetweenWebsitesbyclickingonwords,phrases......
  • P9691 [GDCPC2023] Base Station Construction
    原题链接题解注意数据范围1.我们不知道要在哪些地方建站,所以考虑都遍历一遍2.如果一个地方\(i\)要建站,那么在它前面且离它最近的一个站,一定建在所有右端点大于\(i\)的区间中,左端点最大区间里所以我们令\(dp[i]\)表示为在\(i\)建立一个站,且和\([1,i]\)有交集的区间......
  • HTML 18 - Lists
     HTMLListisacollectionofrelatedinfomation.Thelistscanbeorderedorunderdereddependingontherequirement.Inhtmlwecancreatebothorderandunorderlistsbyusing<ol>and<ul>tags.Eachtypeoflistcanbedecoratedusingpo......
  • Weblogic T3反序列化漏洞(CVE-2018-2628)
    目录前言T3协议概述漏洞复现修复方案前言WebLogicServer是一个企业级的应用服务器,由Oracle公司开发,支持完整的JavaEE规范,包括EJB、JSP、Servlet、JMS等,适合大型分布式应用和高负载场景。T3协议概述T3协议(Two-TierTCP/IPProtocol),是WebLogic中的一种专有协议,建立在TCP/IP协......
  • 用flask框架在html中运行python程序
    目录-app.py-templates-index.html首先安装Flask和OpenCV库pipinstallflaskopencv-python接着创建一个Python脚本,叫做app.pyfromflaskimportFlask,render_template,Responseimportcv2app=Flask(__name__)@app.route('/')defindex():retur......
  • HTML 17 - Tables
     HTMLTablesallowustoputdatainaorganizedwaybyprovidingrowandcolumnfacility.Alsoofferavisualstructurethataidsinclarityandcomprehension,makingthemafundamentalelementinwebdevelopment.WhyTablesareUsedinHTML?Tablesare......
  • HTML 15 - CSS IDs
     HTML"id"isanattributeusedtouniquelyidentifyanelementwithinawebpage.ItservesasalabelforthatelementandenablesJavaScriptandCSStotargetitspecifically.Thisidentificationhelpsinapplyingcustomstyles,makinginter......
  • 代码随想录算法训练营第十一天 | 20.有效的括号 1047.删除字符串中的所有相邻 重复项
    20.有效的括号题目链接文章讲解视频讲解思路:遍历字符串,如果栈不为空,则进行匹配   如果匹配则出栈,否则入栈   如果栈为空,直接入栈   遍历结束后栈为空则说明全部匹配,否则没有全部匹配classSolution{public:boolisValid(strings){stack<cha......
  • [SWPUCTF 2016]Web7 利用ssrf攻击redis
    今天做了一道攻击redis的相关题目,以前没接触过。初始界面有输入框,随便输入看看。是urllib2相关库报错,去搜了搜发现是Python2的Urllib2头部注入(CVE-2016-5699)。那就看看这个cve。说是Python2.x3.x的urllib/urllib2从数据解析到发包的整个流程中,均未对URL提供安全性过滤或检查......