jquery wrapping groups of adjacent elements

前端 未结 3 1539
我寻月下人不归
我寻月下人不归 2020-12-19 09:36

I have a cms that lets users insert blocks of content on a page. There are different types of content block available to the user and they can be inserted in any order. An e

3条回答
  •  孤城傲影
    2020-12-19 09:48

    The fiddle is here: http://jsfiddle.net/jdelight/XutA6/5/ Here's a possible solution using css which lets you style the blocks with a single background colour and border. The HTML would be something like this:

        
    this is block 1
    this is block 2
    this is block 3
    this is block 4
    this is block 5

    And the CSS would be:

                /* style all blocks with the required background colour and border */
            .block {
                background: #eee;
                color: #000;
                border: 1px solid red;
                border-bottom: 0;
                padding: 20px;
                width: 400px;
                border-radius: 20px;
                /* remove the rounded corners from he bottom left/right */
                border-bottom-left-radius:0;
                border-bottom-right-radius:0;
                position: relative;
            }
            /* style all adjacent blocks and remove the radius - so the top block has a radius and the others don't */
            .block + .block {
                border-radius: 0;
                border-top: 0;
            }
    
            /* create a cheeky block with content after which sits below all blocks */
            /* so it's hidden from all the blocks above it apart from the very bottom one (see bottom: -10px) */
            /* then style the rounded corners on that one */
            .block::after {
                content:'.';
                display: block;
                background: red;
                height: 10px;
                position: absolute;
                border-bottom: 1px solid red;
                border-left:  1px solid red;
                border-right:  1px solid red;
                bottom: -10px;
                width: 440px;
                background: #eee;
                left:-1px;
                border-bottom-left-radius:10px;
                border-bottom-right-radius:10px;
            }
    

提交回复
热议问题