React Bootstrap NavBar Container, set width to auto - css

I am trying to use a NavBar from react bootstrap. However there seems to be a <div class="container"> that adds width. How do I set this width to auto?
I tried the following:
.navbar > .container {
width:auto;
}
But this margin still remains. I also tried to
<Navbar style={{ width: "auto" }}>
<Navbar.Header>
...
But no success. My complete code:
<Row>
<Navbar>
<Navbar.Header>
<Navbar.Brand className="lang-de">
<a href="/" />
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav pullRight>
<NavItem eventKey={1} href="#">
Impressum
</NavItem>
</Nav>
</Navbar.Collapse>
</Navbar>
</Row>

you can use only React Bootstrap Fixed top
<Navbar fixed="top" />
It will auto create the CSS below:
.fixed-top {
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: 1030;
}
You can see the this and another positions in documentation here

In your css, try the following:
.navbar > .container {
width:auto!important;
}

Just add "fluid" next to Navbar on your code
<Row>
<Navbar fluid>
<Navbar.Header>
<Navbar.Brand className="lang-de">
<a href="/" />
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav pullRight>
<NavItem eventKey={1} href="#">
Impressum
</NavItem>
</Nav>
</Navbar.Collapse>
</Navbar>

If you are using the grid system you can set the Container to fluid
<Container fluid>
<NavBar />
<Row>
<div>Personal Digital Assistants</div>
<ProfileCard text="Hello" info='unknown' imageTag={AlexaImg}/>
<ProfileCard text="Sir" info='unknown' imageTag={CortanaImg}/>
<ProfileCard text="Google thing" info='known' imageTag={SiriImg}/>
</Row>
</Container>

Related

Center image in bootstrap navbar with uneven ends

I would like to center the brand logo in my page and it is currently to the side:
Here is my code:
export default function NavBar() {
return (
<Navbar bg='light' fixed='top' className='navbar py-1 '>
<Container>
<HiOutlineMenuAlt4 />
<Navbar.Brand className="justify-content-center">
<img src={publicgoodslogo} width="120" height="65" ></img>
</Navbar.Brand>
<Navbar.Collapse className="justify-content-end">
<Nav>
<Nav.Link><GoSearch /></Nav.Link>
</Nav>
<Navbar.Text>
Cart:
</Navbar.Text>
</Navbar.Collapse>
<Nav>
0
</Nav>
</Container>
</Navbar>
)
According to the docs I should just be able to use justify-content-center but that doesn't work. Is it because I need to wrap the menu icon in something?

CSS Code don't work on react.js centering width

Hi guys so I'm trying to create an web application using react-bootstrap and I wanted to change the width of my row and center it. I already make the css and js file but I cannot center the row. I tried moving my code to codesandbox and it work just fine. anyone know why ?
My code:
<Container fluid>
<Row className="roomfac fontReg">
<Col lg={3} className="text-center">
<img src="./Images/logofridge.png" alt="Logo 1"/>
<h3 className="fontSB">Fridge</h3>
</Col>
<Col lg={3} className="text-center">
<img src="./Images/logoAC.png" alt="Logo 2"/>
<h3 className="fontSB">AC</h3>
</Col>
<Col lg={3} className="text-center">
<img src="./Images/logowifi2.png" alt="Logo 3"/>
<h3 className="fontSB">Wifi</h3>
</Col>
<Col lg={3} className="text-center">
<img src="./Images/logotv.png" alt="Logo 4"/>
<h3 className="fontSB">TV</h3>
</Col>
</Row>
</Container>
My CSS Code:
.roomfac {
display: flex;
width: 60%;
justify-content: center;
margin: auto;
}
It is working for me too in chrome as well as edge, make sure whether your css files are included correctly or else try using inline css in jsx.
<Row style={{display:"flex",width: "60%",margin: "auto",justifyContent: "center"}} className="fontReg">

React Bootstrap - position sticky not working

I am using React Bootstrap and the class position-sticky doesn't work at all.
There is not overflow at all levels.
Any hints?
I found out the Container needs height specified.
Adding height: 100% to the parent and top: 0 to the child fixes the issue.
The reason is that the sticky rule uses the height of the parent to calculate its own position.
Using React Bootstrap the className h-100 can be used to set height: 100%
I hope this helps also others :)
<>
<Navbar
sticky="top"
collapseOnSelect
expand="lg"
bg="primary"
variant="dark"
>
<Container className="">
<Navbar.Brand as={Link} to="/">
<img height={"30px"} src={logo} alt="" />
</Navbar.Brand>
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
<Navbar.Collapse id="responsive-navbar-nav">
<Nav className="me-auto">
<Nav.Link href="home#services">Services</Nav.Link>
<Nav.Link href="home#experts">Experts</Nav.Link>
<NavDropdown title="Dropdown" id="collasible-nav-dropdown">
<NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.2">
Another action
</NavDropdown.Item>
<NavDropdown.Item href="#action/3.3">
Something
</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item href="#action/3.4">
Separated link
</NavDropdown.Item>
</NavDropdown>
</Nav>
<Nav>
<Nav.Link as={Link} to="/about">
About
</Nav.Link>
<Nav.Link as={Link} to="/login">
Log In
</Nav.Link>
</Nav>
</Navbar.Collapse>
</Container>
</Navbar>
</>

