简体   繁体   English

CSS-如何设置与邻居图像相同的绝对div高度?

[英]CSS - How to set height of absolute div same with neighbor image?

在此处输入图片说明

I got two DOM elements in (A) relatively positioned <div> 我在(A)中有两个相对位置<div> DOM元素

One of them is (B) responsive image and the other is (C) absolutely positioned <div> 其中一个是(B)响应图像,另一个是(C)绝对定位<div>

I'd like to set (C)'s height same with (B)'s height to align (C)'s content vertically centered in (A) 我想将(C)的高度设置为与(B)的高度相同,以使(C)的内容垂直居中于(A)

Here is JSFiddle code 这是JSFiddle代码

I'd like to find method which uses CSS only , not the javascript. 我想查找使用CSS而不使用javascript的方法。

you have given teh height 100px and width 100% . 您已给定height 100pxwidth 100% But the height must be 100% and i give the width 60%. 但高度必须为100%,而我给宽度为60%。 And to get center the div i give left 20%. 为了获得中心的div,我给了20%。 Because width = 60% left = 20% and right 20% then 60% + 20% + 20% = 100% 因为宽度= 60%,左边= 20%,右边20%,则60%+ 20%+ 20%= 100%

This is the fiddle 这是小提琴

http://jsfiddle.net/avrkmhfq/1/ http://jsfiddle.net/avrkmhfq/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM