Bootstrap modal "data-Dismiss" bugging with position="Absolute"

Asked

Viewed 438 times

1

I’m adding a custom close button on modal of bootstrap.

I want him on the right modal, for that I gave a position: absolute and modified the top and right his.

The problem is that by doing this the button becomes unusable. From what I could understand, there is a conflict between the data-dismiss: modal (attribute that causes the element to close the modal) with the position: absolute.

I tried other ways to do this "button" like import a . svg, create a <button>, <span> besides changing the position: absolute for float:right. By doing this, only a small portion of the button area becomes the close link and not the whole area. The mobile and desktop experience is quite unpleasant because it is necessary to press/click several times until you find the right area, and the correct one is ALL the area of the button be a link to close the modal.

Follow the code and a Snippet to be clearer:

.close-modal {
  position: absolute;
  /* REMOVA O `POSITION` E O 'BOTÃO' FUNCIONA */
  width: 75px;
  height: 75px;
  background-color: transparent;
  right: 35px;
  top: 25px;
  cursor: pointer
}
.close-modal:hover {
  opacity: .3;
}
.lr {
  height: 75px;
  width: 1px;
  margin-left: 35px;
  background-color: #222;
  transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  z-index: 1051;
}
.rl {
  height: 75px;
  width: 1px;
  background-color: #222;
  transform: rotate(90deg);
  -ms-transform: rotate(90deg);
  -webkit-transform: rotate(90deg);
  z-index: 1051;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />



<a href="#modal" class="portfolio-link" data-toggle="modal">
             CHAMAR MODAL    
</a>



<div class="portfolio-modal modal fade" id="modal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-content">
    <div class="close-modal" data-dismiss="modal">
      <div class="lr">
        <div class="rl">
        </div>
      </div>
    </div>
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-lg-offset-2">
          <div class="modal-body">

            <p>CONTEÚDO MODAL CONTEÚDO MODAL</p>

            <p>CONTEÚDO MODAL CONTEÚDO MODAL</p>

            <p>CONTEÚDO MODAL CONTEÚDO MODAL</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

How can I fix this?

2 answers

0

Instead of position:absolute, use float:right, and margin-right and margin-top, instead of right e top.

0


Enter the property z-index to define the order of the position elements (relative, absolute and fixed)

.close-modal {
    z-index: 1;
}
  • Solved! Thank you very much. Very simple

Browser other questions tagged

You are not signed in. Login or sign up in order to post.