GVKun编程网logo

HTML布局之计算器(div+css)_html/css_WEB-ITnose(html设计计算器)

10

关于HTML布局之计算器(div+css)_html/css_WEB-ITnose和html设计计算器的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于1.DIV+CSS常用的Html网页布

关于HTML布局之计算器(div+css)_html/css_WEB-ITnosehtml设计计算器的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于1.DIV+CSS常用的Html网页布局代码_html/css_WEB-ITnose、css + div 布局之 CSS盒模型 外边距合并问题_html/css_WEB-ITnose、CSS 完美DIV+CSS布局_html/css_WEB-ITnose、CSS 嵌套DIV布局_html/css_WEB-ITnose等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

HTML布局之计算器(div+css)_html/css_WEB-ITnose(html设计计算器)

HTML布局之计算器(div+css)_html/css_WEB-ITnose(html设计计算器)

 纯布局, 没有功能实现, 代码多但是不难, 可以作为参考.

代码示例:

html(div)代码:

      <title>计算器</title><meta charset="utf-8"><meta name="keywords" content="keyword1,keyword2,keyword3"><meta name="description" content="this is my page"><meta name="content-type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="css/layout.css"><a href="Main.html">返回主页</a>  	<div id="container">  	  		<div id="title">  			<div id="image"><img  src="Image/image.png" alt="HTML布局之计算器(div+css)_html/css_WEB-ITnose" ></div>  			<div id="word">
<p>计算器</p>
<p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1"rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p>
</div>  			<div id="select">  				<div id="min"><img  src="Image/min.png" alt="HTML布局之计算器(div+css)_html/css_WEB-ITnose" ></div>  				<div id="max"><img  src="Image/max.png" alt="HTML布局之计算器(div+css)_html/css_WEB-ITnose" ></div>  				<div id="off"><img  src="Image/off.png" alt="HTML布局之计算器(div+css)_html/css_WEB-ITnose" ></div>  			</div>  		</div>  		  		<div id="main">  			<div id="menu">  			<p>查看(V)</p>  			<div></div>  			<p>编辑(E)</p>  			<div></div>  			<p>帮助(H)</p>  			</div>  			<div id="frame"><img  src="Image/frame.png" alt="HTML布局之计算器(div+css)_html/css_WEB-ITnose" ></div>  			<!-- 下面是按键 -->  			<div id="button">  				<div><p>MC</p></div>  				 <div></div>                      <div><p>MR</p></div>                      <div></div>                      <div><p>MS</p></div>                      <div></div>                      <div><p>M+</p></div>                      <div></div>                      <div><p>M-</p></div>                        <div><p>←</p></div>                      <div></div>                      <div><p>CE</p></div>                      <div></div>                      <div><p>C</p></div>                      <div></div>                      <div><p>±</p></div>                      <div></div>                      <div><p>√</p></div>                        <div><p>7</p></div>                      <div></div>                      <div><p>8</p></div>                      <div></div>                      <div><p>9</p></div>                      <div></div>                      <div><p>/</p></div>                      <div></div>                      <div><p>%</p></div>                        <div><p>4</p></div>                      <div></div>                      <div><p>5</p></div>                      <div></div>                      <div><p>6</p></div>                      <div></div>                      <div><p>*</p></div>                      <div></div>                      <div><p>1/x</p></div>                        <div><p>1</p></div>                      <div></div>                      <div><p>2</p></div>                      <div></div>                      <div><p>3</p></div>                      <div></div>                      <div><p>-</p></div>                      <div></div>                      <div><p>=</p></div>                        <div><p>0</p></div>                      <div></div>                      <div><p>.</p></div>                      <div></div>                      <div><p>+</p></div>    			</div>  		</div>  	</div>  
登录后复制

CSS代码:

