Add a small margin in a div with text-align: right

Asked

Viewed 182 times

1

I have a div with material bootstrap design of size 4 col-md-4 that aligns right my texts using text-align: right

The problem is that in the same line this text has an icon, which is also aligning to the right but with the float: right.

My text and my icon are very close, I would like to add a margin in my text to the left, so that it distances a little from my icon of "x".

Follow picture:

Follow my html and responsible css:

 <div class="row">
   <div class="col-12 col-md-4">
     <span class="tituloAtributo">Tamanho</span> <i class="fa fa-close iconeexcluiatributo" aria-hidden="true"></i>
     <br>
     <span class="atributo">P</span>
   </div>

   <div class="col-12 col-md-4 alinhacentro">
      <span class="tituloAtributo">Cor</span> <i class="fa fa-close iconeexcluiatributo" aria-hidden="true"></i>
      <br>
      <span class="atributo">Cinza</span>
    </div>

    <div class="col-12 col-md-4 alinhadireita">
        <span class="tituloAtributo">Cor</span> <i class="fa fa-close iconeexcluiatributo" aria-hidden="true"></i>
        <br>
        <span class="atributo">Rosa</span>
      </div>
 </div>

My css:

.alinhadireita{
    text-align: right;
}

.iconeexcluiatributo{
    color: #C62828;
    font-size: 14px!important;
    float: right;
}

inserir a descrição da imagem aqui

How can I add a margin between this x button so it doesn’t destroy my responsiveness?

1 answer

1


Dude just give one margin-left icon and not text

See how it looks:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <!-- Bootstrap core CSS -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
    <!-- Material Design Bootstrap -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.13/css/mdb.min.css" rel="stylesheet">
    <style>
        .alinhadireita {
            text-align: right;
        }

        .iconeexcluiatributo {
            color: #C62828;
            font-size: 14px !important;
            float: right;
            margin-left: 10px;
        }
    </style>
</head>

<body>

    <div class="row">
        <div class="col-12 col-md-4">
            <span class="tituloAtributo">Tamanho</span> <i class="fa fa-close iconeexcluiatributo" aria-hidden="true"></i>
            <br>
            <span class="atributo">P</span>
        </div>

        <div class="col-12 col-md-4 alinhacentro">
            <span class="tituloAtributo">Cor</span> <i class="fa fa-close iconeexcluiatributo" aria-hidden="true"></i>
            <br>
            <span class="atributo">Cinza</span>
        </div>

        <div class="col-12 col-md-4 alinhadireita">
            <span class="tituloAtributo">Cor</span> <i class="fa fa-close iconeexcluiatributo" aria-hidden="true"></i>
            <br>
            <span class="atributo">Rosa</span>
        </div>
    </div>


    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.bundle.min.js"></script>
</body>

</html>

  • It worked partially. But on the bottom line, in the "pink" case, I had to winter, so two classes were created: . ultimoelementocolumn{ margin-right: 10px; } . ultimoelementocolunacomclose{ margin-left: 10px; ;}

  • 1

    @Renaotpls this happened pq vc broke the line with a BR, but his reasoning was correct, it was only clone the margin-left for the text of the second line :D

Browser other questions tagged

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