display images based on browser width

后端 未结 3 427
生来不讨喜
生来不讨喜 2021-01-29 01:35

I have bunch of images that I would like to display using jquery. I have divs and I used jquery to populate the divs based on some node_id criteria. For example, if the node_id

相关标签:
3条回答
  • 2021-01-29 02:25
    <div class="tab-content" id="tabs1">
    <div id="team_A" class="team">
        <img src="http://placehold.it/500x500" />
        <img src="http://placehold.it/500x500" />
        <img src="http://placehold.it/500x500" />
    </div>
    

    CSS

    .team img{float: left;}
    
    0 讨论(0)
  • 2021-01-29 02:26

    If you can specify the width of the images, you can float them in a block-level element. For example:

    <div class="tab-content" id="tabs1">
        <div id="team_A" class="team"><img src="http://placehold.it/350x150"></div>
        <div id="team_B" class="team"><img src="http://placehold.it/350x150"></div>
        <div id="team_C" class="team"><img src="http://placehold.it/350x150"></div>
        <div id="team_D" class="team"><img src="http://placehold.it/350x150"></div>
    </div>
    

    and use the following CSS:

    .tab-content {
        padding: 0px;
        background-color: yellow;
        overflow: auto;
    }
    .team {
        float: left;
        margin: 0 5px 5px 0;
    }
    .team img {
        display: block;
    }
    

    To make this work, set overflow: auto in the parent container especially if you want to use a background color or image.

    You can adjust the margin or padding of the floated element to create and style gutters between images.

    Finally, I use display: block on the images to deal with any white space that may result from an inline element.

    For reference, see: http://jsfiddle.net/audetwebdesign/8FEeM/

    0 讨论(0)
  • 2021-01-29 02:28

    In my script can do this:

    $('.team').css({ "width": $(window).width(), "height": "auto" });

    0 讨论(0)
提交回复
热议问题