How to apply style only to modal (Bootstrap)

Asked

Viewed 1,075 times

1

$head =
'<!-- ARQUIVOS CSS -->
<link rel="stylesheet" href="css/estrutura-informacoes-BD.css" />
<link rel="stylesheet" href="css/botoes.css" />
';


echo $abreTagHead.
        $head.
    $fechaTagHead.

    $abreTagBody.
        '<div id="container">'.
            $body.
        '</div>'.
    $fechaTagBody;

HTML

<div id="showModal"></div>



<div class="modal fade modalConteudo modal-fullscreen" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"></span></button>
                <h4 class="modal-title" id="myModalLabel">Regras</h4>
            </div>
            <div class="modal-body" style="text-align: center;">
                <span id="resultado"></span>
            </div>
        </div>'
    </div>
</div>

That content on top, in PHP, I have printar on span with id="resultado".

I made this echo just to be imprinted inside the showmodal (it opens a Bootstrap modal, and is shown a content). The problem is that CSS conflicts with my main page HTML (when I call modal, the effects are also applied to the main HTML,).

2 answers

2


If you own more than one modal and rewrite the css using ! Important all the modals of the page will be motified. a more assertive approach would be to create your own css configuration and add the modal you want example:

.minhaModal {
  width: 300px !important;
  text-align: center !important;
}
<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.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  MODAL 1
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal2">
  MODAL 2
</button>

<!-- Modal -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog minhaModal" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...GGGG
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Another thing, the bootstrap possesses text-center which replaces your inline css BOOTSTRAP CSS

1

You must use !important

.modal {
    background-color: red !important;
    color: white !important;
    border: 4px solid #000 !important;
}

Browser other questions tagged

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