How to apply the style only in modal (Bootstrap)

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 above, in PHP, I have to start with span with id="resultado" .

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

    
asked by anonymous 25.07.2015 / 05:25

2 answers

2

If you have more than one modal and rewrite css using! important all page modals will be motifed. 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><scriptsrc="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, bootstrap has text-center that replaces your inline css BOOTSTRAP CSS

    
25.07.2015 / 13:46
1

You should use !important

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