鱼C论坛

 找回密码
 立即注册
查看: 3149|回复: 7

[作品展示] CSS设置背景图片位置应用小小小案例

[复制链接]
发表于 2021-4-25 21:51:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 肖-肖 于 2021-4-25 22:21 编辑

案例目的::
ft16.png
知识点清单
  1. <!--由于图片太大,而有使用者的屏幕大小不一。导致如果直接使用img插入图片
  2.     1.会使图片的加载速度变慢 2.会导致图片只能显示一部分加入屏幕<图片
  3.     所以要使用背景图片的方式来解决这个问题,用背景位置的方式来实现显示图片的核心内容
  4. -->
复制代码

源代码(源代码中有所有详细的解释)
背景图片应用小小小案例.zip (456.69 KB, 下载次数: 0, 售价: 1 鱼币)
鹅 再写一个小应用不然太小了
案例目的
ft19.png
ft17.png
源代码
背景图片精确定位.zip (512.82 KB, 下载次数: 0, 售价: 1 鱼币)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-4-26 07:22:01 From FishC Mobile | 显示全部楼层
好好努力学啊,后期我会请教你,教我画前端
我现在画的界面都狠丑
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-26 11:41:30 | 显示全部楼层
wp231957 发表于 2021-4-26 07:22
好好努力学啊,后期我会请教你,教我画前端
我现在画的界面都狠丑

大多数人学的都不一样,导致各有长短,所以只能说是互相请教了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-26 11:42:09 | 显示全部楼层
wp231957 发表于 2021-4-26 07:22
好好努力学啊,后期我会请教你,教我画前端
我现在画的界面都狠丑

大多数人学的都不一样,导致各有长短,所以只能说是互相请教了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-26 11:48:18 From FishC Mobile | 显示全部楼层
肖-肖 发表于 2021-4-26 11:42
大多数人学的都不一样,导致各有长短,所以只能说是互相请教了

我画了几个div 因为我在谷歌下做的测试,所以谷歌下正常显示,可是到了360浏览器下,容器不能正常显示,咋弄?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-26 11:54:06 | 显示全部楼层
wp231957 发表于 2021-4-26 11:48
我画了几个div 因为我在谷歌下做的测试,所以谷歌下正常显示,可是到了360浏览器下,容器不能正常显示, ...

你发下代码吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-26 13:09:14 | 显示全部楼层

