【codecademy summary】html+css layout

The default position of an element can be chagned by setting its position property. 

values:

  static: the default value.

  relative: this value allows you to position an element relative to its default position the web page with four offset properties: top / bottom / left / right. Offset properties will not work if the position of the element is not set to relative.

  absolute: all other elements on the page will ignore the element and act like it is not present on the page. When an element's position is set to absolute, the element can still scroll out of view when a user scrolls.

  fix: the div will remain fixed to its position no matter where the user scrolls on the page. This technique is used often for navigation bars on a web page. But it is still possible to overlap other content. One solution is to set an opaque background color for the element.

 

-------------------------------------------------------------------------------------------------------------------

 

exmaple:

  div.exmaple{

    position: fixed;

    background-color: #FFFFFF;

    height:50px;

    width: 100%;

  }

 

-------------------------------------------------------------------------------------------------------------------

 z-index

  z-index property controls how far "back" or how far "forward" an element should on the web page. It accepts integer values. Deoending on their values, the integers instruct the browser on the order in which elements should be displayed on the web page. Setting the z-index of navigation to a number greater than 0 is sufficient to prevent overlapping content.

 

-------------------------------------------------------------------------------------------------------------------

 

exmaple:

  div.exmaple{

    position: fixed;

    background-color: #FFFFFF;

    height:50px;

    width: 100%;

    z-index: 1;

  }

 

-------------------------------------------------------------------------------------------------------------------

float

  If we want to move an element as far left ot as right as possible on the page, we can use float.

  1. float: left - this value will move, or float, elements as far left as possible.

  2. float: right - this value will move elements as far right as possible. 

  When an element is floated, any other content within the same containing element will naturally fow around the element. Floated elements must have a width specified, as in the example above. Otherwise, the element will assume the full width of its containing element, and attempting to float the element mat not yield any visible results.

-------------------------------------------------------------------------------------------------------------------

 

exmaple:

  div.block{

    width: 10px;

    floatL left;

  }  

 

-------------------------------------------------------------------------------------------------------------------

clear

  The float property can also be used to float multiple elements at once. When multiple floated elements have different heights, however, this can affect their layout on the page. Specifically, elemets can "bump" into each other and not allow other elements to properly move the left or or the right.

  The clear property specifies how elements should behave when they bump into each other on the page. It can take on one of the following values:

  left - the left side of the element will not touch ant other element within the same containing element.

  right - the rifht side of the element will not touch ant other element within the same containing element.

  both - the element can touch either side.

  none - the element can touch either side.

-------------------------------------------------------------------------------------------------------------------

example:

  div { 

    width: 200px;

    float: left;

  }

  

  div.special {

    clear : left;

  }

转载于:https://www.cnblogs.com/guangluwutu/p/6606220.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值