Skip to main content

flexbox布局,媒体查询自适应屏幕大小,box-sizing

box-sizing的用途:防止盒子被撑大。

假设有个块元素,width和height都是200px,如果这个块元素的border是1px,那么这个时候块元素的实际宽高就是202px;假设块元素设置padding属性为1px,那么这个时候块元素的实际宽高就是204px。所以,块元素的padding和border实际都会撑大这个盒子。

要让盒子保持原来的尺寸,不受border和padding的影响的话,可以在css中加这么一句话:

* {

        box-sizing: border-box;

}

box-sizing更改默认的计算元素宽高属性值。更改为border-box后,width=content+border+padding


媒体查询自适应屏幕大小

不同的设备浏览器大小是不同的,媒体查询就是查询窗口大小动态的显示或者调整元素。

@media (min/max-width: px)

{

        元素 {

                width: px;

                height: px;

}

}

@media (prefers-reduced-motion:no-preference){* {
  scroll-behavior: smooth;
}}

flexbox布局

弹性布局方式,与常规的流式或块式布局不同。items 将会在 主轴 (main axis) 或者在 交叉轴(cross axis) 排版。

display: flex

                           

Comments

Popular posts from this blog

span[class~="sr-only"]

  The  span[class~="sr-only"]  selector will select any  span  element whose  class   includes   sr-only . Create that selector, and give it a  border  property set to  0 . span [ class ~= "sr-only" ] {    border:   0 ; }

Use Recursion to Create a Range of Numbers

  function   rangeOfNumbers ( startNum ,  endNum ) {    if ( startNum <= endNum )   {      const   arrNumber  =  rangeOfNumbers ( startNum ,  endNum - 1 );      arrNumber . push ( endNum );      return   arrNumber ;   }    else  {      return  [];   }       }; console . log ( rangeOfNumbers ( 6 , 8 ));//[6,7,8] console . log ( rangeOfNumbers ( 3 , 12 )); //[ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]

About the Little Lemon receipt maker exercise

 My homework and exercise of the lesson "About the Little Lemon receipt maker exercise" of the class "programming with Javascript" on coursera. const menu = [     {         Dish : "Italian pasta" ,         price : 9.55     },     {         Dish : "Rice with veggies" ,         price : 8.65     },     {         Dish : "Chicken with potatoes" ,         price : 15.55     },     {         Dish : "Vegetarian Pizza" ,         price : 6.45     } ]; function receiptMaker ( arr , bool ) {     if ( bool == false )     {         console . log ( "Prices without tax:" );         arr . forEach ( element => {             console . log ( `Dish: ${ element . Dish } Price (incl.tax):$ ${ element . price } ` );                     });     }     else     {         console . log ( "Prices with 20% tax:" );         arr . forEach ( element => {             console . log ( `Dish: ${ element . Dish } Price (inc