那个div的 先放放吧
你如果有空 先帮我看看这个代码,这个代码最下面的4个按钮的位置,总是随着浏览器的变化  而变化
导致页面很丑

  1. <!DOCTYPE.html>
  2. <html>

  3. <head>
  4.     <title>CHENGUOFENG's PAGE</title>
  5.     <meta charset="utf-8">
  6.     <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
  7.     </script>
  8.     <style type="text/css">
  9.         .style1 {
  10.             font-size: x-large;
  11.             font-weight: bold;
  12.             color: #FF0000;
  13.         }
  14.         
  15.         .style2 {
  16.             text-align: center;
  17.         }
  18.         
  19.         #btn_1 {
  20.             width: 75px;
  21.         }
  22.         
  23.         .style3 {
  24.             color: #0000FF;
  25.             font-weight: 700;
  26.         }
  27.     </style>

  28. </head>

  29. <body id="mainbody">

  30.     <div class="style2">
  31.         <label for="input_1"><span class="style1">
  32.             <br />
  33.             <br />
  34.             <br />
  35.             <br />
  36.             <br />
  37.             <br />
  38.             <br />
  39.             <br />
  40.             乾安联通实时经营信息系统         <br />
  41.             </span></label><br> 员工姓名: <input type="text" id="name" /><br />
  42.         <br> 系统密码: <input type="password" id="pwd" />
  43.     </div>
  44.     <div class="form-group">
  45.     </div>

  46.     <p>
  47.         &nbsp;</p>
  48.     <p>
  49.         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  50.         <button id="denglu" class="style3" type="button"><b>发展录入</b></button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  51.         <button id="chaxun" class="style3" type="button">日报查询 </button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  52.         <button id="ybchaxun" class="style3" type="button">月报查询 </button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  53.         <button id="weihu" class="style3" type="button"><b>系统维护</b></button>
  54.     </p>

  55.     <script>
  56.         $('#denglu').on('click', function() {
  57.             var name = document.getElementById("name").value;
  58.             var pwd = document.getElementById("pwd").value;
  59.             console.log(name);
  60.             if (name == "" || pwd == "") {
  61.                 alert("帐号和密码不能为空");
  62.             } else {
  63.                 //console.log(htmlname) ;
  64.                 $.ajax({
  65.                     type: "get",
  66.                     url: "/login",
  67.                     data: {
  68.                         'name': name,
  69.                         "pwd": pwd
  70.                     },
  71.                     ContentType: 'text/html',
  72.                     dataType: "html",
  73.                     success: function(hdata) {
  74.                         if (hdata) {
  75.                             if (hdata === "error") {
  76.                                 console.log("hello is wo ");
  77.                                 console.log(typeof(hdata));
  78.                             }
  79.                             console.log("come in 121");
  80.                             console.log(typeof(hdata));
  81.                             //console.log(hdata);
  82.                             //$("#main").html(hdata);
  83.                             var html2 = "";
  84.                             html2 += hdata;
  85.                             //alert("html2");
  86.                             $("#mainbody").html(hdata);

  87.                         } else {
  88.                             console.log("失败了");
  89.                         }
  90.                     },
  91.                     error: function(data, XMLHttpRequest, textStatus, errorThrown) {
  92.                         console.log(data);
  93.                         console.log(XMLHttpRequest.status);
  94.                         console.log(XMLHttpRequest.readyState);
  95.                         console.log(textStatus);
  96.                     }


  97.                 });
  98.             }
  99.         });

  100.         /////////////维护界面//////////////////////////////
  101.         $('#weihu').on('click', function() {
  102.             var name = document.getElementById("name").value;
  103.             var pwd = document.getElementById("pwd").value;
  104.             console.log(name);
  105.             if (name == "" || pwd == "") {
  106.                 alert("帐号和密码不能为空");
  107.             } else {
  108.                 //console.log(htmlname) ;
  109.                 $.ajax({
  110.                     type: "get",
  111.                     url: "/weihu",
  112.                     data: {
  113.                         'name': name,
  114.                         "pwd": pwd
  115.                     },
  116.                     ContentType: 'text/html',
  117.                     dataType: "html",
  118.                     success: function(hdata) {
  119.                         if (hdata) {
  120.                             if (hdata === "error") {
  121.                                 console.log("hello is wo ");
  122.                                 console.log(typeof(hdata));
  123.                             }
  124.                             console.log("come in 121");
  125.                             console.log(typeof(hdata));
  126.                             console.log(hdata);
  127.                             //$("#main").html(hdata);
  128.                             var html2 = "";
  129.                             html2 += hdata;
  130.                             //alert("html2");
  131.                             $("#mainbody").html(hdata);

  132.                         } else {
  133.                             console.log("失败了");
  134.                         }
  135.                     },
  136.                     error: function(data, XMLHttpRequest, textStatus, errorThrown) {
  137.                         console.log(data);
  138.                         console.log(XMLHttpRequest.status);
  139.                         console.log(XMLHttpRequest.readyState);
  140.                         console.log(textStatus);
  141.                     }


  142.                 });
  143.             }
  144.         });
  145.         ////////////////////////查询界面//////////////////////////////////
  146.         $('#chaxun').on('click', function() {
  147.             var name = document.getElementById("name").value;
  148.             var pwd = document.getElementById("pwd").value;
  149.             console.log(name);
  150.             if (name == "" || pwd == "") {
  151.                 alert("帐号和密码不能为空");
  152.             } else {
  153.                 //console.log(htmlname) ;
  154.                 $.ajax({
  155.                     type: "get",
  156.                     url: "/chaxun",
  157.                     data: {
  158.                         'name': name,
  159.                         "pwd": pwd
  160.                     },
  161.                     ContentType: 'text/html',
  162.                     dataType: "html",
  163.                     success: function(hdata) {
  164.                         if (hdata) {
  165.                             if (hdata === "error") {
  166.                                 console.log("hello is wo ");
  167.                                 console.log(typeof(hdata));
  168.                             }
  169.                             console.log("come in 121");
  170.                             console.log(typeof(hdata));
  171.                             console.log(hdata);
  172.                             //$("#main").html(hdata);
  173.                             var html2 = "";
  174.                             html2 += hdata;
  175.                             //alert("html2");
  176.                             $("#mainbody").html(hdata);

  177.                         } else {
  178.                             console.log("失败了");
  179.                         }
  180.                     },
  181.                     error: function(data, XMLHttpRequest, textStatus, errorThrown) {
  182.                         console.log(data);
  183.                         console.log(XMLHttpRequest.status);
  184.                         console.log(XMLHttpRequest.readyState);
  185.                         console.log(textStatus);
  186.                     }


  187.                 });
  188.             }
  189.         });
  190.     </script>

  191. </body>

  192. </html>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-4-26 14:14:57 | 显示全部楼层
