How to display an image next to some texts

2019-01-20 19:57发布

问题:

I am trying to achieve the following:

The DIVS are divided in three section and once reaching a certain screen size, I want them to stack on top of another using Media Queries.

Here is the HTML (disregard inline CSS, i will be moving it to a file once I have it working):

<div class="col span_1_of_3" style="height: 150px;">
    <div class="test2n" style="height: 100%;">
        <div style="float: left; displat: inline-block; width: 28% padding-right: 2%; height: 100%;"><img id="NewsArticle_2790_image" class="imgArtThumb" title="The Com" alt="The Com" src="tOne.png?n=5350" /></div>
        <div style="float: left; display: inline-block; width: 58%; height: 100%;">
            <div style="width: 100%; height: 48%; padding-bottom: 2%; text-align: left;"><a href="/template.aspx?id=2790">How we can better develop</a></div>
            <div style="width: 100%; height: 48%; overflow: hidden; text-overflow: ellipses; white-space: nowrap; text-align: left">TThis DIV will have a long text but anything that doesn't fit the set dimension will end with a "..."</div>
        </div>
    </div>
</div>
<div class="col span_1_of_3" style="height: 150px;">
    <div class="test2n" style="height: 100%;">
        <div style="float: left; displat: inline-block; width: 28% padding-right: 2%; height: 100%;"><img id="NewsArticle_2790_image" class="imgArtThumb" title="The Com" alt="The Com" src="tOne.png?n=5350" /></div>
        <div style="float: left; display: inline-block; width: 58%; height: 100%;">
            <div style="width: 100%; height: 48%; padding-bottom: 2%; text-align: left;"><a href="/template.aspx?id=2790">How we can better develop</a></div>
            <div style="width: 100%; height: 48%; overflow: hidden; text-overflow: ellipses; white-space: nowrap; text-align: left">TThis DIV will have a long text but anything that doesn't fit the set dimension will end with a "..."</div>
        </div>
    </div>
</div>
<div class="col span_1_of_3" style="height: 150px;">
    <div class="test2n" style="height: 100%;">
        <div style="float: left; displat: inline-block; width: 28% padding-right: 2%; height: 100%;"><img id="NewsArticle_2790_image" class="imgArtThumb" title="The Com" alt="The Com" src="tOne.png?n=5350" /></div>
        <div style="float: left; display: inline-block; width: 58%; height: 100%;">
            <div style="width: 100%; height: 48%; padding-bottom: 2%; text-align: left;"><a href="/template.aspx?id=2790">How we can better develop</a></div>
            <div style="width: 100%; height: 48%; overflow: hidden; text-overflow: ellipses; white-space: nowrap; text-align: left">TThis DIV will have a long text but anything that doesn't fit the set dimension will end with a "..."</div>
        </div>
    </div>
</div>

CSS:

.imgArtThumb
{
    width: 155px;
    height: 100px;
}
.test2n
{
    text-align: left;
    box-shadow: inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(238,146,85,1);
}
.test2 p, .test2n p
{
    text-align: left;
}
/*  COLUMN SETUP  */
.col {
    display: block;
    /*float:left;*/
    display: inline-block;
    margin: 1% 0 1% 0;
}
.col:first-child {
    margin-left: 0;
}
.span_1_of_3 {
    width: 32.2%;
}
@media only screen and (max-width: 825px) {
    .col { 
        margin: 1% 0 1% 0%;
    }
}

@media only screen and (max-width: 825px) {
    .span_3_of_3 {
        width: 100%; 
    }
    .span_2_of_3 {
        width: 100%; 
    }
    .span_1_of_3 {
        width: 98%;
    }
}

Here is the JSFiddle: http://jsfiddle.net/ofrj55j4/1/

Updated JSFiddle with max-width set to 90%: http://jsfiddle.net/ofrj55j4/6/

How to I make it so that the image is centered on the left vertically and the top right title link should take up 50% and the description on bottom right take up 50%. For the description I would like to have the ellipses if it exceeds the dimension.

UPDATE: I got everything working except the ellipses. Why doesn't fill out the entire DIV before using the ellipses? JSFiddle: http://jsfiddle.net/ofrj55j4/19/

回答1:

Maybe it is just a typo you entered here on the site...your divs that contain the image are set to displat: inline-block instead of display



回答2:

To get an image to stack on top of each other you have to specify it by removing the floats.

Using "clear:both;" will remove the floats will stack them, and then you can adjust the size using margins, padding, width, and height to get a perfect box.