CSSの幅と高さのプロパティ
高さと幅は要素のコンテンツ専用に定義できますが、これらのプロパティには余白、パディング、境界線は含まれていません。
構文
CSSのheightプロパティの構文は次のとおりです-
Selector {
height: /*value*/
} CSSwidthプロパティの構文は次のとおりです-
Selector {
width: /*value*/
} 幅と高さのプロパティの例を見てみましょう-
例
<!DOCTYPE html>
<html>
<head>
<title>CSS height and width</title>
</head>
<style>
* {
padding: 2px;
margin:5px;
}
button {
border-radius: 10px;
}
#containerDiv {
width:70%;
margin: 0 auto;
padding:20px;
background-image: linear-gradient(62deg, #fbab7e 0%, #f7ce68 100%);
text-align: center;
border-radius: 10px;
}
#contentDiv2{
width:200px;
height: 200px;
opacity: .5;
border:1px solid black;
}
</style>
<body>
<div id="containerDiv">
<div id="contentDiv1">
This is paragraph 1 with some dummy text.
</div>
<div id="contentDiv2">
This is paragraph 2 with some dummy text.
</div>
</div>
<script>
</script>
</body>
</html> 出力
幅と高さのプロパティの別の例を見てみましょう-
例
<!DOCTYPE html>
<html>
<head>
<title>CSS height and width</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
#containerDiv {
margin: 0 auto;
height: 150px;
width:250px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>CSS height and width</legend>
<div id="containerDiv">
<img id="image" src="https://www.tutorialspoint.com/tensorflow/images/tensorflow-mini-logo.jpg">
</div>
</fieldset>
</form>
</body>
</html> 出力
-
CSSの要素の幅と高さ
CSSのheightプロパティとwidthプロパティは、要素の高さと幅をそれぞれ指定するために使用されます。 max-height、max-width、min-height、およびmin-widthプロパティを使用して、これらのプロパティの最大値と最小値を設定することもできます。 構文 CSSの高さとCSSの幅のプロパティの構文は次のとおりです- Selector { height: /*value*/ width: /*value*/ } 要素の実際の幅と高さは次のように計算されます- ボックスサイズ 計算 全幅 幅+パディン
-
CSSでパーセンテージとEmの組み合わせを使用する
フォントの互換性を高めるために、パーセンテージとemの組み合わせを使用して、要素のフォントサイズを指定できます。これにより、さまざまなブラウザ間でテキストを統一できます。 構文 CSSfont-sizeプロパティの構文は次のとおりです- Selector { font-size: /*value*/ } 例 次の例は、CSSのfont-sizeプロパティをキーワード-で設定する方法を示しています。 <!DOCTYPE html> <html> <head> <style> body { fo