@CHARSET "UTF-8";#container{	position: absolute;	top: 50%;	left: 50%;	margin: -161px -114px;	width: 228px;	height: 322px;	border: 1px black solid;	background: #e6e6fa;	}#title{	width: 100%;	height: 30px;	background: #e6e6fa;}#image{	float: left;	width: 14px;	height: 17px;	margin-top: 6px;	margin-left: 10px;}#word{	margin-top: -8px; !important;		float: left;	width: 60px;	height: 20px;}#word p{	font-size: 14px;	text-align: center;}#select{	float: right;	width: 107px;	height: 15px;		margin-right: 8px;}#min{	float: left;	width: 30px;	height: 18px;}#max{	float: left;	width: 30px;	height: 18px;}#off{	float: right;	width: 47px;	height: 18px;}#main{	width: 212px;	height: 284px;	margin-left: 8px;	overflow: hidden;}#menu{	float: left;	width: 212px;	height: 20px;	background: #dcdcdc;}#menu p{	float: left;	font-size: 15px;	margin-top: 1px;	margin-left: 5px;}.block{	float: left;	width: 15px;	height: 20px;}#frame{	float: left;	width: 190px;	height: 48px;	margin-top: 10px;	margin-left: 3px;}#button{	float: left;	width: 190px;	height: 180px;	margin-left: 11px;}.smallbutton{	float: left;	width: 34px;	height: 25px;	margin-top: 5px;	background: #dcdcdc}.bigbuttonY{	float: right;	width: 34px;	height: 55px;	background: #dcdcdc;	margin-top: 5px;}.bigbuttonX{	float: left;	width: 73px;	height: 25px;	background: #dcdcdc;	margin-top: 5px;}.buttonblock{	float: left;	width: 5px;	height: 25px;}#button p{	text-align: center;	margin-top: 3px;}
登录后复制

运行结果:


1.DIV+CSS常用的Html网页布局代码_html/css_WEB-ITnose

1.DIV+CSS常用的Html网页布局代码_html/css_WEB-ITnose

单行一列
以下是引用片段:
body { margin: 0px; padding: 0px; text-align: center; } 
#content { margin-left:auto; margin-right:auto; width: 400px; width: 370px; }

两行一列
以下是引用片段:
body { margin: 0px; padding: 0px; text-align: center;} 
#content-top { margin-left:auto; margin-right:auto; width: 400px; width: 370px;} 
#content-end {margin-left:auto; margin-right:auto; width: 400px; width: 370px;}

三行一列
以下是引用片段:
body { margin: 0px; padding: 0px; text-align: center; } 
#content-top { margin-left:auto; margin-right:auto; width: 400px; width: 370px; }

#content-mid { margin-left:auto; margin-right:auto; width: 400px; width: 370px; } 
#content-end { margin-left:auto; margin-right:auto; width: 400px; width: 370px; }

单行两列
以下是引用片段:
#bodycenter { width: 700px;margin-right: auto; margin-left: auto;overflow: auto; } 
#bodycenter #dv1 {float: left;width: 280px;} 
#bodycenter #dv2 {float: right;width: 410px;}

立即学习“前端免费学习笔记(深入)”;

两行两列
以下是引用片段:
#header{ width: 700px; margin-right: auto;margin-left: auto; overflow: auto;} 
#bodycenter { width: 700px; margin-right: auto; margin-left: auto; overflow: auto; }


#bodycenter #dv1 { float: left; width: 280px;} 
#bodycenter #dv2 { float: right;width: 410px;}

三行两列
以下是引用片段:
#header{ width: 700px;margin-right: auto; margin-left: auto; } 
#bodycenter {width: 700px; margin-right: auto; margin-left: auto; } 
#bodycenter #dv1 { float: left;width: 280px;} 
#bodycenter #dv2 { float: right; width: 410px;} 
#footer{ width: 700px; margin-right: auto; margin-left: auto; overflow: auto; }

单行三列 
绝对定位
以下是引用片段:
#left { position: absolute; top: 0px; left: 0px; width: 120px; } 
#middle {margin: 20px 190px 20px 190px; } 
#right {position: absolute;top: 0px; right: 0px; width: 120px;}

float定位一
xhtml: 
以下是引用片段:

这里是第一列
这里是第二列
这里是第三列

CSS: 
以下是引用片段:
#wrap{ width:100%; height:auto;} 
#column{ float:left; width:60%;} 
#column1{ float:left; width:30%;} 
#column2{ float:right; width:30%;} 
#column3{ float:right; width:40%;} 
.clear{ clear:both;}

float定位二
xhtml:
以下是引用片段:

This is the main content.

This is the left sidebar.

CSS: 
以下是引用片段:
body {margin: 0;padding-left: 200px;padding-right: 190px;min-width: 240px;} 
.column {position: relative;float: left;} 
#center {width: 100%;} 
#left {width: 180px; right: 240px;margin-left: -100%;} 
#right {width: 130px;margin-right: -100%;}

两行三列
xhtml:以下是引用片段:

这里是第一列
这里是第二列

这里是第三列

