Skip to content

Instantly share code, notes, and snippets.

@carlesba
Last active February 27, 2016 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlesba/a0c0cd365b06080ecdca to your computer and use it in GitHub Desktop.
Save carlesba/a0c0cd365b06080ecdca to your computer and use it in GitHub Desktop.
SASS Object Beside to create tooltips/dropdowns

Object Beside

Based on BEM IT css convention, this object will place any container beside the parent one. So you can build tooltips, dropdowns, etc just adding this object inside the main wrapper. The only condition is that wrapper has to have position: relative

ie:

<div class='c-label'>
  <div class='c-label__title'>label title</div>
  <div class='o-beside o-beside--bottom'>
    <div class='o-beside__wrapper'>
      <div class='o-beside__content'>tooltip/dropdown/whatever</div>
    </div>
  </div>
</div>

Notes

Note that this snippet uses bourbon mixins to build flex elements as this standard has been changed in the last years. This way we can assure more retro-compatibility.

As it's based on new CSS3 standard Flex this is should be considered as a concept. It seems to have some bugs on Safari, (not tested on Explorer).

/*
<div class="o-beside**">
<div class="o-beside__wrapper">
<div>content</div>
</div>
</div>
*/
.o-beside
position: absolute
height: 0
width: 0
.o-beside--bottom
bottom: -$padding
right: 50%
.o-beside--bottom-right
bottom: -$padding
right: 0
.o-beside--bottom-left
bottom: -$padding
left: 0
.o-beside--right
bottom: 50%
right: 0
.o-beside__wrapper
+display(flex)
+align-items(center)
.o-beside--center > &
+justify-content(center)
.o-beside--start > &
+justify-content(flex-start)
.o-beside--end > &
+justify-content(flex-end)
@JoanClaret
Copy link

Looks interesting!
What about to create a codepen preview example?

@davesnx
Copy link

davesnx commented Feb 19, 2016

👍

@carlesba
Copy link
Author

Here:

Object Beside example

Notice that I avoided bourbon mixins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment