Search code examples
htmlcsstwitter-bootstrapbootstrap-4

Bootstrap card padding on phone


I need to add padding to right side and left side of the card in bootstrap but I am not able to do it. Here is the code: (Bootstrap 4)

 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
 <section class="question-section">
            <div class="container">
                <div class="row padding-xs">
                    <div class="card shadow-lg rounded-lg" style="width: 30rem;">
                        <div class="pt-3">
                            <img class="card-img-top" src="question.svg" alt="Card image cap" height="128px" width="128px">
                        </div>
                        <div class="card-body">
                            <h5 class="card-title text-center">Jak budete zařízení využívat?</h5>
                          <p class="card-text text-center">Celodenní pracant nebo herní mašina?
                            Nebo jen nenáročné prohlížení internetu?</p>
                        </div>
            
                        <div class="input-group pr-3 pl-3 pt-3 pb-5">
                            <select class="custom-select" id="inputGroupSelect04">
                              <option selected>Vyberte...</option>
                              <option value="1">One</option>
                              <option value="2">Two</option>
                              <option value="3">Three</option>
                            </select>
                            <div class="input-group-append">
                              <button class="btn btn-outline-dark text-dark" type="button">Potvrdit</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            </section>


Solution

  • Padding in BS4 regulate by following rules:

    Formula {padding}{sides}-{size}, where

    p - sets padding

    Where sides is one of:

    t - sets padding-top

    b - sets padding-bottom

    l - sets padding-left

    r - sets padding-right

    x - sets both padding-left and padding-right

    y - sets both padding-top and padding-bottom

    blank - sets a margin or padding on all 4 sides of the element

    Where size is one of:

    0 - sets padding to 0

    1 - sets padding to .25rem (4px if font-size is 16px)

    2 - sets padding to .5rem (8px if font-size is 16px)

    3 - sets padding to 1rem (16px if font-size is 16px)

    4 - sets padding to 1.5rem (24px if font-size is 16px)

    5 - sets padding to 3rem (48px if font-size is 16px)

    auto - sets margin to auto

    Try to use class like .px-4

    <div class="row px-4" style="padding: 0 10px 0 10px;">
    

    Ore you can use style attribute like

    <div class="row padding-xs" style="padding: 0 10px 0 10px;">