--- title: object-position slug: Web/CSS/object-position tags: - CSS - CSS Image - CSS Property - Reference translation_of: Web/CSS/object-position ---
object-position
プロパティは、ボックス内における置換要素の配置を指定します。Areas of the box which aren't covered by the replaced element's object will show the element's background.
You can adjust how the replaced element's object's intrinsic size (that is, its natural size) is adjusted to fit within the element's box using the {{cssxref("object-fit")}} property.
{{cssinfo}}
/* <position> 値 */ object-position: center top; object-position: 100px 50px; /* グローバル値 */ object-position: inherit; object-position: initial; object-position: unset;
<position>
注: 要素がボックス外にはみ出る位置も指定できます。
<img id="object-position-1" src="https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png" alt="MDN Logo"/> <img id="object-position-2" src="https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png" alt="MDN Logo"/>
img { width: 150px; height: 100px; border: 1px solid #000; background-color: yellow; margin-right: 1em; } #object-position-1 { object-position: 10px; } #object-position-2 { object-position: 20% 10%; }
The first image is positioned with its left edge inset 10 pixels from the left edge of the element's box. The second image is positioned with its right edge flush against the right edge of the element's box and is located 10% of the way down the height of the element's box.
{{EmbedLiveSample('Example', '100%','300px' )}}
仕様書 | 策定状況 | コメント |
---|---|---|
{{SpecName('CSS4 Images', '#the-object-position', 'object-position')}} | {{Spec2('CSS4 Images')}} | |
{{SpecName('CSS3 Images', '#the-object-position', 'object-position')}} | {{Spec2('CSS3 Images')}} | 最初期の定義 |
{{Compat("css.properties.object-position")}}