css div撑满窗口高度_如何使用CSS将div的高度设置为窗口的100%?
css div撐滿窗口高度
Introduction:
介紹:
Hello there developers! Well, certainly if you are reading this article then that means that you have run into some trouble while creating your web page or website and if you are a beginner in this field, then there is no better place than this. So let us get started without further adieu. But before we can proceed forward with this article it is crucial to know that what are divs and what could be their possible uses.
您好,開發(fā)人員! 好吧,當(dāng)然,如果您正在閱讀本文,那么這意味著您在創(chuàng)建網(wǎng)頁(yè)或網(wǎng)站時(shí)遇到了麻煩,并且如果您是該領(lǐng)域的初學(xué)者,那么沒有比這更好的地方了。 因此,讓我們開始吧! 但是在繼續(xù)本文之前,至關(guān)重要的是要知道什么是div以及它們的可能用途。
Definition and uses:
定義和用途:
Well, divs are something that we deal with regularly while developing a web page or website, the divs are used to group lines of texts or elements and anything similar, besides divs are also used to structure the code, so that various sections remain segregated from each other. Although you can make use of section tag both of them behave pretty similarly. Besides divs also help in declaring class and ids of the various elements. Therefore, in a nutshell, it would be right to say that divs are very essential when we are developing a website or web page and divs also help in keeping our code structured.
好吧,divs是我們?cè)陂_發(fā)網(wǎng)頁(yè)或網(wǎng)站時(shí)經(jīng)常處理的事情,divs用于對(duì)文本或元素行以及類似內(nèi)容進(jìn)行分組,此外divs還用于構(gòu)造代碼,以便各個(gè)部分與彼此。 盡管您可以使用section標(biāo)簽,但它們的行為都非常相似。 除了div之外,還有助于聲明各種元素的類和ID。 因此,總的來說,當(dāng)我們開發(fā)網(wǎng)站或網(wǎng)頁(yè)時(shí),div是非常重要的,而div也有助于保持代碼的結(jié)構(gòu)化。
Solution:
解:
We have already seen by now how to set the height of the div elements using CSS height property? Now the question arises what if we want to set the height of the div 100% height of the window? here comes the answer to the solution that is using the vh property in CSS. We will discuss the vh property in detail in this article.
到目前為止,我們已經(jīng)看到了如何使用CSS height屬性設(shè)置div元素的高度? 現(xiàn)在出現(xiàn)了一個(gè)問題,如果我們想將div的高度設(shè)置為窗口高度的100%,該怎么辦? 這是使用CSS中的vh屬性的解決方案的答案。 我們將在本文中詳細(xì)討論vh屬性。
Property:
屬性:
Here, "vh" stands for "viewport-height", and the word viewport refers to the user's browser windows size. So whenever we use the vh property, the element's height is adjusted relative to the height of the viewport.
在此, “ vh”代表“ viewport-height” ,而“ viewport”一詞指的是用戶瀏覽器窗口的大小。 因此,每當(dāng)我們使用vh屬性時(shí) ,元素的高度都會(huì)相對(duì)于視口的高度進(jìn)行調(diào)整。
To set the height of div element to 100% height of the window, we can use the following syntax,
要將div元素的高度設(shè)置為窗口的100%高度 ,我們可以使用以下語法,
Syntax:
句法:
element{height:100vh;}Example:
例:
Output
輸出量
In the above example, it can be seen that by making use of the viewport-height property the height of the div element is 100% height of the window. Therefore, now you know both how to increase the height of the element as well as how to make it equivalent to 100% height of the window.
在上面的示例中,可以看到,通過使用viewport-height屬性,div元素的高度為window的100%高度 。 因此,現(xiàn)在您知道如何增加元素的高度以及如何使其等于窗口的100%高度。
This method proves to be very helpful, so just keep in mind that all you gotta do is make use of "vh" property and there you got it!
這種方法被證明是非常有用的,因此請(qǐng)記住,您要做的就是利用“ vh”屬性 ,您就已經(jīng)掌握了!
翻譯自: https://www.includehelp.com/code-snippets/how-to-set-height-of-div-to-100-percentage-height-of-window-using-css.aspx
css div撐滿窗口高度
總結(jié)
以上是生活随笔為你收集整理的css div撑满窗口高度_如何使用CSS将div的高度设置为窗口的100%?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript中带有示例的Math
- 下一篇: css禁用选中文本_使用CSS禁用文本选