CSSディメンションのプロパティ
CSSの幅、高さ、最大高さなどのいくつかのプロパティを使用すると、ユーザーは要素コンテンツボックスのサイズを制御できます。
CSSのmax-heightプロパティの例を見てみましょう-
例
<!DOCTYPE html>
<html>
<head>
<title>CSS max-height</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
#containerDiv {
margin: 0 auto;
max-height: 150px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>CSS max-height</legend>
<div id="containerDiv">
<img id="image" src="https://www.tutorialspoint.com/machine_learning_with_python/images/machine-learning-with-python-mini-logo.jpg">
</div>
</fieldset>
</form>
</body>
</html> 出力
最大高さが定義される前-
最大高さが定義された後-
CSSのmin-widthプロパティの別の例を見てみましょう-
例
<!DOCTYPE html>
<html>
<head>
<title>CSS min-width Property</title>
</head>
<style>
* {
padding: 2px;
margin:5px;
}
button {
border-radius: 10px;
}
#containerDiv {
width:70%;
margin: 0 auto;
padding:20px;
background-image: linear-gradient(135deg, #dc3545 0%, #9599E2 100%);
text-align: center;
border-radius: 10px;
}
.contentDiv{
min-width:200px;
border: 1px solid black;
}
</style>
<body>
<div id="containerDiv">
<div class="contentDiv">
This is paragraph 1 with some dummy text.
</div>
<div class="contentDiv">
This is paragraph 2 with some dummy text.
</div>
<div class="contentDiv">
This is paragraph 2 with some dummy text.
</div>
<button onclick="add()" class="btn">Set minWidth</button>
</div>
<script>
function add() {
document.querySelectorAll('.contentDiv')[1].style.minWidth = "100%";
}
</script>
</body>
</html> 出力
[minWidthの設定]をクリックする前に ボタン-
[minWidthの設定]をクリックした後 ボタン-
-
CSSマージンプロパティ
CSSマージンプロパティは、margin-top、margin-right、margin-bottom、およびmargin-leftの省略形です。これにより、要素の周囲のスペースを指定できます。個々の辺にマージンを設定することもできます。 構文 CSSマージンプロパティの構文は次のとおりです- Selector { margin: /*value*/ } 例 次の例は、CSSマージンプロパティ-を示しています。 <!DOCTYPE html> <html> <head> <style> div { &n
-
CSSのclientHeight、offsetHeight、scrollHeightプロパティを理解する
clientHeight clientHeightは、パディングを含む要素の高さの尺度を示します。境界線、マージン、およびスクロールバーの高さ(再調整されている場合)はこれに含まれないことに注意してください。 offsetHeight offsetHeightは、垂直方向のパディング、上下の境界線を含む要素の高さの尺度を示します。マージンはここに含まれていません。 scrollHeight scrollHeightは、垂直方向のパディングと、オーバーフロープロパティのために画面に表示されないコンテンツを含む要素の高さの測定値を示します。 次の例は、clientHeight、o