css 宽度高度等于宽度
The height and width properties allow you to set the height and width properties of an element.
height和width属性使您可以设置元素的height和width属性 。
Height and width properties are crucial for any website because it helps in making the websites more space-efficient and further adds more to the styles of the site as well.
高度和宽度属性对于任何网站都是至关重要的,因为它有助于使网站更节省空间,并进一步增加网站的样式。
The height and width properties do not include any padding, margins or borders instead they influence the padding, margins, and borders of the element.
height和width属性不包含任何padding , margin或border,它们会影响元素的padding,margin和borders。
Syntax:
句法:
Element{
height: 200px/60%
width: 200px/70%
}
Example:
例:
<!DOCTYPE html>
<title>heading</title>
<style>
div {
height: 200px;
width: 60%;
background-color: lightblue;
}
</style>
<div>
The div has height and weight property.
</div>
Output
输出量
The div has height and weight property.
div具有height和weight属性。
The height and width may have the following set of values:
高度和宽度可以具有以下一组值:
auto - This is a default value. The browser itself calculates the height and width
自动 -这是默认值。 浏览器本身会计算高度和宽度
length -It helps in defining the height/width in px, cm, etc
长度 -有助于定义以px,cm等为单位的高度/宽度
% - It helps in defining the height/width in percent of the containing block
% -它有助于定义包含块的百分比的高度/宽度
initial - This sets the height/width to its default value
初始 -将高度/宽度设置为其默认值
inherit - The height and width will be inherited from its parent value
继承 -高度和宽度将从其父值继承
Setting the max-width and max-height:
设置最大宽度和最大高度:
The max-width and max-height properties are used to set the maximum width and height of an element.
max-width和max-height属性用于设置元素的最大宽度和高度。
The properties can be specified into px, cm or percent.
可以将属性指定为px,cm或百分比。
Using max-width and max-height the browser with small windows can be handled more neatly.
使用max-width和max-height ,可以更轻松地处理带有小窗口的浏览器。
Example:
例:
<!DOCTYPE html>
<title>heading</title>
<style>
div {
max-height: 100px;
max-width: 95px;
background-color: green;
}
</style>
<div>
The div has 'max-height' and 'max-width' applied.
</div>
Output:
输出:
The div has 'max-height' and 'max-width' applied.
div应用了“最大高度”和“最大宽度”。
Setting the min-width and min-height
设置最小宽度和最小高度
It helps in constraining the width and height of an element to a minimum value.
它有助于将元素的宽度和高度限制为最小值。
Example:
例:
<!DOCTYPE html>
<title>heading</title>
<style>
div {
min-height: 390px;
min-width: 95px;
background-color: red;
}
</style>
<div>
The div has 'min-height' and 'min-width' applied.
</div>
Output
输出量
The div has 'min-height' and 'min-width' applied.
div应用了“最小高度”和“最小宽度”。
Some CSS dimension properties
一些CSS尺寸属性
Property | Description |
---|---|
height | Sets the height of an element |
min-height | Sets the minimum height of an element |
max-height | Sets the maximum height of an element |
width | Sets the width of an element |
max-width | Sets the maximum width of an element |
min-width | Sets the minimum width of an element |
属性 | 描述 |
---|---|
高度 | 设置元素的高度 |
最小高度 | 设置元素的最小高度 |
最大高度 | 设置元素的最大高度 |
宽度 | 设置元素的宽度 |
最大宽度 | 设置元素的最大宽度 |
最小宽度 | 设置元素的最小宽度 |
翻译自: https://www.includehelp.com/code-snippets/height-and-width-in-css.aspx
css 宽度高度等于宽度