【使用DIV+CSS重写网站首页案例】步骤分析与代码实现

news/2024/5/17 4:06:12/文章来源:https://blog.csdn.net/u012161251/article/details/101739620

使用DIV+CSS重写网站首页案例

 

 

步骤分析:

 

第一步:先定义一个大的 div(整个页面),然后嵌套 8 个小的 div(共八行);

 

第二步:(第一行)在第一个 div 里面嵌套 3 个小的 div;

 

第三步:(第二行)在小 div 里面写一个列表标签(需要使用 css 的 display 属性的 inline);

 

第四步:(第三行)在小 div 里面放置一张图片

 

第五步:(第四行)在小 div 里面嵌套 2 个 div(在下面的 div 再嵌套 2 个 div,最后在右

 

边的 div 里面嵌套 10 个 div)

第六步:(第五行)在小 div 里面放置一张广告图片
第七步:(第六行)复制第四行的代码
第八步:(第七行)在小 div 里面放置一张广告图片
第九步:(第八行) 在小 div 里面放置超链接和文字内容。
代码实现:
* 一般样式设置<style>写在外部css文件
 细节调整:
(注意:样式中,必须是style写的,不然没法这样调整)
F11按键(Ctrl+Shift+I),打开;
,选择要调整的元素;
在样式中,选择相应属性,上下箭头按键进行调整;

调整效果ok,F11按键关闭,在html文件中调整相应的数值;

 

 代码:

 

  1 <!DOCTYPE html>
  2 <html>
  3 
  4     <head>
  5         <meta charset="UTF-8">
  6         <title>首页</title>
  7         <style>
  8             #father {
  9                 border: 1px solid red;
 10                 width: 1300px;
 11                 height: 2200px;
 12                 /*margin可以设置为自动*/
 13                 margin: auto;
 14             }
 15             /*方法一:加上这个框<div id="logo">,
 16             把下面三个小div和menu隔离开*/
 17             /*#logo {
 18                 border: 1px solid black;
 19                 width: 1299px;
 20                 height: 50px;
 21             }*/
 22             
 23             .top {
 24                 border: 1px solid blue;
 25                 width: 431px;
 26                 height: 50px;
 27                 float: left;
 28             }
 29             /*设置内边距,可根据页面F11做调整*/
 30             
 31             #top {
 32                 padding-top: 12px;
 33                 /*注意取值:height=50px-12px*/
 34                 height: 38px;
 35             }
 36             
 37             #menu {
 38                 border: 1px solid red;
 39                 width: 1300px;
 40                 height: 50px;
 41                 background-color: black;
 42             }
 43             /*设置列表的项*/
 44             
 45             ul li {
 46                 /*将列表显示成一行
 47                 inline:内联(不单独成行)*/
 48                 display: inline;
 49                 color: white;
 50             }
 51             /*方法二:(消除浮动)
 52              * 如果没有<div id="logo">的框,
 53              * 三个小div(left浮动)和menu(不浮动)是并列关系,
 54              * 会覆盖menu*/
 55             
 56             #clear {
 57                 clear: both;
 58             }
 59             
 60             #product {
 61                 border: 1px solid red;
 62                 width: 1300px;
 63                 height: 556px;
 64             }
 65             
 66             #product_top {
 67                 border: 1px solid blue;
 68                 width: 100%;
 69                 height: 45px;
 70                 padding-top: 8px
 71             }
 72             
 73             #product_bottom {
 74                 border: 1px solid green;
 75                 width: 1300px;
 76                 height: 500px;
 77             }
 78             /*要让product_bottom_left和product_bottom_right并列,
 79             两个都要加上float: left*/
 80             
 81             #product_bottom_left {
 82                 border: 1px solid red;
 83                 width: 200px;
 84                 height: 500px;
 85                 float: left;
 86             }
 87             
 88             #product_bottom_right {
 89                 border: 1px solid blue;
 90                 width: 1096px;
 91                 height: 500px;
 92                 float: left;
 93             }
 94             
 95             #big {
 96                 border: 1px solid red;
 97                 width: 544px;
 98                 height: 248px;
 99                 float: left;
100             }
101             
102             .small {
103                 border: 1px solid blue;
104                 width: 180px;
105                 height: 248px;
106                 float: left;
107                 /*里面内容居中*/
108                 text-align: center;
109             }
110             
111             #bottom {
112                 text-align: center;
113             }
114             /*去除超链接的下划线*/
115             
116             a {
117                 text-decoration: none;
118             }
119         </style>
120     </head>
121 
122     <body>
123         <div id="father">
124             <!--1.logo-->
125 
126             <!--方法一:-->
127             <div id="logo">
128                 <div class="top">
129                     <img src="../../img/logo2.png" height="46px" />
130                 </div>
131                 <div class="top">
132                     <img src="../../img/header.png" height="46px" />
133                 </div>
134                 <div class="top" id="top">
135                     <a href="#">登录</a>
136                     <a href="#">注册</a>
137                     <a href="#">购物车</a>
138                 </div>
139             </div>
140 
141             <!--方二:-->
142             <div id="clear">
143 
144             </div>
145             <!--2.导航栏-->
146             <div id="menu">
147                 <ul>
148                     <a href="#">
149                         <li style="font-size:20px;">首页</li>
150                     </a>&nbsp;&nbsp;&nbsp;&nbsp;
151                     <a href="#">
152                         <li>手机数码</li>
153                     </a>&nbsp;&nbsp;&nbsp;&nbsp;
154                     <a href="#">
155                         <li>家用电器</li>
156                     </a>&nbsp;&nbsp;&nbsp;&nbsp;
157                     <a href="#">
158                         <li>鞋靴箱包</li>
159                     </a>&nbsp;&nbsp;&nbsp;&nbsp;
160                     <a href="#">
161                         <li>孕婴保健</li>
162                     </a>&nbsp;&nbsp;&nbsp;&nbsp;
163                 </ul>
164             </div>
165             <!--3.轮播图片-->
166             <div id="">
167                 <img src="../../img/1.jpg" width="100%" />
168             </div>
169             <!--4.最新商品-->
170             <div id="product">
171                 <div id="product_top">
172                     &nbsp;&nbsp;
173                     <span style="font-size:25px;">最新商品
174                     &nbsp;&nbsp;<img src="../../img/title2.jpg" />
175                     </span>
176                 </div>
177                 <div id="product_bottom">
178                     <div id="product_bottom_left">
179                         <img src="../../img/big01.jpg" width="100%" height="100%" />
180                     </div>
181                     <div id="product_bottom_right">
182                         <div id="big">
183                             <a href=#><img src="../../img/middle01.jpg" width="100%" height="100%" /> </a>
184                         </div>
185                         <div class="small">
186                             <img src="../../img/small03.jpg" />
187                             <a href="#">
188                                 <p style="color:grey;">电炖锅</p>
189                             </a>
190                             <p style="color: red;">$399</p>
191                         </div>
192                         <div class="small">
193                             <img src="../../img/small03.jpg" />
194                             <a href="#">
195                                 <p style="color:grey;">电炖锅</p>
196                             </a>
197                             <p style="color: red;">$399</p>
198                         </div>
199                         <div class="small">
200                             <img src="../../img/small03.jpg" />
201                             <a href="#">
202                                 <p style="color:grey;">电炖锅</p>
203                             </a>
204                             <p style="color: red;">$399</p>
205                         </div>
206                         <div class="small">
207                             <img src="../../img/small03.jpg" />
208                             <a href="#">
209                                 <p style="color:grey;">电炖锅</p>
210                             </a>
211                             <p style="color: red;">$399</p>
212                         </div>
213                         <div class="small">
214                             <img src="../../img/small03.jpg" />
215                             <a href="#">
216                                 <p style="color:grey;">电炖锅</p>
217                             </a>
218                             <p style="color: red;">$399</p>
219                         </div>
220                         <div class="small">
221                             <img src="../../img/small03.jpg" />
222                             <a href="#">
223                                 <p style="color:grey;">电炖锅</p>
224                             </a>
225                             <p style="color: red;">$399</p>
226                         </div>
227                         <div class="small">
228                             <img src="../../img/small03.jpg" />
229                             <a href="#">
230                                 <p style="color:grey;">电炖锅</p>
231                             </a>
232                             <p style="color: red;">$399</p>
233                         </div>
234                         <div class="small">
235                             <img src="../../img/small03.jpg" />
236                             <a href="#">
237                                 <p style="color:grey;">电炖锅</p>
238                             </a>
239                             <p style="color: red;">$399</p>
240                         </div>
241                         <div class="small">
242                             <img src="../../img/small03.jpg" />
243                             <a href="#">
244                                 <p style="color:grey;">电炖锅</p>
245                             </a>
246                             <p style="color: red;">$399</p>
247                         </div>
248                     </div>
249                 </div>
250             </div>
251             <!--5.广告图片-->
252             <div id="">
253                 <img src="../../img/ad.jpg" width="100%" />
254             </div>
255             <!--6.热门商品-->
256             <div id="">
257                 <div id="product_top">
258                     &nbsp;&nbsp;
259                     <span style="font-size:25px;">热门商品
260                     &nbsp;&nbsp;<img src="../../img/title2.jpg" />
261                     </span>
262                 </div>
263                 <div id="product_bottom">
264                     <div id="product_bottom_left">
265                         <img src="../../img/big01.jpg" width="100%" height="100%" />
266                     </div>
267                     <div id="product_bottom_right">
268                         <div id="big">
269                             <a href=#><img src="../../img/middle01.jpg" width="100%" height="100%" /> </a>
270                         </div>
271                         <div class="small">
272                             <img src="../../img/small03.jpg" />
273                             <a href="#">
274                                 <p style="color:grey;">电炖锅</p>
275                             </a>
276                             <p style="color: red;">$399</p>
277                         </div>
278                         <div class="small">
279                             <img src="../../img/small03.jpg" />
280                             <a href="#">
281                                 <p style="color:grey;">电炖锅</p>
282                             </a>
283                             <p style="color: red;">$399</p>
284                         </div>
285                         <div class="small">
286                             <img src="../../img/small03.jpg" />
287                             <a href="#">
288                                 <p style="color:grey;">电炖锅</p>
289                             </a>
290                             <p style="color: red;">$399</p>
291                         </div>
292                         <div class="small">
293                             <img src="../../img/small03.jpg" />
294                             <a href="#">
295                                 <p style="color:grey;">电炖锅</p>
296                             </a>
297                             <p style="color: red;">$399</p>
298                         </div>
299                         <div class="small">
300                             <img src="../../img/small03.jpg" />
301                             <a href="#">
302                                 <p style="color:grey;">电炖锅</p>
303                             </a>
304                             <p style="color: red;">$399</p>
305                         </div>
306                         <div class="small">
307                             <img src="../../img/small03.jpg" />
308                             <a href="#">
309                                 <p style="color:grey;">电炖锅</p>
310                             </a>
311                             <p style="color: red;">$399</p>
312                         </div>
313                         <div class="small">
314                             <img src="../../img/small03.jpg" />
315                             <a href="#">
316                                 <p style="color:grey;">电炖锅</p>
317                             </a>
318                             <p style="color: red;">$399</p>
319                         </div>
320                         <div class="small">
321                             <img src="../../img/small03.jpg" />
322                             <a href="#">
323                                 <p style="color:grey;">电炖锅</p>
324                             </a>
325                             <p style="color: red;">$399</p>
326                         </div>
327                         <div class="small">
328                             <img src="../../img/small03.jpg" />
329                             <a href="#">
330                                 <p style="color:grey;">电炖锅</p>
331                             </a>
332                             <p style="color: red;">$399</p>
333                         </div>
334                     </div>
335                 </div>
336             </div>
337             <!--7.广告图片-->
338             <div id="">
339                 <img src="../../img/footer.jpg" width="100%" />
340             </div>
341             <!--7.友情链接和版权信息-->
342             <div id="bottom">
343                 <td align="center">
344                     <a href="#">关于我们</a> &nbsp;
345                     <a href="#">联系我们</a> &nbsp;
346                     <a href="#">法律声明</a> &nbsp;
347                     <a href="#">...</a>
348 
349                     <p>
350                         Copyright ...
351                     </p>
352                 </td>
353             </div>
354         </div>
355     </body>
356 
357 </html>

 

 

结果:(未细调)

http://127.0.0.1:8020/WEB02_HTML%26CSS/%E6%A1%88%E4%BE%8B%E4%BA%8C%EF%BC%9A%E4%BD%BF%E7%94%A8Div%2bCSS%E5%AE%9E%E7%8E%B0%E7%BD%91%E7%AB%99%E9%A6%96%E9%A1%B5%E9%87%8D%E6%9E%84/05_CSS%E6%B5%AE%E5%8A%A8/%E4%BD%BF%E7%94%A8Div%2bCSS%E5%AE%9E%E7%8E%B0%E7%BD%91%E7%AB%99%E9%A6%96%E9%A1%B5%E9%87%8D%E6%9E%84.html

 

用到的CSS内容:

  • margin: auto;

  • 注意盒子模型的取值计算

  • 内联: display: inline;

  • 内容居中:text-align: center;

  • 去除超链接的下划线

 

 

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_760506.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

简易网站栏目解决方案(附代码)

虽然是购物系统&#xff0c;但由于没有具体需求&#xff0c;只能多加几个诸如最新动态&#xff0c;精品推荐&#xff0c;近期公告&#xff0c;热点问答等小栏目上去凑数了&#xff01;为了能更高效的制作管理站点&#xff0c;经过多番思考设计了栏目及栏目类别关系模式&#xf…

zz.NET开发人员必知的八个网站

当前全球有数百万的开发人员在使用微软的.NET技术。如果你是其中之一&#xff0c;或者想要成为其中之一的话&#xff0c;我下面将要列出的每一个站点都应该是你的最爱&#xff0c;都应该收藏到书签中去。 对于不熟悉.NET技术的朋友&#xff0c;需要说明一下&#xff0c;.NET提供…

父级元素绑定定mouseout和mouseover,移过子元素是都会触发

2019独角兽企业重金招聘Python工程师标准>>> mouseover与mouseenter 不论鼠标指针穿过被选元素或其子元素&#xff0c;都会触发 mouseover 事件。 只有在鼠标指针从元素外穿入被选元素&#xff08;到元素内&#xff09;时&#xff0c;才会触发 mouseenter 事件。 mo…

一个绝佳的学习网站技术的网站——w3school

上个月无意中进入一个网站&#xff0c;看到里面还有挺多教程的&#xff0c;不管三七二十一&#xff0c;先收藏先。进去尝试一下w3school&#xff0c;感觉非常的棒。 首先它提供整套的网站架设技术的培训教程&#xff0c;从html->css->javaScript->php->SQL->.ne…

多家网站用户密码数据库被爆 下载地址及文件网络疯传

国内最大的程序员网站CSDN网站21日被曝600万用户的数据库信息被***公开&#xff0c;随后网上出现嘟嘟牛、7K7K、多玩网、178游戏网等多家网站也出现用户数据库泄露的消息。 用户数据库文件集合&#xff1a; CSDN-中文IT社区-600万.rar 104MB 多玩网_800W.rar 216MB 人人网500W_…

大型网站技术架构(七)网站的可扩展性架构

2019独角兽企业重金招聘Python工程师标准>>> 扩展性是指对现有系统影响最小的情况下&#xff0c;系统功能可持续扩展或提升的能力。 设计网站可扩展架构的核心思想是模块化&#xff0c;并在此基础上&#xff0c;降低模块间的耦合性&#xff0c;提供模块的复用性。模…

大型网站技术架构(一)大型网站架构演化

2019独角兽企业重金招聘Python工程师标准>>> 看完了有一本书&#xff0c;就应该有所收获&#xff0c;有所总结&#xff0c;最近把《大型网站技术架构》一书给看完了&#xff0c;给人的印象实在深刻&#xff0c;再加上之前也搞过书本上讲的反向代理和负载均衡以及ses…

网站数据分析的基本流程、思路与焦点:看趋势、看分布、看对比

2019独角兽企业重金招聘Python工程师标准>>> 1、网站数据分析基本流程 网站数据分析没有规范的分析流程容易使最后的结果逻辑混乱或者偏离原来的主题&#xff0c;所以一套规范的流程能够使网站分析更加清晰和有效。 网站分析其实就是一个发现问题、分析问题的解决…

优秀案例:20个销售顶级名鞋的电子商务网站

今天&#xff0c;我们为您带来20佳来自世界各地的顶级品牌鞋电子商务网站设计。现在网上购物是越来越受欢迎&#xff0c;在线购物让我们可以足不出户买到心仪的商品。 设计电子商务网站是一项非常有挑战性的任务。如果网站销售的是顶尖品牌的鞋&#xff0c;那么网站应该传达一种…

谁在使用我的网站——用户分类

谁在使用我的网站——用户分类 用户分类 在网站分析中&#xff0c;根据用户的基本信息和行为特征可以将用户分为许多类别&#xff0c;衍生出各种各样的用户指标&#xff0c;对于用户总体的统计可以让我们明确用户的整体变化情况&#xff0c;而对于用户各分类的统计分析&#xf…

浙江高考成绩查询2021电话,2021年浙江高考查分时间几点及查询电话网站系统入口...

高考是一场绝对公平的笔试&#xff0c;它不需要看颜值、不需要拼关系&#xff0c;你能考出多少分&#xff0c;全凭实力。2020年浙江高考查询时间是什么呢&#xff1f;几号几点可以查询到自己成绩&#xff0c;本文高考升学网整理了关于2020年浙江高考查询时间及几点钟可以查询的…

MyBatis学习门户网站(一)

需要jar包&#xff1a;mybatis-3.x.x.jar 、假设需要和spring综合&#xff0c;此外&#xff0c;我们需要增加相关的包 1&#xff1a;看到项目文件夹 不要在意红色 2&#xff1a;依照步骤&#xff1a; 1&#xff1a;增加jar包 2&#xff1a;创建数据源&#xff08;configuration…

基于jQuery适合做图片类网站的特效

分享一款基于jquery适合做图片类网站的特效。这是一款鼠标经过图片滑动弹出标题效果代码。效果图如下&#xff1a; 在线预览 源码下载 实现的代码。 html代码&#xff1a; <div class"common"><ul><li class"listbox mr20"><div c…

使用GitHub建立个人网站

使用GitHub建立个人网站 1 Git简介 2 为什么使用Github Pages 3 创建Github Pages 3.1 安装git工具. 3.2 两种pages模式 3.3 创建步骤 3.4 常用命令 4 使用Jekyll搭建博客 4.1 什么是jekyll 4.2 jekyll本地环境搭建 4.3 jekyll目录结构 4.4 Jekyll-Bootstrap创建博客 4.5 Je…

阿里云--域名,主机,备案都配置好了,就是不能访问网站的解决方案

异常处理汇总 ~ 修正果带着你的Net飞奔吧&#xff01;http://www.cnblogs.com/dunitian/p/4599258.html 1.解析问题&#xff1a;参考这个文章&#xff1a;http://www.cnblogs.com/dunitian/p/4977261.html 2.主机设置问题&#xff1a; 主机管理 http://cp.aliyun.com/ 主机里面…

利用github pages创建简单的网站

github.com 作为最流行的源代码管理工具已经风靡全球&#xff0c;同时在依托于github也衍生出了各种各样的应用&#xff0c;比如可以利用github搭建博客系统等等。 先换个话题&#xff0c;我们每人手头都或多或少有些“藏”书&#xff0c;这里的“藏”我打了引号&#xff0c;因…

网站服务器双机,LVS-DR+Keepalived网站服务器双机热备配置(示例代码)

keepalived是一个类似于layer3, 4 & 7交换机制的软件&#xff0c;也就是我们平时说的第3层、第4层和第7层交换。Keepalived是自动完成&#xff0c;不需人工干涉。调度服务器&#xff1a;需要在LVS的基础上面做。参考上两节&#xff1a;负载均衡群集之一LVS-DR&#xff1a;h…

分享代码的添加|网站中怎么添加分享|分享代码的样式添加|分享工具的添加|网站中怎么添加分享工具...

2019独角兽企业重金招聘Python工程师标准>>> 请参考网站&#xff1a;http://www.jiathis.com/share &#xff08;所有的分享&#xff0c;可以自动生成代码&#xff0c;超简单的&#xff09; 介绍和使用&#xff1a; 分享代码的添加|网站中怎么添加分享|分享代码的样…

authentication与网站安全验证

1.Forms 身份验证提供程序 通过 Forms 身份验证&#xff0c;可以使用所创建的登录窗体验证用户的用户名和密码。未经过身份验证的请求被重定向到登录页&#xff0c;用户在该页上提供凭据和提交窗体。如果应用程序对请求进行了验证&#xff0c;系统会颁发一个票证&#xff0c;该…

SEO意识的网站设计:设计和SEO的完美结合可能么?

日期&#xff1a;2011/11/10 来源&#xff1a;GBin1.com 介绍 约 束和创新是一对天生的冤家&#xff0c;为了更好的提升其中一个方面你不得不需要牺牲另外一个方面。同样的原因造成了设计者仍然在黑暗中摸索如果有效的结合SEO和设 计理念。SEO往往遵循着特定的原则&#xff0…