Reactstrap - Align navbar items to left and right

I currently have a navbar that has site navigation to the left and login/register/search to the right. When I add a button with an image, the layout of the navbar goes wrong and I cannot solve it. The elements that should be to the right, are aligning more the the middle.
This is my JSX:
<Navbar className="custNav navbar-inverse bg-primary" expand="md">
<NavbarBrand className='custNav' href="/">Brand</NavbarBrand>
<NavbarToggler onClick={this.toggle} />
<Collapse isOpen={this.state.isOpen} navbar>
<Nav className='mr-auto' navbar>
<NavItem className='custNav'>
<NavLink className='custNav' href="/comments">Home</NavLink>
</NavItem>
<NavItem className='custNav'>
<NavLink className='custNav' href="/report">About Us</NavLink>
</NavItem>
<NavItem>
<NavLink className='custNav' href="/report">Contact Us</NavLink>
</NavItem>
</Nav>
<Nav className='rightNav ml-auto' navbar>
<NavItem className=' custNav'>
<NavLink className='custNav' href="/comments">Login</NavLink>
</NavItem>
<NavItem className='custNav'>
<NavLink className='custNav' href="/report">Signup</NavLink>
</NavItem>
<FormGroup className='m-auto'>
<Input type="text" name="search" id="search" placeholder="Search" />
</FormGroup>
<Button className='searchBTN'><img className='btnIMG' src={searchIMG} alt=''/></Button>
</Nav>
</Collapse>
</Navbar>
My CSS:
body{
flex: 1;
}
.custNav{
background-color: #d4452d !important;
color: #f1f2ed !important;
}
.searchNav{
justify-content: center !important;
align-items: flex-start !important;
}
.searchBTN{
background-color: #d4452d !important;
color: #f1f2ed !important;
border-color: #d4452d;
width: 5%;
height: 5%;
}
.btnIMG{
position: relative;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
When I inspected the element, it appears to be the formgroup that is taking up all the room between the search button and the signup button.

React Bootstrap, Adding Hover Effects to NavItems

Brand new to React Bootstrap and I have been trying to add some custom styling to components.
I was able to remove the border radius from the Nav by using chrome inspector to find the classname, but I haven't been able to do the same for adding hover effects to my NavItems.
Here is my component.
<Navbar inverse collapseOnSelect className="nav-bar">
<Navbar.Header>
<Navbar.Brand>
efrt
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav>
<NavItem eventKey={1} href="#">Features</NavItem>
<NavItem eventKey={2} href="#">Who we Are</NavItem>
</Nav>
<Navbar.Form pullRight>
<UniversalButton style="primary" name='Login' />
</Navbar.Form>
<Nav pullRight>
<NavDropdown eventKey={3} title="Signup" id="basic-nav-dropdown">
<MenuItem eventKey={3.3}>Member</MenuItem>
<MenuItem divider />
<MenuItem eventKey={3.3}>Coach</MenuItem>
</NavDropdown>
</Nav>
</Navbar.Collapse>
</Navbar>
Copied over from Chrome inspector, I get the following as the class/elements where I want to make changes
.navbar-inverse .navbar-nav>li>a {
color: #9d9d9d;
}
When I try the following nothing happens. I tried adding custom class names with no effect either.
.navbar-inverse.navbar-nav>li>a:hover {
background: grey;
}
Any help appreciated :)!
You are missing a space after .navbar-inverse as .navbar-nav is a child:
.navbar-inverse .navbar-nav > li > a:hover {
background-color: gray;
}
Running example:
const { Navbar, Nav, NavItem, NavDropdown, MenuItem } = ReactBootstrap;
class App extends React.Component {
render() {
return (
<div>
<Navbar inverse collapseOnSelect className="nav-bar">
<Navbar.Header>
<Navbar.Brand>
efrt
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav>
<NavItem eventKey={1} href="#">
Features
</NavItem>
<NavItem eventKey={2} href="#">
Who we Are
</NavItem>
</Nav>
<Navbar.Form pullRight />
<Nav pullRight>
<NavDropdown eventKey={3} title="Signup" id="basic-nav-dropdown">
<MenuItem eventKey={3.3}>Member</MenuItem>
<MenuItem divider />
<MenuItem eventKey={3.3}>Coach</MenuItem>
</NavDropdown>
</Nav>
</Navbar.Collapse>
</Navbar>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById("root"));
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.31.3/react-bootstrap.min.js"></script>
<style>
.navbar-inverse .navbar-nav>li>a:hover {
background-color: green;
}
</style>
<div id="root"></div>

Resources