There are a few ways that you can reorder the columns. I recommend you to use bootstrap 4 classes rather than custom CSS since you already use bootstrap.
- In the HTML code, first write the columns that you want to position at the top on mobile. And use the
order-sm-1
class. But i think it is better to use order-sm-last
since it is more intuitive. In this particular case, they both function the same.
<!DOCTYPE html>
<html lang="en">
<head>
<link crossorigin="anonymous" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-4 order-sm-last bg-primary">
First on mobile
</div>
<div class="col-sm-8 bg-danger">
2
</div>
</div>
</div>
</body>
</html>
- Maintain the order of columns as you have written and use
order-last
and order-sm-first
for the first column.
<!DOCTYPE html>
<html lang="en">
<head>
<link crossorigin="anonymous" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-8 order-last order-sm-first">
2
</div>
<div class="col-sm-4">
First on mobile
</div>
</div>
</div>
</body>
</html>
Alternatively, you can use order-1
and order-sm-0