Vladimir Kirov
Vladimir Kirov

Reputation: 69

How to resolve this problem? How to break the grid row, bootstrap 4? Which Bootstrap classes I have to use?

  1. Test Links. Using Bootstrap classes, modify the div element with the id "links" so that on extra small resolutions (<576px), each link and ad takes one whole row. It should look like this: enter image description here

On small resolutions and higher (≥576px), both links should take one half of the row and the ads should be invisible. It should look like this: enter image description here

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Tests</title>
    <link
      rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
    />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
    <style>
      a,
      div {
        outline: 1px solid black;
      }
    </style>
  </head>
  <body>
    <div id="links">
      <a href="#">Aptitude tests</a>
      <div>Ads!</div>
      <a href="#">Programming tests</a>
      <div>More ads!</div>
    </div>
    <article>Here you can find various tests...</article>
  </body>
</html>

Upvotes: 0

Views: 387

Answers (2)

FluffyKitten
FluffyKitten

Reputation: 14312

You are getting close with your answer. To get it to work, these are the changes you need to make to the original code in your question:

  1. add the class row to the container that has your cols (i.e. the links div) - cols must be in a row
  2. Add col-12 col-sm-6 to the a elements (you just had the wrong breakpoint when you said col-12 col-md-6) Ref: Bootstrap breakpoints, Bootstrap Grid Mix & Match Col classes
  3. For the divs, add d-sm-none to hide it on small screens (Ref: Bootstrap Display property) and col-12 to show it full width on all other screens.

You can see it working here:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Tests</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script> 
    <style>
      a, div {
        outline: 1px solid black;
      }
    </style>
  </head>
  
  <body>
    <div id="links" class="row">
      <a href="#" class="col-12 col-sm-6">Aptitude tests</a>
      <div class="d-sm-none col-12">Ads!</div>
      <a href="#" class="col-12 col-sm-6">Programming tests</a>
      <div  class="d-sm-none col-12">More ads!</div>
    </div>
    <article>Here you can find various tests...</article>
  </body>
</html>

Upvotes: 1

Vladimir Kirov
Vladimir Kirov

Reputation: 69

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Tests</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script> 
        <style>
            a, div {
                outline: 1px solid black;
            }
            @media (min-width: 576px ) {
                #links {
                    display: flex;
                    flex-direction: column;
                    padding-right: none;
                    padding-left: none;
                }
            }

            @media (max-width: 576px ) {
                #links {
                    flex-direction: row;
                }
            }

        </style>
    </head>
    <body>
        <div id="links">
            <a href="#" class="col-12">Aptitude tests</a>
            <div class="d-none d-md-block">Ads!</div>
            <a href="#" class="col-12">Programming tests</a>
            <div class="d-none d-md-block">More ads!</div>
        </div>
        <article>Here you can find various tests...</article>
    </body>
</html>

This is the code I got with it.

Upvotes: 0

Related Questions