CSS 面試題

  1. Margin:
    margin: top right bottom left (margin: 25px 50px 75px 100px;)
    margin: top right_and_left bottom( margin: 25px 50px 75px;)
    margin: top_bottom right_left (margin: 25px 50px;)
    margin: top_bottom_right_left (margin: 25px;)

    margin: 0 auto (0 for top and bottom margin, and left and right margin should be equal)

  2. Position property:
    static: default value. Elements render in order, as they appear in the document flow. Not effected by the top, bottom, left, right and z-index properties.

    relative: relative behaves the same as static unless you add some extra properties. Set the top, right, bottom and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.

    fixed: positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used.

    absolute: it behaves like fixed except relative to the nearest positioned ancestor instead of relative to the viewport. If an absolutely positioned element has no positioned ancestors, it uses the document body, and still moves along with page scrolling. Absolute positioned elements are removed from the normal flow, which means it can be overlapped by other elements.

    sticky: a hybrid of relative and fixed positioning. The element is treated as relative positioned until it crosses a specified threshold, at which point it is treated as fixed positioned.
    eg. #sample{position: sticky; top: 10px;}
    The sample element will behave just like a relatively positioned element until the viewport scrolls such that the element would be less than 10px from the top. Then. it will be fixed to 10px from the top until the view port is scrolled back past this threshold.

  3. Float:
    The elements after the floating element will flow around it. The elements before the floating element will not be affected. If a image is floated to the right, a following text flows around it, to the left.

  4. Avoid visual differences in different browsers
    Reset the body margin and padding at the very first of the css style sheet:
    *{margin:0; padding:0}

  5. Combinators in CSS3:
    Combinator: explains the relationship between the selectors.
    Descendant selector: matches all elements that are descendants of a specified element.
    div p{ color:black;} (All p in the div)
    Child selector: selects all elements that are the immediate children of a specified element.
    div > p{...}
    Adjacent sibling selector: selects all elements that are the adjacent siblings of a element. Adjacent means the immediately following.
    div + p{...}
    General sibling selector: selects all elements that are siblings of a specified element.
    div ~ p{...}

  6. Pseudo-class
    Used to define a special state of an element. eg. a:hover{...} means do the set when hover over the link.

  7. Pseudo-element
    Used to style specified parts of an element. eg. p::first-letter{...}
    p::after, insert after the content of each <p> element
    p::before, insert before the content of each<p> element
    p::first-letter, selects the first letter of each <p> element
    p::first-line, selects the first line of each <p> element
    p::selection, selects the portion of an element that is selected by a user

  8. Text-align
    Justify, each line is stretched so that every line has equal width, and the left and right margins are straight.

  9. Box model
    margin,border,padding,content

  10. Box-sizing
    content-box:default. The width and height properties includes only the content.
    border-box:the width and height properties includes content, padding and border.

  11. IE, firefox render the box model
    Firefox and other standards compliant browsers will add the size of the padding to the width or height of the box, while IE will place the padding inside of the box without adjusting the width or height.
    Solution: Place one element inside of a container, where container does not have any padding but has a width defined, and the inside element does have padding defined

  12. CSS Specificity:
    Specificity means a browser decides which property values are the most relevant to an element and gets to be applied. CSS styles follow an order of specificity. It specifies when styles override another or take precedence.
    (1). Inline css is higher than <style> tag
    (2). <style> tag is higher than css introduced by the <link> tag
    (3). Id selector is higher than class and then higher than tag name
    (4). Tow color properties in the same curly brakets, the later one will override the previous one.
    (5). You can use "!important" statement to make the highest priority specificity.
    (6). Inherited css has the lowest priority.(Inherited property uses the property value from its parent property)

  13. CSS reset:
    A CSS Reset is a short, compressed set of CSS rules that resets the styling of all HTML elements to a consist baseline. Using a CSS RESET, css authors can force every browser to have all its styles reset to null, thus avoiding cross-browser differences as much as possible.

  14. CSS Performances:
    repaint: it occurs when changes are made to an element skin that changes visibility, but do not affect its layout.(eg. outline, visibility, background color)

    reflow: it involves changes that affect the layout of a portion of the page. It is expensive and will slow the performance because most of the time it means to re-render the whole page. Resize window, change font, add or remove a stylesheet, content changes, activation of CSS pseudo classes and many more will cause the reflow.

  15. Flex
    It specifies the length of the item, relative to the rest of the flexible tiems inside the same container. The flex property is a shorthand for the flex-grow, flex-shrink, and flex-basis properties. If the element is not a flexible item, the flex property has no effect.(display:flex)

  16. Background image size:
    Before CSS3, the size was determined by the actual size of the image. In CSS3, it is possible to specify the size of the background image, which allows us to reuse background images in different contexts.

  17. CSS3 web fonts:the @font-face rule
    Web fonts allow developers to use fonts that are not installed on the user's computer. When you have found/bought the font you wich to use, just include the font file on your web server, and it will be automatically downloaded to the user when needed.
    @font-face {font-family: myFirstFont; src: url(sansation_light.woff);}
    div{font-family: myFirstFont;}

  18. @import:
    The @import CSS at-rule allows to import style rules from other style sheets
    eg. @import url;
    @import url list-of-media-queries;
    The @import can make your css code clearer, however, it slows down your application spped because it causes files to load sequentially instead of in parallel. This wastes times and round trips and makes your web page load slower. You can use a stylesheet link to avoid the @import

  19. Image Sprites
    It is a collection of images put into a single image.
    An web page with many images can take a long time to load and generates multiple server requests. With image sprites, it will reduce the number of server requests and save badnwidth. And you can use the width, height and other properties to choose a part of the combined image to form the needed image.

  20. Optimize css:
    (1). No more than one external CSS stylesheet
    (2). Inline small CSS into HTML using style tags for above the fold content
    (3). No @IMPORT CALLS FOR CSS

  21. CSS3 @media query
    With a @media query, you can write different CSS code for different media types to make your webpage responsive.

  22. Use CSS to hide HTML element:
    (1) visibility: hidden
    (2) opacity: 0
    (3) display:none
    (4) position:absolute, then adjust the top, left, bottom, right properties

  23. CSS overflow:
    It specifies what happens if content overlfows an element's box:
    visiable, hidden, scroll, auto, initial, inherit

  24. What is meant by cascade in CSS
    The cascade is a fundamental feature of CSS. It is an algorithm defining how to combine properties values originating from different sources. It defines the order of precedence for how conflicting styles should be applied

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末家卖,一起剝皮案震驚了整個濱河市智嚷,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌匀谣,老刑警劉巖迂尝,帶你破解...
    沈念sama閱讀 219,188評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件嘉熊,死亡現(xiàn)場離奇詭異陈惰,居然都是意外死亡北专,警方通過查閱死者的電腦和手機禀挫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,464評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來拓颓,“玉大人语婴,你說我怎么就攤上這事∈荒溃” “怎么了砰左?”我有些...
    開封第一講書人閱讀 165,562評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長场航。 經(jīng)常有香客問我缠导,道長,這世上最難降的妖魔是什么溉痢? 我笑而不...
    開封第一講書人閱讀 58,893評論 1 295
  • 正文 為了忘掉前任僻造,我火速辦了婚禮,結(jié)果婚禮上孩饼,老公的妹妹穿的比我還像新娘髓削。我一直安慰自己,他們只是感情好镀娶,可當(dāng)我...
    茶點故事閱讀 67,917評論 6 392
  • 文/花漫 我一把揭開白布立膛。 她就那樣靜靜地躺著,像睡著了一般汽畴。 火紅的嫁衣襯著肌膚如雪旧巾。 梳的紋絲不亂的頭發(fā)上耸序,一...
    開封第一講書人閱讀 51,708評論 1 305
  • 那天,我揣著相機與錄音鲁猩,去河邊找鬼坎怪。 笑死,一個胖子當(dāng)著我的面吹牛廓握,可吹牛的內(nèi)容都是我干的搅窿。 我是一名探鬼主播,決...
    沈念sama閱讀 40,430評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼隙券,長吁一口氣:“原來是場噩夢啊……” “哼男应!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起娱仔,我...
    開封第一講書人閱讀 39,342評論 0 276
  • 序言:老撾萬榮一對情侶失蹤沐飘,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后牲迫,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體耐朴,經(jīng)...
    沈念sama閱讀 45,801評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,976評論 3 337
  • 正文 我和宋清朗相戀三年盹憎,在試婚紗的時候發(fā)現(xiàn)自己被綠了筛峭。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,115評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡陪每,死狀恐怖影晓,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情檩禾,我是刑警寧澤挂签,帶...
    沈念sama閱讀 35,804評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站锌订,受9級特大地震影響竹握,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜辆飘,卻給世界環(huán)境...
    茶點故事閱讀 41,458評論 3 331
  • 文/蒙蒙 一啦辐、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧蜈项,春花似錦芹关、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,008評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春轴总,著一層夾襖步出監(jiān)牢的瞬間直颅,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,135評論 1 272
  • 我被黑心中介騙來泰國打工怀樟, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留功偿,地道東北人。 一個月前我還...
    沈念sama閱讀 48,365評論 3 373
  • 正文 我出身青樓往堡,卻偏偏與公主長得像械荷,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子虑灰,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,055評論 2 355

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,511評論 0 23
  • 三青w閱讀 558評論 0 2
  • logstash 它一個有jruby語言編寫的運行在java虛擬機上的具有收集分析轉(zhuǎn)發(fā)數(shù)據(jù)流功能的工具 能集中處理...
    bdslinux閱讀 3,138評論 0 1
  • 敬篤 春天吨瞎,與風(fēng)有關(guān)的日子,讓我沉醉在一種干涸之中穆咐。我開始理解颤诀,這個季節(jié)的詭辯。 時間像一只白鶴对湃,延續(xù)著某種生命的...
    山谷小道士閱讀 318評論 1 3
  • 從小着绊,很多次想過,讓自己快點長大熟尉!不知道怎么的,仿佛曾經(jīng)的時光不屬于自己一般洲脂,就到了人生的三十歲斤儿!從大學(xué)畢業(yè)后,我...
    天使姑涼閱讀 184評論 0 0