
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create Block Element on Specific Screen Width with Bootstrap 4
To create a block on a specific screen width, use the .d-*-block class.
The specific screen width can be small, medium, large and extra large. Set the class indivifually based on the screen size as shown below −
<span class="d-sm-block bg-primary"> d-sm-block </span> <span class="d-md-block bg-success"> d-md-block </span> <span class="d-lg-block bg-info"> d-lg-block< /span> <span class="d-xl-block bg-warning"> d-xl-block </span>
Let us see the complete example to learn how to create a block element on a specific screen width −
Example
<!DOCTYPE html> <html> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> </head> <body> <div class="container mt-3"> <h2>Blocks</h2> <p>Resize the browser to check the effect</p> <span class="d-block bg-info">d-block</span> <span class="d-sm-block bg-primary">d-sm-block</span> <span class="d-md-block bg-success">d-md-block</span> <span class="d-lg-block bg-info">d-lg-block</span> <span class="d-xl-block bg-warning">d-xl-block</span> </div> </body> </html>
Advertisements