Sagar
Sagar

Reputation: 497

Require help on implementing border design

Have to implement a design where I am confused on how to implement the border design. Attached is the pic which I am trying to implement.

I am trying to figure out how to implement that border ui based on selecting the type of filter I want to select. The same applies for the other two tabs. Also the option's are not visible until and unless the user explicitly selects it. I have searched on codepen.io but did not get the required results. I know such type of css exist however I am unable to get the specific words/term to search for it.

Filter options price selected

Here's the work I have done so far

HTML

<div class="search_options_container">
  <div class="search_option_tab">
    <div class="option_header" data-filter-type="team">
      TEAM
      <br>
      <span>ALL</span>
    </div>
    <div class="option_header" data-filter-type="position">
      POSITION
      <br>
      <span>ALL</span>
    </div>
    <div class="option_header" data-filter-type="price">
      PRICE
      <br>
      <span>ALL</span>
    </div>
  </div>
  <div class="options_container">
    <span class="filter-option" data-option="All">All</span>
    <span class="filter-option" data-option="Option 1">Option 1</span>
    <span class="filter-option" data-option="Option 2">Option 2</span>
    <span class="filter-option" data-option="Option 3">Option 3</span>
    <span class="filter-option" data-option="Option 4">Option 4</span>
    <span class="filter-option" data-option="Option 5">Option 5</span>
  </div>
  <div class="options_container" ng-if="filter-position">
    <span class="filter-option" data-option="All">All</span>
    <span class="filter-option" data-option="Option 1">Option 1</span>
    <span class="filter-option" data-option="Option 2">Option 2</span>
    <span class="filter-option" data-option="Option 3">Option 3</span>
    <span class="filter-option" data-option="Option 4">Option 4</span>
    <span class="filter-option" data-option="Option 5">Option 5</span>
  </div>
  <div class="options_container" ng-if="filter-price">
    <span class="filter-option" data-option="All">All</span>
    <span class="filter-option" data-option="Option 1">Option 1</span>
    <span class="filter-option" data-option="Option 2">Option 2</span>
    <span class="filter-option" data-option="Option 3">Option 3</span>
    <span class="filter-option" data-option="Option 4">Option 4</span>
    <span class="filter-option" data-option="Option 5">Option 5</span>
  </div>
</div>

--

CSS

.search_options_container {
  text-align: center;
}
.search_option_tab {
  display: flex;
  padding-top: 6px;
}
.option_header {
  display: inline-block;
  width: 33.33%;
}
.options_container {
  display: block;
  width: 100%;
  text-align: center;
  position: absolute;
  left: 0;
  background: white;
  z-index: 1;
  padding-top: 6px;
  height: 180px;
  overflow: auto;
}
.options_container > .filter-option {
  display: inline-block;
  padding: 5px;
  border-bottom: 1px solid black;
  width: 80%;
}
.options_container > .filter-option:last-child {
  border-bottom: none;
}

P.S:- I have corped the pic to the required detail as I have seen fit. In case you would like to have the whole pic, please do let me know.

Also, I know some of you might say where is the code that shows implementation of the border. And my response to that is because I cannot cut merge that minor portion of the border between the two divs, aka between the price tab and it's options, I have not implemented at all.

Upvotes: 1

Views: 49

Answers (2)

Fered
Fered

Reputation: 908

This is my approach for this,... I added some new CSS rules and also have overwritten some of your CSS codes. this will create a flying box above each tab . with this i think you can show something similar to the picture where the white area is behind the word " ALL ".

Note : your current and active option_header must receives an active class.

.search_options_container {
    text-align: center;
}
.search_option_tab {
    display: flex;
    padding-top: 6px;
}
.option_header {
    display: inline-block;
    width: 33.33%;
    position: relative; /* added : makes childs to be relative */
}

/* === Add === */
.option_header span{
    position:relative; /* makes sure z-index works for them */
    z-index:3;         /* brings span (element with word "ALL") in tabs to front  */
} 
.option_header.active:after{
    content: ' ';      /* must defined in order to render after element */ 
    position: absolute;
    background-color: #fff;
    border: 2px solid purple;
    border-bottom: none;
    border-radius: 10px 10px 0 0;
    height: 25px;      /* a number that is related to height of tabs */

    /* optional : add space to left and right */
    right: 30px;       
    left: 30px; 

    /* optional: if you don't want that you can add width 
    left:0;
    width:100%; */

    bottom: -2px;      /* shifts the element 2 pixels down ( 2px = width of the border) */
    z-index: 2;        /* brings 1 layer in front */
}
/* === End of Add === */

.options_container {
    display: block;
    width: 100%;
    text-align: center;
    position: absolute;
    left: 0;
    background: white;
    z-index: 1;
    padding-top: 6px;
    height: 180px;
    overflow: auto;

    /* === Add === */
    border:2px solid purple;
    border-radius:10px; 
    right:10px;         /* optional, adds small distance from right */
    left:10px;          /* not required, adds small distance from left */
    width:auto;         /* if you don't use left and right, remove this. */
}
.options_container > .filter-option {
    display: inline-block;
    padding: 5px;
    border-bottom: 1px solid black;
    width: 80%;
}
.options_container > .filter-option:last-child {
    border-bottom: none;
}

Hope it helps you

Upvotes: 1

Asons
Asons

Reputation: 87191

Here is a solution, where you move the tabs 1 pixel down, and when they get a background they will cover the border below. See notes in CSS.

.search_options_container {
  text-align: center;
}
.search_option_tab {
  display: flex;
  padding-top: 6px;
  position: relative;                      /*  added so z-index work       */
  z-index: 2;                              /*  put tab's in a higher layer */
}
.option_header {
  display: inline-block;
  width: 33.33%;
  transform: translateY(1px);              /*  push the tabs 1px down so they
                                               cover the below border */
}
.option_header[data-filter-type="team"] {  /*  added new rule  */
  border: 1px solid red;
  border-bottom: none;
  background: lightgray;
}
.options_container {
  display: block;
  width: 100%;
  text-align: center;
  position: absolute;
  left: 0;
  background: white;
  z-index: 1;
  padding-top: 6px;
  height: 180px;
  overflow: auto;
  border: 1px solid red;                    /*  added  */
  background: lightgray;                    /*  added  */
}

.options_container > .filter-option {
  display: inline-block;
  padding: 5px;
  border-bottom: 1px solid black;
  width: 80%;
}
.options_container > .filter-option:last-child {
  border-bottom: none;
}
<div class="search_options_container">
  <div class="search_option_tab">
    <div class="option_header" data-filter-type="team">
      TEAM
      <br>
      <span>ALL</span>
    </div>
    <div class="option_header" data-filter-type="position">
      POSITION
      <br>
      <span>ALL</span>
    </div>
    <div class="option_header" data-filter-type="price">
      PRICE
      <br>
      <span>ALL</span>
    </div>
  </div>
  <div class="options_container">
    <span class="filter-option" data-option="All">All</span>
    <span class="filter-option" data-option="Option 1">Option 1</span>
    <span class="filter-option" data-option="Option 2">Option 2</span>
    <span class="filter-option" data-option="Option 3">Option 3</span>
    <span class="filter-option" data-option="Option 4">Option 4</span>
    <span class="filter-option" data-option="Option 5">Option 5</span>
  </div>
  <div class="options_container" ng-if="filter-position">
    <span class="filter-option" data-option="All">All</span>
    <span class="filter-option" data-option="Option 1">Option 1</span>
    <span class="filter-option" data-option="Option 2">Option 2</span>
    <span class="filter-option" data-option="Option 3">Option 3</span>
    <span class="filter-option" data-option="Option 4">Option 4</span>
    <span class="filter-option" data-option="Option 5">Option 5</span>
  </div>
  <div class="options_container" ng-if="filter-price">
    <span class="filter-option" data-option="All">All</span>
    <span class="filter-option" data-option="Option 1">Option 1</span>
    <span class="filter-option" data-option="Option 2">Option 2</span>
    <span class="filter-option" data-option="Option 3">Option 3</span>
    <span class="filter-option" data-option="Option 4">Option 4</span>
    <span class="filter-option" data-option="Option 5">Option 5</span>
  </div>
</div>


Updated

If you only want to wrap border around the "ALL" text, simply change their elements to a div, remove the <br> and change this CSS rule

.option_header[data-filter-type="team"]

to

.option_header[data-filter-type="team"] div

Stack snippet

.search_options_container {
  text-align: center;
}
.search_option_tab {
  display: flex;
  padding-top: 6px;
  position: relative;                          /*  added so z-index work       */
  z-index: 2;                                  /*  put tab's in a higher layer */
}
.option_header {
  display: inline-block;
  width: 33.33%;
  transform: translateY(1px);                  /*  push the tabs 1px down so they
                                               cover the below border */
}
.option_header[data-filter-type="team"] div {  /*  added new rule  */
  border: 1px solid red;
  border-bottom: none;
  background: lightgray;
}
.options_container {
  display: block;
  width: 100%;
  text-align: center;
  position: absolute;
  left: 0;
  background: white;
  z-index: 1;
  padding-top: 6px;
  height: 180px;
  overflow: auto;
  border: 1px solid red;                       /*  added  */
  background: lightgray;                       /*  added  */
}

.options_container > .filter-option {
  display: inline-block;
  padding: 5px;
  border-bottom: 1px solid black;
  width: 80%;
}
.options_container > .filter-option:last-child {
  border-bottom: none;
}
<div class="search_options_container">
  <div class="search_option_tab">
    <div class="option_header" data-filter-type="team">
      TEAM
      <div>ALL</div>
    </div>
    <div class="option_header" data-filter-type="position">
      POSITION
      <div>ALL</div>
    </div>
    <div class="option_header" data-filter-type="price">
      PRICE
      <div>ALL</div>
    </div>
  </div>
  <div class="options_container">
    <span class="filter-option" data-option="All">All</span>
    <span class="filter-option" data-option="Option 1">Option 1</span>
    <span class="filter-option" data-option="Option 2">Option 2</span>
    <span class="filter-option" data-option="Option 3">Option 3</span>
    <span class="filter-option" data-option="Option 4">Option 4</span>
    <span class="filter-option" data-option="Option 5">Option 5</span>
  </div>
  <div class="options_container" ng-if="filter-position">
    <span class="filter-option" data-option="All">All</span>
    <span class="filter-option" data-option="Option 1">Option 1</span>
    <span class="filter-option" data-option="Option 2">Option 2</span>
    <span class="filter-option" data-option="Option 3">Option 3</span>
    <span class="filter-option" data-option="Option 4">Option 4</span>
    <span class="filter-option" data-option="Option 5">Option 5</span>
  </div>
  <div class="options_container" ng-if="filter-price">
    <span class="filter-option" data-option="All">All</span>
    <span class="filter-option" data-option="Option 1">Option 1</span>
    <span class="filter-option" data-option="Option 2">Option 2</span>
    <span class="filter-option" data-option="Option 3">Option 3</span>
    <span class="filter-option" data-option="Option 4">Option 4</span>
    <span class="filter-option" data-option="Option 5">Option 5</span>
  </div>
</div>

Upvotes: 1

Related Questions