CSS布局方法

1. 两列布局

 (1)第一种方法:

html:

1 <div id="Lbar"></div>
2 <div id="Rbar"></div>

css:

1 #Lbar{height: 600px;width:200px;background: red;float: left;}
2 #Rbar{height: 600px;width: 60%;background: green;margin-left: 200px;}

左侧固定bar左浮动,右边自适应bar设置width为百分数,margin-left为左侧bar宽度。

(2)第二种方法

1 <div id="Lbar"></div>
2 <div id="content">
3     <div id="Rbar"></div>
4 </div>

css:

#Lbar {width: 200px;height:600px;background-color: red;float: left;margin-right: -100%;}
#content {float: left;width: 100%;}
#Rbar {height:600px;background-color: green;margin-left: 220px;}

左侧固定bar左浮动,margin-right:-100%。右边自适应bar的父元素左浮动,宽度为100%.

margin-right:-100%解释:

往左移动了100%的宽度,使后面的元素移上来占据100%的宽。

“如果给一个浮动元素加上相反方向的负margin,则会使行间距为0且内容重叠。这对于创建1列是100%宽度而其他列是固定宽度(比如100px)的自适应布局来说是非常有用的方法。 ”

 

2. 三列布局,左右固定宽度,中间自适应

(1)第一种方法:浮动

html,div顺序:左右中

1     <div id="leftb"></div>
2     <div id="rightb"></div>    
3     <div id="middleb"></div>

css

#leftb{width: 200px;height: 400px;background: red;float: left;}
#middleb{height: 400px;background: orange;margin: 0 220px;}
#rightb{width: 200px;height: 400px;background: blue;float: right;}

左侧bar左浮动,右侧bar右浮动,中间bar设置margin。

 

(2)第二种方法:绝对定位

html

1     <div id="leftb"></div>
2     <div id="rightb"></div>    
3     <div id="middleb"></div>

css

1 #leftb{width: 200px;height: 400px;background: red;position: absolute;left: 0;}
2 #middleb{height: 400px;background: orange;margin: 0 220px;}
3 #rightb{width: 200px;height: 400px;background: blue;position: absolute;right: 0;}

左侧bar,left:0;右侧bar,right:0。

 

转载于:https://www.cnblogs.com/CassieLY/p/5215580.html

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

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

相关文章

Springcloud整理

Springcloud 答题技巧&#xff1a; 总&#xff1a;当前问题回答的是那些具体的点 分&#xff1a;以1&#xff0c;2&#xff0c;3&#xff0c;4&#xff0c;5的方式分细节取描述相关的知识点&#xff0c;如果有哪些点不清楚&#xff0c;直接忽略过去 突出一些技术名词&#…

java 正则表达式的使用

https://segmentfault.com/q/1010000007136433/a-1020000007139400

Redis集群搭建笔记

系统为CentOS7,创建9001-9006 6个文件夹,复制 redis-server redis.conf 文件到6个新文件夹下 redis.conf文件配置如下: port 9001 daemonize yes cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 3000 cluster-require-full-coverage no appendonly …

记一次生产频繁出现 Full GC 的 GC日志定位

https://cloud.tencent.com/developer/article/1552089 https://www.cnblogs.com/klvchen/articles/11758324.html 感谢&#xff01;

正则高级用法-分组group+替换

public static void main(String[] args) {Pattern patternTestPattern.compile("c\\(a\\)\\(t\\(2\\)\\)");Matcher matcherTestpatternTest.matcher("c(a)(t(2))");System.out.println(matcherTest.matches()); // 全部匹配System.out.println();patter…

java 安全加密

https://www.cnblogs.com/tancky/p/6409823.html https://blog.csdn.net/gulang03/article/details/81771341

Java Servlet(一):创建工程(jdk7+tomcat7+eclipse)

本篇文件主要记录下怎么在jdk7tomcat7下&#xff0c;使用eclipse创建并运行一个servlet工程。 安装具体步骤从网上搜索就可以找到&#xff0c;这里不再赘述。 在eclipse中切换到j2ee下&#xff0c; 从导航菜单windows下找到show view选项&#xff0c;并在show view下找到server…

分支定义之Trunk vs Master

trunk是svn版本管理中的主干表示&#xff0c;而git中的主干叫master&#xff0c;因此git的master相当于svn的trunk&#xff0c;git的开发分支dev分支相当于svn里的branches SVN&#xff1a; trunk&#xff1a;是用来做主方向开发的一直向前进行&#xff0c;一个新模块的开发就…

Jsvc的使用场景

组件启动安装的操作顺序&#xff1a; 执行postinstall.sh 执行启动组件的linux服务 执行组件的__service文件 执行jsvc命令 执行spring boot的main方法 组件的卸载流程&#xff1a; 通过preuninstall.sh脚本&#xff0c;供运行和管理中心来进行调用 启动组件的底层命令&…

inline,block,inline-block的区别

display:blockblock元素会独占一行&#xff0c;多个block元素会各自新起一行。默认情况下&#xff0c;block元素宽度自动填满其父元素宽度。block元素可以设置width,height属性。块级元素即使设置了宽度,仍然是独占一行。block元素可以设置margin和padding属性。display:inline…

mysql 多条件统计

第一种写法 select count(IF(t2.work_order_status102 or t2.work_order_status5,1,null)) as totalComWorkOrderNum, count(IF(t2.work_order_status9,1,null)) as toBeTakingWorkOrderNum, count(IF(t2.work_order_status10,1,null)) as toBeSignedWorkOrderNum, count(IF(t2…

面试、求职妙招!

简历关 简单干净、纯色底板的简历模板是最好的选择简历结构与逻辑&#xff1a;个人信息、教育情况、工作经历、项目经历、自我评价、其他信息。如果有很多段经历&#xff0c;建议优先写最近的经历&#xff0c;然后采用倒叙的顺序来写比较合适&#xff0c;大部分公司习惯从最近…