skip to Main Content

Issue:
I am trying to highlight the top and bottom border of items within an accordion when they have hovered state.

The issue is that I use the border-collapse: collapse statement to collapse borders that are adjacent. There the hover effects don’t resolve the wanted styling.

Below you will find the HTML and CSS:

HTML:

<table class="accordion-container">
        <tr class="accordionItem-container" v-for="(item, index) in state.topics" :key="index">
            <td class="accordionItem">
                <div class="accordionImage-container">
                    <img class="accordionImage" :src="item.img" alt="">
                </div>
                <div class="accordionCopy-container">
                    <BaseHeading class="accordionHeader">
                        <template #default>
                            <span class="mainHeader">{{ item.mainHeader }}</span>
                            <span class="subHeader">{{ item.subHeader }}</span>
                        </template>
                    </BaseHeading>
                </div>
            </td>
        </tr>
        <tr class="accordionItem-container" v-for="(item, index) in state.topics" :key="index">
            <td class="accordionItem">
                <div class="accordionImage-container">
                    <img class="accordionImage" :src="item.img" alt="">
                </div>
                <div class="accordionCopy-container">
                    <BaseHeading class="accordionHeader">
                        <template #default>
                            <span class="mainHeader">{{ item.mainHeader }}</span>
                            <span class="subHeader">{{ item.subHeader }}</span>
                        </template>
                    </BaseHeading>
                </div>
            </td>
        </tr>
    </table>

CSS:

<style scoped>
    .accordion-container {
        border-collapse: collapse;
        border-spacing: 0 4px;
    }
    .accordionItem-container {
        border: 4px solid #EBEEF0;
        border-left: none;
        border-right: none;
    }
    .accordionItem-container:hover {
        border: 4px solid #006366;
        border-left: none;
        border-right: none;
    }
    .accordionItem {
        display: flex;
        padding: 16px 0 20px 0;
        gap: 20px;
        align-items: center;
    }
    .accordionImage-container {
        width: 61px;
        height: 56px;
    }
    .accordionImage {
        border-radius: 12px;
        max-width: 100%;
        height: auto;
    }
    .accordionHeader {
        display: flex;
        flex-direction: column;
    }
    .mainHeader {
        font-weight: 400 !important;
    }
    .subHeader {
        font-weight: 300 !important;
        font-size: 16px;
    }

    @media screen and (max-width: 1024px) {
        .accordionImage-container {
            display: none;
        }
    }
</style>

Here is also a link to the jsfiddle: https://jsfiddle.net/MarquezTMoore/Lyb5ah7o/6/

I have tried using the outline property in the hover state however this add outline to all four sides…

2

Answers


  1. The issue is trying to give the border to the tr. Try this instead:
    .accordionItem-container:hover td {}

    CSS Styling Tables
    https://www.w3schools.com/css/css_table.asp

    Login or Signup to reply.
  2. It can be achieved use pseudo-elements like after and before

     .accordion-container {
            border-collapse: collapse;
            border-spacing: 0 4px;
    }
    .accordionItem-container {
            border: 4px solid #EBEEF0;
            border-left: none;
            border-right: none;
            position:relative;
            cursor:pointer;
    }
    
    .accordionItem-container:hover:after  {
            width:100%;
    }
    .accordionItem-container:hover:before  {
            width:100%;
    }
    .accordionItem-container:after{
       content:'';
       position:absolute;
       height:4px;
       top:0;
       left:0;
       background-color:#006366;
    }
    .accordionItem-container:before{
       content:'';
       position:absolute;
       height:4px;
       bottom:0;
       left:0;
       background-color:#006366;
    }
    <table class="accordion-container">
            <tr class="accordionItem-container">
                <td class="accordionItem">
                   some content
                </td>
            </tr>
            <tr class="accordionItem-container">
                <td class="accordionItem">
                    some content
                </td>
            </tr>
             <tr class="accordionItem-container">
                <td class="accordionItem">
                    some content
                </td>
            </tr>
    </table>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search