Is it possible to do a popover always centered on the page, something like a modal but on hover?

-1

How do I adapt the size of the bootstrap popover to the size of the content?

Within that link there is a popover adapted to the 100% width, my question is, if it is possible that the same popover is always shown at the center of the screen

    
asked by Enrique Solis 01.02.2018 в 16:14
source

1 answer

0

Actually it's very easy (if I understood correctly what you want), but I'll clarify, that I'll probably earn some negative points in this question by answering you, being that you have formulated them incorrectly , since you do not provide at least how you have your html structure, if you have tried to do it or an example in image of what you want to achieve.

To the point, you only need to use position: fixed in the pop up container and position it to the center dynamically, like this:

.popup{
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate( -50%, -50%);
}

Here is an example with 2 html structures, one with the popup content inside the popover and another being in the same hierarchical position:

*{box-sizing: border-box; margin: 0; padding: 0;
  font-family: arial;}

.pop-over{
  display: inline-block;
  padding: 0.5em;
  background: whitesmoke;
  cursor: pointer;
  border-radius: 0.3em;
}

.popup{
padding: 0.5em 1em;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate( -50%, 0);
  display: inline-block;
  z-index: 10;
  background: white;
  box-shadow: 0 0 1em 0 rgba(0,0,0,.2);  
  border-radius: 0.3em;
  pointer-events: none;
  opacity: 0;
  transition: all ease .3s;
}

.pop-over:hover .popup,
.pop-over:hover + .popup{
  transform: translate(-50%, -50%);  
  opacity: 1;
}
<label class="pop-over">
  Texto 01
  <div class="popup">
    Contenido
  </div>
</label>

<label class="pop-over">
  Texto 02
</label>
<div class="popup">
  Contenido
</div>

Now, it works or not, it depends on several things, your html structure, the css you have to overwrite, if you are wanting a solution with javascript or if your problem is well understood. Anything leave me your comment. Successes!

    
answered by 02.02.2018 / 18:57
source