本帖最后由 肖-肖 于 2021-4-26 14:16 编辑
wp231957 发表于 2021-4-26 13:09
那个div的 先放放吧
你如果有空 先帮我看看这个代码,这个代码最下面的4个按钮的位置,总是随着浏览器的 ...


改了一小下,你看下吧 虽然不是很华丽但是是居中了
ft20.png
代码如下附加解释
  1. <!DOCTYPE.html>
  2. <html>

  3. <head>
  4.     <title>CHENGUOFENG's PAGE</title>
  5.     <meta charset="utf-8">
  6.     <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
  7.     </script>
  8.     <style type="text/css">
  9.         .style1 {
  10.             font-size: x-large;
  11.             font-weight: bold;
  12.             color: #FF0000;
  13.         }
  14.         
  15.         .style2 {
  16.             text-align: center;
  17.         }
  18.         
  19.         #btn_1 {
  20.             width: 75px;
  21.         }
  22.         
  23.         .style3 {
  24.             color: #0000FF;
  25.             font-weight: 700;
  26.         }
  27.         .btn{
  28.             width:1200px;
  29.             margin:0 auto;/*(1200-470)/2=365*/
  30.             padding-left: 446px;
  31.         }
  32.         .btn button{
  33.             margin-left: 47px;
  34.         }
  35.     </style>

  36. </head>

  37. <body id="mainbody">

  38.     <div class="style2">
  39.         <label for="input_1"><span class="style1">
  40.             <br />
  41.             <br />
  42.             <br />
  43.             <br />
  44.             <br />
  45.             <br />
  46.             <br />
  47.             <br />
  48.             乾安联通实时经营信息系统         <br />
  49.             </span></label><br> 员工姓名: <input type="text" id="name" /><br />
  50.         <br> 系统密码: <input type="password" id="pwd" />
  51.     </div>
  52.     <div class="form-group">
  53.     </div>

  54.     <br>
  55.     <p>
  56.         <div class="btn">
  57.             <button id="denglu" class="style3" type="button"><b>发展录入</b></button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  58.             <button id="chaxun" class="style3" type="button">日报查询 </button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  59.             <button id="ybchaxun" class="style3" type="button">月报查询 </button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  60.             <button id="weihu" class="style3" type="button"><b>系统维护</b></button>
  61.         </div>
  62.     </p>

  63.     <script>
  64.         $('#denglu').on('click', function() {
  65.             var name = document.getElementById("name").value;
  66.             var pwd = document.getElementById("pwd").value;
  67.             console.log(name);
  68.             if (name == "" || pwd == "") {
  69.                 alert("帐号和密码不能为空");
  70.             } else {
  71.                 //console.log(htmlname) ;
  72.                 $.ajax({
  73.                     type: "get",
  74.                     url: "/login",
  75.                     data: {
  76.                         'name': name,
  77.                         "pwd": pwd
  78.                     },
  79.                     ContentType: 'text/html',
  80.                     dataType: "html",
  81.                     success: function(hdata) {
  82.                         if (hdata) {
  83.                             if (hdata === "error") {
  84.                                 console.log("hello is wo ");
  85.                                 console.log(typeof(hdata));
  86.                             }
  87.                             console.log("come in 121");
  88.                             console.log(typeof(hdata));
  89.                             //console.log(hdata);
  90.                             //$("#main").html(hdata);
  91.                             var html2 = "";
  92.                             html2 += hdata;
  93.                             //alert("html2");
  94.                             $("#mainbody").html(hdata);

  95.                         } else {
  96.                             console.log("失败了");
  97.                         }
  98.                     },
  99.                     error: function(data, XMLHttpRequest, textStatus, errorThrown) {
  100.                         console.log(data);
  101.                         console.log(XMLHttpRequest.status);
  102.                         console.log(XMLHttpRequest.readyState);
  103.                         console.log(textStatus);
  104.                     }


  105.                 });
  106.             }
  107.         });

  108.         /////////////维护界面//////////////////////////////
  109.         $('#weihu').on('click', function() {
  110.             var name = document.getElementById("name").value;
  111.             var pwd = document.getElementById("pwd").value;
  112.             console.log(name);
  113.             if (name == "" || pwd == "") {
  114.                 alert("帐号和密码不能为空");
  115.             } else {
  116.                 //console.log(htmlname) ;
  117.                 $.ajax({
  118.                     type: "get",
  119.                     url: "/weihu",
  120.                     data: {
  121.                         'name': name,
  122.                         "pwd": pwd
  123.                     },
  124.                     ContentType: 'text/html',
  125.                     dataType: "html",
  126.                     success: function(hdata) {
  127.                         if (hdata) {
  128.                             if (hdata === "error") {
  129.                                 console.log("hello is wo ");
  130.                                 console.log(typeof(hdata));
  131.                             }
  132.                             console.log("come in 121");
  133.                             console.log(typeof(hdata));
  134.                             console.log(hdata);
  135.                             //$("#main").html(hdata);
  136.                             var html2 = "";
  137.                             html2 += hdata;
  138.                             //alert("html2");
  139.                             $("#mainbody").html(hdata);

  140.                         } else {
  141.                             console.log("失败了");
  142.                         }
  143.                     },
  144.                     error: function(data, XMLHttpRequest, textStatus, errorThrown) {
  145.                         console.log(data);
  146.                         console.log(XMLHttpRequest.status);
  147.                         console.log(XMLHttpRequest.readyState);
  148.                         console.log(textStatus);
  149.                     }


  150.                 });
  151.             }
  152.         });
  153.         ////////////////////////查询界面//////////////////////////////////
  154.         $('#chaxun').on('click', function() {
  155.             var name = document.getElementById("name").value;
  156.             var pwd = document.getElementById("pwd").value;
  157.             console.log(name);
  158.             if (name == "" || pwd == "") {
  159.                 alert("帐号和密码不能为空");
  160.             } else {
  161.                 //console.log(htmlname) ;
  162.                 $.ajax({
  163.                     type: "get",
  164.                     url: "/chaxun",
  165.                     data: {
  166.                         'name': name,
  167.                         "pwd": pwd
  168.                     },
  169.                     ContentType: 'text/html',
  170.                     dataType: "html",
  171.                     success: function(hdata) {
  172.                         if (hdata) {
  173.                             if (hdata === "error") {
  174.                                 console.log("hello is wo ");
  175.                                 console.log(typeof(hdata));
  176.                             }
  177.                             console.log("come in 121");
  178.                             console.log(typeof(hdata));
  179.                             console.log(hdata);
  180.                             //$("#main").html(hdata);
  181.                             var html2 = "";
  182.                             html2 += hdata;
  183.                             //alert("html2");
  184.                             $("#mainbody").html(hdata);

  185.                         } else {
  186.                             console.log("失败了");
  187.                         }
  188.                     },
  189.                     error: function(data, XMLHttpRequest, textStatus, errorThrown) {
  190.                         console.log(data);
  191.                         console.log(XMLHttpRequest.status);
  192.                         console.log(XMLHttpRequest.readyState);
  193.                         console.log(textStatus);
  194.                     }


  195.                 });
  196.             }
  197.         });
  198.     </script>

  199. </body>

  200. </html>
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-25 18:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表