Convert horizontal block to vertical in case screen size smaller than a specified value

前端 未结 1 939
清歌不尽
清歌不尽 2021-01-29 09:36

In the following code, I would like the horizontal three-column block to drop and stack on top of each other in case the size of the container becomes less than X pixels (for sm

1条回答
  •  一向
    一向 (楼主)
    2021-01-29 09:58

    Do you want the layout to only be three across or three down? Or can each container wrap to the next line as the screen size decreases?

    Your current code simply resizes the images, text, and containers when the screen is shrunk down. If you just want the containers to wrap as the screen shrinks, you can accomplish this by using

    tags and float:left; and max-width CSS.

    The main issue you're having is that each container is a completely separate table, each of which is in a completely separate table cell inside another table.

    Take a look at this (run the code snippet and use the Full Page link to test it out):

    .container {
        background-color: #ffffff;
        max-width: 300px;
        float: left;
        margin: 10px;
        padding: 20px;
    }

    Title

    Lorem ipsum
    dolor sit


    Morbi auctor non ipsum quis ullamcorper. Donec et purus mi. Nunc et auctor lacus.

    Lorem ipsum
    dolor sit


    Morbi auctor non ipsum quis ullamcorper. Donec et purus mi. Nunc et auctor lacus.

    Lorem ipsum
    dolor sit


    Morbi auctor non ipsum quis ullamcorper. Donec et purus mi. Nunc et auctor lacus.

    If this isn't what you're looking for, please let me know.

    Also, just an fyi, there are several areas of your code that you should rethink. Specifically, any time you're specifying a size, you should be putting the unit with it. i.e. width="1024"....1024 what? If it's pixels, use 1024px. And to take that point a little further, in the elements you already have CSS that says width: 100%;. So, also having width="1024" is redundant and confusing.

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