(CSS) How position text (with background color) ov

2019-02-28 06:27发布

As the title says

my code is something like this :

<div class=container> <img/> <div>some text with line one, line two , line three </div> </div>

the container should have overflow:hidden and my text would be in more than one line , so I need only a small part of my text to appear at the bottom of container, so when user hovers, the full text appears.

I want to position text over img WITHOUT absolute positioning. I tried negative margins, but text wouldn't have BG color there. Also tried Relative pos. => works great but not on chance on IE.

here is an image of what I want enter image description here

2条回答
够拽才男人
2楼-- · 2019-02-28 06:52

position:relative solves your problem

查看更多
混吃等死
3楼-- · 2019-02-28 07:06

I see no reason not to use position: absolute.

See: http://jsfiddle.net/NeaR4/

CSS:

.container {
    border: 2px dashed #444;
    float: left;
    position: relative
}
.container img {
    display: block
}
.container > div {
    position: absolute;
    left: 0;
    bottom: 0;
    right: 0;
    height: 14px;
    background: #000;
    background: rgba(0,0,0,0.7);
    color: #fff;
    overflow: hidden;
    font: bold 14px Arial, sans-serif;
    padding: 5px;
}
.container:hover > div {
    height: auto
}

HTML:

<div class="container">
    <img src="http://dummyimage.com/230x180/f0f/fff" />
    <div>some text with line oneeee, line twoooooooo ooooooo , line three</div>
</div>
查看更多
登录 后发表回答