CSS: 
以下是引用片段:
#header{width:100%; height:auto;} 
#wrap{ width:100%; height:auto;} 
#column{ float:left; width:60%;} 
#column1{ float:left; width:30%;} 
#column2{ float:right; width:30%;} 
#column3{ float:right; width:40%;} 
.clear{ clear:both;}

三行三列 
xhtml:
以下是引用片段:

这里是第一列
这里是第二列
这里是第三列

CSS:
以下是引用片段:
#header{width:100%; height:auto;} 
#wrap{ width:100%; height:auto;} 
#column{ float:left; width:60%;} 
#column1{ float:left; width:30%;} 
#column2{ float:right; width:30%;} 
#column3{ float:right; width:40%;} 
.clear{ clear:both;} 
#footer{width:100%; height:auto;}

css + div 布局之 CSS盒模型 外边距合并问题_html/css_WEB-ITnose

css + div 布局之 CSS盒模型 外边距合并问题_html/css_WEB-ITnose

问题表述:

那天晚上一个同学给我发来一个问题,原型大概是“一个maindiv嵌套了一个div.的div 和一个div.的这样两个 div,他给maindiv 设定了background="black" header1设定background=“red” 。header2 设定background=“blue” 同时给heder1 设定margin-top:10px; 他预想的是内层 div.heder1 的上边距 maindiv 上边有10px的距离 但事实上 出现一个问题 ,内层div 并没有出现他所预想的那种效果,实际效果是 maindiv 仍然紧贴内层div 整个maindiv 上边框距离浏览器上边 增加了10px 的外边距”
登录后复制
问题页面代码:

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 5 <title>无标题文档</title> 6 <style type="text/css"> 7 *{ 8 margin:0; 9 padding:0;10 }11 #maindiv{12 13 width:800px;14 height:800px;15 background-color:#00FFFF;16 <!-- overflow:hidden; -->17 18 }19 .header1{20 width:600px;21 height:100px;22 margin-top:80px;23 background-color:#FF0000;24 overflow:hidden;25 26 }27 .header2{28 border: 1px solid #00FFFF;29 width:600px;30 height:100px;31 margin-top:20px;32 background-color:#666666;33 overflow:hidden;34 35 }36 </style>37 </head>38 39 <body>40 <div id="maindiv">41 <div> 42 新华网马尼拉4月23日电(记者赵洁民)中国驻菲律宾大使馆发言人张华23日对媒体说,43 中国并非如某些人所说的那样,正使中菲在南海黄岩岛的紧张局势升级,而是正使那里的局势降级。44 张华说,中国在黄岩岛海域的渔政310船和海监船084号22日已离开黄岩岛海域。目前,45 只有一艘海监船仍在黄岩岛海域执法。他指出:“中国撤出两艘舰船再一次证明,中国并非如某些人说的那样,46 正使黄岩岛的紧张局势升级,而是使那里的局势降级。”47 这位发言人的谈话是针对菲律宾一些媒体关于“中国正在使黄岩岛局势升级”的误导。48 张华强调,中国愿意通过外交手段友好解决这一事件。49 </div>50 <div>51 新华网马尼拉4月23日电(记者赵洁民)中国驻菲律宾大使馆发言人张华23日对媒体说,52 中国并非如某些人所说的那样,正使中菲在南海黄岩岛的紧张局势升级,而是正使那里的局势降级。53 张华说,中国在黄岩岛海域的渔政310船和海监船084号22日已离开黄岩岛海域。目前,54 只有一艘海监船仍在黄岩岛海域执法。他指出:“中国撤出两艘舰船再一次证明,中国并非如某些人说的那样,55 正使黄岩岛的紧张局势升级,而是使那里的局势降级。”56 这位发言人的谈话是针对菲律宾一些媒体关于“中国正在使黄岩岛局势升级”的误导。57 张华强调,中国愿意通过外交手段友好解决这一事件。58 </div>59 </div>60 61 </body>62 63 </html>问题页面效果如图:
登录后复制

在该页面中<!-- overflow:hidden; --> 被注释掉了,此时页面显示的效果是问题描述的效果,上边有空出一大块,最外层的DIV也跟着加了80px外边距。如果把这句去掉则是我的那个同学预想的效果。这个也是我在查阅文档以及上网求助后找到的一个解决方法。这个问题被归结为"外边距合并问题" 。
登录后复制
问题产生的原因:

在经过我用谷歌浏览器的查看DOM 结果后我发现还是因为一些浏览器的代码渲染差别造成的,我就到http://w3school.com.cn/ 上寻求解释。终于在这里


