Container-Fluid
The “container-fluid” class in Bootstrap 5 creates a container that spans the entire width of the viewport, adjusting to different screen sizes without margins or gutters. It’s ideal for full-width elements like headers, footers, or hero sections, providing a seamless transition across devices. With no predefined maximum width or centering, it’s perfect for full-bleed layouts where content should extend from edge to edge without any constraints.
Example: Illustration of container-fluid div will take up 100% width of the parent element on all screen sizes.
HTML
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > < link href = "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel = "stylesheet" integrity = "sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin = "anonymous" > < title >Bootstrap 5 Container-fluid</ title > </ head > < body class = "bg-light" > < div class = "container-fluid mt-5 p-4 rounded text-center shadow" > < h2 class = "text-success" >Bootstrap 5 Container-fluid</ h2 > < table class = "table table-bordered" > < thead class = "table-danger" > < tr > < th scope = "col" >Course Id</ th > < th scope = "col" >Course Name</ th > < th scope = "col" >Course Price</ th > </ tr > </ thead > < tbody > < tr class = "table-info" > < th scope = "row" >1</ th > < td >Java</ td > < td >30000</ td > </ tr > < tr class = "table-info" > < th scope = "row" >2</ th > < td >Python</ td > < td >25000</ td > </ tr > < tr class = "table-info" > < th scope = "row" >3</ th > < td >C++</ td > < td >20000</ td > </ tr > </ tbody > </ table > </ div > </ body > </ html > |
Output:
What is the Difference Between container and container-fluid in Bootstrap 5 ?
In Bootstrap 5, the “container” class creates a responsive container with a fixed width, adjusting to different screen sizes while maintaining margins. On the other hand, the “container-fluid” class generates a full-width container that spans the entire viewport without any margins, providing a seamless layout across various devices. “Container” is suitable for centered content with a defined width, while “container-fluid” is ideal for edge-to-edge content without constraints.
Table of Content
- Container
- Container-Fluid
- Difference between container & container-fluid