Align button inside Alert

Asked

Viewed 157 times

1

The needing leaves a button lining inside the boostrap "Alert" element. I tried to do this with the "pull-right" class, but half the button is outside the element.

Someone can help me?

inserir a descrição da imagem aqui

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.css" integrity="sha256-0XAFLBbK7DgQ8t7mRWU5BF2OMm9tjtfH945Z7TTeNIo=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.js" integrity="sha256-29KjXnLtx9a95INIGpEvHDiqV/qydH2bBx0xcznuA6I=" crossorigin="anonymous"></script>

<div class="alert alert-warning" role="alert">
    <form action="/Ti01/AprovaSolicitacao" method="post">
        <h4>Esta solicitação ainda está pendente de sua aprovação!</h4>
        <input htmlattributes="{ class = form-control, readonly = readonly }" id="CadastroID" name="CadastroID" type="hidden" value="1">
        <input type="button" class="btn btn-success btn-finish pull-right" name="aprova" value="Aprovar" onclick="$('#ModalAprovar').modal('show');">
        <!-- Modal -->
        <div class="modal fade" id="ModalAprovar" role="dialog">
            <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">×</button>
                        <h4 class="modal-title text-left">Aprovação da Solicitação</h4>
                    </div>
                    <div class="modal-body">
                        Digite uma justificativa
                        <textarea class="form-control" cols="4" id="ObservacaoAprov" name="ObservacaoAprov" rows="4"></textarea>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
                        <button type="submit" class="btn btn-success">Concluir</button>
                    </div>
                </div>

            </div>
        </div>

2 answers

1


Dude use Bootstrap’s Grid, use row>col etc, in case you need to use offset in col to generate "empty spaces" between a column and another. In this case I even removed the class pull-right that you’re actually putting float:right in his btn. I suggest you stop by for an hour to read the Grid documentation! https://getbootstrap.com/docs/3.4/css/#grid

inserir a descrição da imagem aqui

Follow the image code above. This option does not use extra CSS, only the grid and BS classes. If you want to customize CSS you can also...

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.css" integrity="sha256-0XAFLBbK7DgQ8t7mRWU5BF2OMm9tjtfH945Z7TTeNIo=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.js" integrity="sha256-29KjXnLtx9a95INIGpEvHDiqV/qydH2bBx0xcznuA6I=" crossorigin="anonymous"></script>

    
<div class="alert alert-warning" role="alert">
    <form action="/Ti01/AprovaSolicitacao" method="post">
        <div class="row">
            <div class="col-sm-7 text-center">
                <h4 class="">Esta solicitação ainda está pendente de sua aprovação!</h4>
            </div>
            <div class="col-sm-2 col-sm-offset-3 text-center text-sm-right">
                <input htmlattributes="{ class = form-control, readonly = readonly }" id="CadastroID" name="CadastroID" type="hidden" value="1">
                <input type="button" class="btn btn-success btn-finish " name="aprova" value="Aprovar" onclick="$('#ModalAprovar').modal('show');">
            </div>
        </div>
        <!-- Modal -->
        <div class="modal fade" id="ModalAprovar" role="dialog">
            <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">×</button>
                        <h4 class="modal-title text-left">Aprovação da Solicitação</h4>
                    </div>
                    <div class="modal-body">
                        Digite uma justificativa
                        <textarea class="form-control" cols="4" id="ObservacaoAprov" name="ObservacaoAprov" rows="4"></textarea>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
                        <button type="submit" class="btn btn-success">Concluir</button>
                    </div>
                </div>

            </div>
        </div>
    </form>
</div>

1

Place the button inside a div with the class .text-right. This class applies the property text-align: right. For being inline, the button will be right aligned:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.css" integrity="sha256-0XAFLBbK7DgQ8t7mRWU5BF2OMm9tjtfH945Z7TTeNIo=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.js" integrity="sha256-29KjXnLtx9a95INIGpEvHDiqV/qydH2bBx0xcznuA6I=" crossorigin="anonymous"></script>

<div class="alert alert-warning" role="alert">
    <form action="/Ti01/AprovaSolicitacao" method="post" class="d-flex">
        <h4>Esta solicitação ainda está pendente de sua aprovação!</h4>
        <input htmlattributes="{ class = form-control, readonly = readonly }" id="CadastroID" name="CadastroID" type="hidden" value="1">
        <div class="text-right">
           <input type="button" class="btn btn-success btn-finish" name="aprova" value="Aprovar" onclick="$('#ModalAprovar').modal('show');">
        </div>
        <!-- Modal -->
        <div class="modal fade" id="ModalAprovar" role="dialog">
            <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">×</button>
                        <h4 class="modal-title text-left">Aprovação da Solicitação</h4>
                    </div>
                    <div class="modal-body">
                        Digite uma justificativa
                        <textarea class="form-control" cols="4" id="ObservacaoAprov" name="ObservacaoAprov" rows="4"></textarea>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
                        <button type="submit" class="btn btn-success">Concluir</button>
                    </div>
                </div>

            </div>
        </div>

Browser other questions tagged

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