css如何设置div居左 居中和居右

html-css05

css如何设置div居左 居中和居右,第1张

<style>

div {position:absolute width:200px height:400px}

div.left {left:0 background-color:red}

div.center {left:50% margin-left:-100px background-color:green}

div.right {right:0 background-color:blue}

</style>

<div class="left">左</div>

<div class="center">中</div>

<div class="right">右</div>

看了下 你这个css 感觉不是很好 首先 如果想左右靠边的话 用float好些 然后你设置的width 100% 应该就是填满了父元素了 所以不需要靠边 然后绝对定位 position没有加 left 什么的属性是不会起作用的,padding 100%这个很容易出问题,因为这个100%对应的是 父元素的宽度,需要注意下,看样子 你是想弄个 填满父元素的 div然后设置背景,你查下 父元素的属性吧 估计padding什么的属性干扰了

#left {

height: 200px

width: 200px

border-left-width: 1px

border-left-style: solid

border-left-color: #FF0000

}