margin

用绝对定位实现垂直居中

ぐ巨炮叔叔 提交于 2019-12-16 23:51:29
用绝对定位实现垂直居中 HTML代码: <div class="posdiv"> <img src="1.jpg" alt=""> </div> CSS代码: body{background: #ccc;} .posdiv{width: 300px;height: 250px;background: #fff;position: relative; margin:0 auto} .posdiv img{width: 100px;position: absolute;top: 50%;margin-top: -50px;} 解释: 一张包裹在div中的img图片,我们给不光给图片以及div元素定义了尺寸,还给div元素定义了#fff的背景色(背景颜色可以根据需求设置)。 给img的父元素添加相对定位属性(position: relative),同时,要给子元素也就是图片img元素添加绝对定位属性(position: absolute)。 将图片元素的top属性设置为50%。 现在我们需要给img元素设置一个负的margin-top值,这个值为你想要实现垂直居中的元素高度的一半。 如果不确定元素的高度,可以不使用margin-top,而是使用transform:translateY(-50%);属性。 来源: https://www.cnblogs.com/jjxhp/p

Set margins in a LinearLayout programmatically

倾然丶 夕夏残阳落幕 提交于 2019-12-16 21:21:17
问题 I'm trying to use Java ( not XML ) to create a LinearLayout with buttons that fill the screen, and have margins. Here is code that works without margins: LinearLayout buttonsView = new LinearLayout(this); buttonsView.setOrientation(LinearLayout.VERTICAL); for (int r = 0; r < 6; ++r) { Button btn = new Button(this); btn.setText("A"); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); // Verbose! lp.weight

Set margins in a LinearLayout programmatically

限于喜欢 提交于 2019-12-16 21:20:06
问题 I'm trying to use Java ( not XML ) to create a LinearLayout with buttons that fill the screen, and have margins. Here is code that works without margins: LinearLayout buttonsView = new LinearLayout(this); buttonsView.setOrientation(LinearLayout.VERTICAL); for (int r = 0; r < 6; ++r) { Button btn = new Button(this); btn.setText("A"); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); // Verbose! lp.weight

HTML与CSS学习笔记(2)

安稳与你 提交于 2019-12-16 21:06:39
1、CSS背景样式? background-color 背景色 background-image 背景图 url(背景地址) 默认:会水平垂直铺满背景图 background-repeat 平铺方式 repeat-x x轴平铺 repeat-y y轴平铺 repeat(x和y都进行平铺,默认值) no-repeat 都不平铺 background-position 背景位置 x y 如果为正数:图片就会往右和下进行偏移;如果为负数:图片往左和上进行偏移 还可以用单词: x:left、center、right y:top、center、bottom 还可以是百分数。 background-attachment :背景图随滚动条移动的方式 scroll:默认值,跟着滚动条移动(背景位置是按照当前元素进行偏移的) fixed:固定,不随浏览器滚动条移动(背景位置是按照浏览器进行偏移的) 2、CSS边框样式? border-style:边框样式 solid:实线; dashed:虚线; dotted:点线; border-width:边框大小 px border-color:边框颜色 red、#f00 边框也可以针对某一条边进行单独设置:border-top-style;中间是方向,可以是left、right、top、bottom 颜色:透明颜色 transparent 3、css文字样式

margin 和padding 的区别

丶灬走出姿态 提交于 2019-12-16 19:17:55
margin是用来隔开元素与元素的间距;padding是用来隔开元素与内容的间隔。margin用于布局分开元素使元素与元素互不相干; padding用于元素与内容之间的间隔,让内容(文字)与(包裹)元素之间有一段“呼吸距离”。 来源: https://www.cnblogs.com/wangshicheng/p/12050703.html

CSS布局基础

陌路散爱 提交于 2019-12-16 15:49:04
CSS布局基础 1.块区域介绍 1: <body> 2: <div> 3: <p>This is a pargraph.</p> 4: </div> 5: </body> p 元素的包含块是 div 元素,因为作为块级元素,表单元格或行内元素,这是最近的祖先元素,类似的,div的包含块是 body. 因此,p的布局依赖于 div的布局,而div的布局则依赖于 body的布局。 块级元素会自动重启一行。 2. 块级元素 正常流布局 一般的,一个元素的width被定义为从左内边界到右内边界,height则是从上内边界到下内边界的距离。 不同的宽度,高度,内边距和外边距相结合,就可以确定文档的布局。 水平布局 简单规则,正常流中块级元素框的水平部分 总和 就等于父元素的 width . 假设一个div中有两个段落,这两个段落的外边距设置为 1 em,段落内容宽度 width 在加上其左,右内边距,边框或外边距加在一起正好是div内容的width. 7大属性,margin-left, border-left, padding-left, width, padding-right, border-right, margin-right 这 7 个属性的值加在一起必须是父块元素的width值. ( 其中 margin-left, margin-right, width 可以设置成auto )

webAPI

 ̄綄美尐妖づ 提交于 2019-12-16 09:58:01
graph TDA[JS]A -->|JS语法| D[ECMAScript]A -->|页面文档对象模型| E[DOM]A -->|浏览器对象模型| F[BOM] API 应用程序编程接口,就是一个工具,以便于能轻松实现想要完成的功能 Web API Web API是浏览器提供的一套操作浏览器功能和页面元素的API(DOM和BOM) DOM 可以改变网页的内容、结构和样式 DOM树 文档:一个页面就是一个文档 document 元素:页面中的所有标签都是元素,element 节点:网页中的所有内容都是节点(标签、属性、文本、注释等),node DOM把以上内容都看作是对象 DOM操作 获取元素 getElementById() 注意: 因为文档页面从上往下加载,所以先有标签,然后才能getElementById 参数是字符串,所以需要加引号 返回的是一个 element 对象 console.dir 可以打印返回的元素对象,更好的查看里面的属性和方法 getElementsByTagName() 参数是字符串,所以需要加引号d 得到的是对象的集合,可以用遍历来获取所有对象 得到的是动态的 例子: 获取ol里面的li <ol><li>123一二三四五</li><li>123上山打老虎</li><li>123老虎有几只</li><li>123快来数一数</li><li>123一二三四五

推荐前端常用的CSS代码

萝らか妹 提交于 2019-12-15 17:12:43
预览地址: https://web.lieme.cn/cssDemo/cssdemo.html github地址: https://juejin.im/post/5dee20936fb9a01638079d52 前端常用的CSS代码 1、垂直居中对齐 .vc { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } .vc { position:absolute; top: 50%; left: 50%; width: 100px; height: 100px; margin:-50px 0 -50px; } 复制代码 2、全屏显示 html, body { position: fixed; width: 100%; height: 100%; } div { height: 100%; } 复制代码 3、不同a标签链接使用不同样式 // link a[href^="http://"]{ background: url(link.gif) no-repeat center right; } // emails a[href^="mailto:"]{ background: url(email.png) no-repeat center right; } // pdfs a[href$

CSS display:inline-block大小不精准问题解决

不羁岁月 提交于 2019-12-15 05:02:53
搭建个人博客的时候,使用公安局备案网站复制下来的代码,发现内容大小无法自由控制的问题。 我的个人博客网站 出问题代码: < el-footer height = " 120px " > < div style =" width : 300px ; margin : 0 auto ; padding : 20px 0 ; background-color : red " > < p style =" height : 20px ; line-height : 20px ; margin : 0px 0px 0px 0px ; color : #939393 ; " > 京ICP备19055038号 </ p > </ div > < div style =" width : 300px ; margin : 0 auto ; padding : 20px 0 ; background-color : blue ; overflow:hidden ; " > < a target = " _blank " href = " rehttp://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11011502003885 " style =" display : inline-block ; text-decoration :

Div CSS常用布局方式代码集锦

末鹿安然 提交于 2019-12-14 21:48:20
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 现在都Div CSS布局了,本文收集整理了一些常用的DivCSS布局代码,比如两行一列、三行一列、两行两列、三行两列、两行三列、单行三列以及float定位的代码集锦,下面逐一帖出各个布局的代码: CSS一行一列布局代码: body{margin:0px;padding:0px;text-align:center;} #content{margin-left:auto;margin-right:auto;width:400px;width:350px;} CSS两行一列布局代码: body{margin:0px;padding:0px;text-align:center;} #content-top{margin-left:auto;margin-right:auto;width:400px;width:350px;} #content-end{margin-left:auto;margin-right:auto;width:400px;width:350px;} CSS三行一列布局代码: body{margin:0px;padding:0px;text-align:center;} #content-top{margin-left:auto;margin-right:auto;width:400px;width