绝对定位与相对定位为什么没区别_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:52:41
原创
1374人浏览过

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css">#box_relative {	position: absolute;	left: 30px	top: 192px;	width: 800px;	height: 100px;	background-color: #00F;	left: 95px;	top: 253px;}#box01 {	position: absolute;	left: 72px;	top: 50px;	width: 300px;	height: 20px;	background-color: #000;	z-index: 1;}#box02 {	position:relative;	top: 103px;	width: 300px;	height: 20px;	background-color:#0F0;	margin-left:100px;}#box03 {	position:relative;	top: 103px;	width: 300px;	height: 20px;	background-color:#600;	margin-left:auto;	margin-right:auto;}#box06 {	position:relative;	width: 800px;	height: 100px;	background-color: #F39;	top: 619px;	margin-left:auto;	margin-right:auto;	z-index: -1;}#box07 {	position:relative;	width: 300px;	height: 30px;	background-color:#0F0;	left:30px;}#box08 {	position: absolute;	top: 46px;	width: 300px;	height: 30px;	background-color: #0F0;	margin-left: auto;	margin-right: auto;	left: 30px;}</style></head><body><div id="box03">        1111        </div><div id="box_relative">                <div id="box01">        1111        </div>                     <div id="box02">        1111        </div>        </div><div id="box06">         <div id="box07">        1111        </div>                 <div id="box08">        1111        </div>        </div></body></html>
登录后复制



<div id="box06">         <div id="box07">        1111        </div>                 <div id="box08">        1111        </div>        </div>
登录后复制


#box07 {	position:relative;	width: 300px;	height: 30px;	background-color:#0F0;	left:30px;}#box08 {	position: absolute;	top: 46px;	width: 300px;	height: 30px;	background-color: #0F0;	margin-left: auto;	margin-right: auto;	left: 30px;}
登录后复制


1、box07使用相对定位,box08使用绝对定位,为什么效果是一样的?

2、请问如果想让box06在页面扩大或者缩小都居中,box07 也居中

box08一直距离左边30px

并且box07与box08都在box06中,怎么做?

标书对比王
标书对比王

标书对比王是一款标书查重工具,支持多份投标文件两两相互比对,重复内容高亮标记,可快速定位重复内容原文所在位置,并可导出比对报告。

标书对比王 58
查看详情 标书对比王

回复讨论(解决方案)

1、box07使用相对定位,box08使用绝对定位,为什么效果是一样的?

都相距box06左边30px

都在div的id都在box06内,怎么才能在页面扩大或者缩小是不一样?

2、请问如果想让box06在页面扩大或者缩小都居中,box07 也居中

box08一直距离页面左边30px 怎么做

并且box07与box08都在box06中,怎么做?

<style type="text/css">#box06 {    position:relative;    width: 500px;    height: 100px;  top:50%;  left:50%;  margin-left:-250px;  margin-top:-50px;    background-color:#F39;} #box07 {    position:absolute;    width: 300px;    height: 30px;    background-color:#0F0;    left:50%;  top:50%;  margin-left:-150px;  margin-top:-15px;} #box08 {    position:absolute;    width: 300px;    height: 30px;    background-color:#0Ff;    left:30px;  top:50%;}</style><div id="box06">  <div id="box07">box07</div>  <div id="box08">box08</div></div>
登录后复制



box07与box08还是一起动,我希望在缩小的页面时,他们距离左边的位置一样,但是放大页面的,距离左边的位置就不一样了



box07与box08还是一起动,我希望在缩小的页面时,他们距离左边的位置一样,但是放大页面的,距离左边的位置就不一样了


在一个相对左边的定位下,放大和缩小页面有什么区别呢?
如果不考虑怎么定位 
你希望在页面多大的情况下  是什么状态
有几种大小情况  几种状态
这个叙述清楚了 我们来看下  用什么方式定位

我表示有点头晕,,,,

父级用position:relative;
子级用position:absolute;

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号