Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Bootstrap Rows/Columns are not the full width of the screen (Only 50% of it)

My experience with CSS and Bootstrap, when it comes to positioning and resizing elements on the screen, has been bloody awful ever since I started writing HTML. All I am trying to do (in my React project) is position 2 elements on the screen side by side, the element on the left needs to be 80% of the screens width and the element on the right has to be 20% of the screens width. Obviously for bootstrap to be able to do this, it requires 4 weeks writing code, 20+ stack overflow questions and 1 human sacrifice.

Below is the main app component with a <React.Fragment/> tag and a <Container/> with <Row/> and <Col/> inside that:

import React, { Component } from "react";
import { Container, Row, Col } from "react-bootstrap";

class App extends Component {
  state = {};
  render() {
    return (
      <React.Fragment>
        <Container>
          <Row>
            <Col>Hello</Col>
            <Col>Hello2</Col>
          </Row>
        </Container>
      </React.Fragment>
    );
  }
}

export default MainContent;

Expected result? Hello will be on the left of screen and Hello2 will be on the right of screen smack bang in the middle. Just as the docs suggest here.

But of course that doesn't happen. The row is centered in the middle of the screen and is about half of the screen size in total width.

To illustrate: 25% Whitespace | Hello1 | Hello2 | 25% Whitespace

Honestly, I have no idea what to do. Setting the margins to 0 will put it on the left of screen but it is still not the full width.

Someone please help me, I've had enough :(

like image 576
Liam G Avatar asked Aug 21 '19 01:08

Liam G


People also ask

Which react-Bootstrap component you will use for width 100% across all viewport and device sizes?

You can use <Container fluid /> for width: 100% across all viewport and device sizes.

What is XS SM MD lg in Bootstrap?

The Bootstrap 3 grid system has four tiers of classes: xs (phones), sm (tablets), md (desktops), and lg (larger desktops). You can use nearly any combination of these classes to create more dynamic and flexible layouts.

How do I make 5 columns in Bootstrap 4?

Populate the 'row' div with 5 divs with class 'col'. Because Bootstrap 4.0+ grid system has now shifted to Flexbox, the columns will arrange by themselves into five equally sized DOM elements.


1 Answers

By default in bootstrap, container width and max-width is set to some px like,

@media (min-width: 768px)
.container {
    max-width: 720px;
}

@media (min-width: 576px)
.container {
    max-width: 540px;
} 

.container {
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
}

You have to set max-width: 100% like,

.container {
  max-width: '100%'  //This will make container to take screen width
}

Or, Another way is, you can add fluid prop to Container,

fluid - Allow the Container to fill all of it's availble horizontal space.

<Container fluid>
  ...
</Container>

Note: Here Col will take by default equal space.

The Col lets you specify column widths across 5 breakpoint sizes (xs, sm, md, large, and xl).

For example,

<Row>
    <Col xs={6} md={8}>
      xs=6 (6 parts of screen on small screen) md=8 (8 parts of screen on medium screen)
    </Col>
    <Col xs={6} md={4}>
      xs=6 md=4
    </Col>
</Row>
like image 190
ravibagul91 Avatar answered Sep 22 '22 13:09

ravibagul91