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

后端 未结 2 703
甜味超标
甜味超标 2021-01-25 05:54

As the title says

my code is something like this :

some text with line one, line two , line three <
相关标签:
2条回答
  • 2021-01-25 06:27

    position:relative solves your problem

    0 讨论(0)
  • 2021-01-25 06:37

    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>
    
    0 讨论(0)
提交回复
热议问题