我看出了问题的存在(盒子没有获得 haslayout 造成 margin-top无效),我到百度上又搜索了一下别人是不是也遇到了同样的问题,综合各家说法我最后总结出以下几个问题的重点:

在常规文档流中,2个或以上的块级盒模型相邻的垂直margin会被折叠。最终的margin值计算方法如下:
a、全部都为正值,取最大者;
b、不全是正值,则都取绝对值,然后用正值减去最大值;
c、没有正值,则都取绝对值,然后用0减去最大值。
注意:相邻的盒模型可能由DOM元素动态产生并没有相邻或继承关系。 相邻的盒模型中,如果其中的一个是浮动的(floated),垂直margin不会被折叠,甚至一个浮动的盒模型和它的子元素之间也是这样。 设置了overflow属性的元素和它的子元素之间的margin不会被折叠(overflow取值为visible除外)。 设置了绝对定位(position:absolute)的盒模型,垂直margin不会被折叠,甚至和他们的子元素之间也是一样。 设置了display:inline-block的元素,垂直margin不会被折叠,甚至和他们的子元素之间也是一样。 如果一个盒模型的上下margin相邻,这时它的margin可能折叠覆盖(collapse through)它。在这种情况下,元素的位置(position)取决于它的相邻元素的margin是否被折叠。
a、如果元素的margin和它的父元素的margin-top折叠在一起,盒模型border-top的边界定义和它的父元素相同。
b、另外,任意元素的父元素不参与margin的折叠,或者说只有父元素的margin-bottom是参与计算的。如果元素的border-top非零,那么元素的border-top边界位置和原来一样。
一个应用了清除操作的元素的margin-top绝不会和它的块级父元素的margin-bottom折叠。
注意,那些已经被折叠覆盖的元素的位置对其他已经被折叠的元素的位置没有任何影响;只有在对这些元素的子元素定位时,border-top边界位置才是必需的。 根元素的垂直margin不会被折叠。 解决方案:
在父层div加上:overflow:hidden; 把margin-top外边距改成padding-top内边距; 父元素产生边距重叠的边有不为 0 的 padding 或宽度不为 0 且 style 不为 none 的 border
父层div加: padding-top: 1px;
让父元素生成一个 block formating context,以下属性可以实现 * float: left/right * position: absolute * display: inline-block/table-cell(或其他 table 类型) * overflow: hidden/auto 父层div加:position: absolute;

就此截住!

注:本文的总结也是网上其他前辈的辛劳我这里知识借用了一下,在此做出声明:我参考的博文地址有:
http://blog.sina.com.cn/s/blog_6bec36f9010110w9.html

http://hi.baidu.com/jmtbai/blog/item/a91a136ca2d098eb42169456.html

立即学习“前端免费学习笔记(深入)”;

还有一点是我觉得有必要说一下的就是这个效果在IE里面出现在谷歌里面不出现,我找到了一点资料是关于IE浏览器关于渲染的原理:
hasLayout:http://baike.baidu.com/view/2945869.htm

                                                                                                                                                                                                                          
登录后复制

CSS 完美DIV+CSS布局_html/css_WEB-ITnose

CSS 完美DIV+CSS布局_html/css_WEB-ITnose

--技巧 先对每个较大div的css样式设置 border:solid 1px blue 整体布局调整完再去掉

1.先弄最外框的

View Code

1 <div id="outterDiv">2 3 </div>
登录后复制

2.马上加上CSS

View Code

1 <style type="text/css">2 3 #outterDiv{ width:600px; }4 5 </style>
登录后复制

3.分析布局左右结构

View Code

1 <div>2 3 </div>4 5 <div>6 7 </div>
登录后复制

4.加上CSS

立即学习“前端免费学习笔记(深入)”;

View Code

1 .InnerDiv { width:49%; float:left; overflow:hidden; margin-left:5px; display:inline; }
登录后复制

5.分析为 左-右-下 结构

View Code

1 <div> 2 3 </div> 4 5 <div> 6 7 </div> 8 9 <div>10 11 </div>
登录后复制

6.加上CSS

View Code

1 .LeftDiv { width:200px; float:left; margin-left:17px;margin-top:10px; display:inline; }2 .RightDiv { width:40px; float:left; display:inline; margin-left:5px; margin-top:100px; }3 .DownDiv { width:200px; text-align:center;margin-bottom:8px; }
登录后复制

7.左部 又分为上下2个DIV

View Code

<div></div><div></div>
登录后复制

8.加上CSS

View Code

1 .NameDiv { width:100%; }2 .SortDiv { width:100%; }
登录后复制

