简体   繁体   English

CSS如何改变父元素的溢出?

[英]CSS how to change overflow of parent element?

How can i place div on an img element? 如何将div放在img元素上? Also i would like to do it slightly outside. 我也想在外面做一点。

I have something like this: 我有这样的事情:

<div class="slide">
    <div class="arrow">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer scelerisque ex eget ultricies blandit.</p>
    </div>
    <img src="http://boallen.com/assets/images/randbitmap_true.png">
</div>

And here is my css style: 这是我的CSS样式:

    .arrow {
        max-width: 300px;
        background-color: #FAFAFA;
        position: absolute;
    }
    .arrow:after {
        left: 100%;
        bottom: 0px;
        content: " ";
        height: 0;
        width: 0;
        position: absolute;
        pointer-events: none;
        border-width: 15px;
        border-bottom: 30px solid #FAFAFA;
        border-right: 30px solid transparent;
    }

So how can i do this? 那我该怎么办呢? to place my arrow div on an image slightly outside? 将我的箭头div放在稍微外面的图像上? and i don't want to set the image as background i need it to be in the img tag. 而且我不想将图像设置为背景,我需要将其放置在img标签中。

@update @更新

keep in minde i dont want to change style of .slide element. 请记住,我不想更改.slide元素的样式。 and i have overflow: hidden; 而且我有overflow: hidden; so how to make my arrow element to not be hidden ? 那么如何使我的arrow元素不被隐藏?

check it here: http://jsfiddle.net/pyx3zx25/9/ 在这里检查: http : //jsfiddle.net/pyx3zx25/9/

how to change overflow of parent element? 如何更改父元素的溢出?

You have given position absolute to the arrow div. 您已将绝对位置赋予了箭头div。 when you give top and left value to that; 当您为之赋予最高和最低价值时; you can position it any where on the image. 您可以将其放置在图像上的任何位置。 try the below value,the div with text come inside the image,adjust the values according to your need. 尝试以下值,带有div的文本会出现在图像中,请根据需要调整值。

.arrow {
            max-width: 300px;
            background-color: #FAFAFA;
            position: absolute;
            top:200px;
            left:100px;
}

you can add top:10px; 您可以添加top:10px; left:0px; 左:0px; i think those values will give you desired result 我认为这些价值观会给您想要的结果

Just use the 'negative value' on top and left. 只需在顶部和左侧使用“负值”即可。

  .arrow { max-width: 300px; background-color: #FAFAFA; position: absolute; top:-10px; left:-10px; } 

You can try it. 你可以试试。

    .slide{
        position: relative;
        height: 521px;
        width: 521px;
    }

   .arrow {
            max-width: 300px;
            background-color: #FAFAFA;
            position: absolute;
            top:40%;
            left:20%;

    }

Update 更新资料

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

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