intouch负值显示0_17、定位的盒子居中显示

本文介绍了如何使用CSS实现盒子居中显示,包括定位和标准流的居中方法,并探讨了Intouch中负值显示为0的问题。通过实例展示了定位盒子的居中技巧,如设置`margin: 0 auto`和使用负`margin-left`。同时,文章强调了HTML标签的正确使用规范,避免非标准用法。
摘要由CSDN通过智能技术生成

盒子居中显示

margin: 0 auto; 只能让标准流的盒子居中对齐,脱标的盒子无法居中;

定位的盒子居中:先向右走父级盒子的一半50%,然后再向左走子盒子的一半(margin-left:负值);

body {

margin: 0;

padding: 0;

}

.box {

height: 500px;

background-color: #aaa;

position: relative;

}

.nav {

width: 960px;

height: 60px;

background-color: #666;

position: absolute;

bottom: 0;

/*首先走到父盒子的一半*/

left: 50%;

/*然后使用负数,往回走,走子盒子的一半*/

margin-left: -480px;

}

0ef5deeb8bbc2be59c0cb74c37868fc1.png

顺风盒子居中

body,ul {

margin: 0;

padding: 0;

}

.banner {

width: 1259px;

height: 472px;

margin: 0 auto;

position: relative;

}

.search {

width: 960px;

height: 60px;

background-color: #666;

position: absolute;

bottom: 0;

left: 50%;

margin-left: -480px;

}

.search ul li {

list-style: none;

}

.search ul li {

float: left;

}

.search ul li a {

display: inline-block;

width: 160px;

height: 60px;

line-height: 60px;

text-align: center;

color: #fff;

text-decoration: none;

}

.search ul li a:hover {

background-color: #fff;

color: #000;

}

.search ul li a.one:hover {

background-color: #333;

color: #fff;

}

.login {

position: absolute;

left: 149px;

bottom: 56px;

}

.sj {

position: absolute;

left: 223px;

bottom: 48px;

z-index: 1;

}

b8706ddbfdef753efc6a410ba5064506.png

注意

标签包含规范:

div可以包含所有标签;

p标签不能包含div、h1等标签;

h1可以包含p,div等标签;

行内元素尽量包含行内元素,行内元素不要包含块元素;

规避脱标流

尽量使用标准流。

标准流解决不了的使用浮动。

浮动解决不了的使用定位。

margin-left: auto:意思就是左边自动往右边冲,直至冲不动了,所以使用该样式的会在父盒子的最右边;

body,ul {

margin: 0;

padding: 0;

}

.box {

width: 200px;

height: 200px;

background-color: red;

margin: 0 auto;

}

.nav {

width: 50px;

height: 30px;

background-color: aliceblue;

margin-left: auto;

}

6094e7c66841b8dcf7ddb80cd9487639.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值