9.填充每个DIV内容

10.全部代码

View Code

1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head runat="server"> 3 <title>排序管理</title> 4 <style type="text/css"> 5 #outterDiv{ width:600px; } 6 .InnerDiv { width:49%; float:left; overflow:hidden; margin-left:5px; display:inline; } 7 .LeftDiv { width:200px; float:left; margin-left:17px;margin-top:10px; display:inline; } 8 .RightDiv { width:40px; float:left; display:inline; margin-left:5px; margin-top:100px; } 9 .DownDiv { width:200px; text-align:center;margin-bottom:8px; }10 .NameDiv { width:100%; }11 .SortDiv { width:100%; }12 </style>13 </head>14 <body>15 <form id="form1" runat="server">16 <div id="outterDiv">17 <div>18 <fieldset>19 <legend>20 <fontfont-size:12px;''>部门管理</font>21 </legend>22 <div>23 <div>24 部门维护:<br />25 <asp:TextBox ID="tbDept" runat="server" Width="200px"></asp:TextBox>26 </div>27 <div>28 部门排序:<br />29 <asp:ListBox ID="LibDeptOrder" runat="server" Height="250px" Width="200px" AutoPostBack="true"30 onselectedindexchanged="LibDeptOrder_SelectedIndexChanged"></asp:ListBox>31 </div>32 </div>33 <div>34 <asp:Button ID="btnDeptUp" runat="server" Text="上移" onclick="btnDeptUp_Click" />35 <br />36 <asp:Button ID="btnDeptDown" runat="server" Text="下移" onclick="btnDeptDown_Click" />37 </div>38 <div>39 <asp:Button ID="btnDeptSave" runat="server" Text="保存" onclick="btnDeptSave_Click" />40 <asp:Button ID="btnDeptDel" runat="server" Text="删除" onclick="btnDeptDel_Click" />41 </div>42 </fieldset>43 </div>44 <div>45 <fieldset>46 <legend>47 <fontfont-size:12px;''>职位管理</font>48 </legend>49 <div>50 <div>51 职位维护:<br />52 <asp:TextBox ID="tbPosi" runat="server" Width="200px"></asp:TextBox>53 </div>54 <div>55 职位排序:<br />56 <asp:ListBox ID="libPosiOrder" runat="server" Height="250px" Width="200px" AutoPostBack="true" 57 onselectedindexchanged="libPosiOrder_SelectedIndexChanged"></asp:ListBox>58 </div>59 </div>60 <div>61 <asp:Button ID="btnPosiUp" runat="server" Text="上移" onclick="btnPosiUp_Click" />62 <br />63 <asp:Button ID="btnPosiDown" runat="server" Text="下移" onclick="btnPosiDown_Click" />64 </div>65 <div>66 <asp:Button ID="btnPosiSave" runat="server" Text="保存" onclick="btnPosiSave_Click" />67 <asp:Button ID="btnPosiDel" runat="server" Text="删除" onclick="btnPosiDel_Click" />68 </div>69 </fieldset>70 </div>71 </div>72 <input type="hidden" id="hidUnitID" runat="server"/>73 </form>74 </body>75 </html>
登录后复制











CSS 嵌套DIV布局_html/css_WEB-ITnose

CSS 嵌套DIV布局_html/css_WEB-ITnose

嵌套div布局,会牵扯到css的position属性

 

如果内层DIV将position属性设置为absolute,并设置left,和top等属性,还需要考虑外层DIV的position属性设置。

 

absolute:absolute绝对定位,直接指定top、left、right、bottom。有意思的是绝对定位也是“相对”的。它的坐标是相对其容器来说的。容器又是什么呢,容器就是离元素最近的一个定位好的“祖先”,定位好的意思就是其Position是absolute或fixed或relative。如果没有这个容器,那就使用浏览器初始的,也就是body或者html元素。标准是说只需要指定left和right,width可以自动根据容器宽度计算出来,可惜ie不支持。

立即学习“前端免费学习笔记(深入)”;

关于HTML布局之计算器(div+css)_html/css_WEB-ITnosehtml设计计算器的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于1.DIV+CSS常用的Html网页布局代码_html/css_WEB-ITnose、css + div 布局之 CSS盒模型 外边距合并问题_html/css_WEB-ITnose、CSS 完美DIV+CSS布局_html/css_WEB-ITnose、CSS 嵌套DIV布局_html/css_WEB-ITnose的相关信息,请在本站寻找。

本文标签: