I have a project built with react and reactstrap (bootstrap 4 components). When I add the code
.col:nth-child(3) {
order: -1 !important;
}
it work great, but when I try to add in a media query it doesn't work.
#media only screen and (max-width: 700) {
.col:nth-child(3) {
order: -1 !important;
max-width: 700px
}}
what is going on here??
it is part of a nav built with reactStrap.
<Nav className='nav'>
<Col>
<Link to='/product'>
<NavItem className='nav-item'>Product</NavItem>
</Link>
</Col>
<Col>
<Link to='/brand'>
<NavItem className='nav-item'>Brands</NavItem>
</Link>
</Col>
<Col className='nav-column'>
<Link to='/'>
<NavItem className='nav-item nav-title'>
<h1 className='title'>
Makeup <span className='bomb'>Bomb</span>
</h1>
</NavItem>
</Link>
</Col>
<Col>
<Link to='/update'>
<NavItem className='nav-item'>Update</NavItem>
</Link>
</Col>
<Col>
<Link to='/about'>
<NavItem className='nav-item'>About</NavItem>
</Link>
</Col>
</Nav>
#media (max-width: 700px) {
.col:nth-child(3) {
order: -1 !important;
}
}
Try this instead, you haven't used PX and did not close the bracket
Here you go - Move screen resolution over 700px to see the color change.
Fiddle for screen visualization.
Nav :nth-child(1) {
order: -1 !important;
color: red;
}
#media only screen and (max-width: 700px) {
Nav :nth-child(1) {
order: -1 !important;
color: blue;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<Nav className='nav'>
<Col class="col">
<Link to='/product'>
<NavItem className='nav-item'>Product</NavItem>
</Link>
</Col>
<Col class="col">
<Link to='/brand'>
<NavItem className='nav-item'>Brands</NavItem>
</Link>
</Col>
<Col className='nav-column'>
<Link to='/'>
<NavItem className='nav-item nav-title'>
<h1 className='title'>
Makeup <span className='bomb'>Bomb</span>
</h1>
</NavItem>
</Link>
</Col>
<Col class="col">
<Link to='/update'>
<NavItem className='nav-item'>Update</NavItem>
</Link>
</Col>
<Col class="col">
<Link to='/about'>
<NavItem className='nav-item'>About</NavItem>
</Link>
</Col>
</Nav>
EDIT:
I decided to change the class .col to an id. This works.
#media only screen and (max-width: 700px) {
#col:nth-child(3) {
order: -1 !important;
}
}
Related
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">
I'm using react together with nextjs for SSR and boostrap. I have a component that loads bootstrap though cdn:
<Head>
<title>{title}</title>
<meta charSet="utf-8" />
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" />
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" />
</Head>
Now in my navbar I use the font Montserrat via style jsx which is the way in nextjs to change css:
import Link from "next/link";
class Navbar extends React.Component {
render() {
return (
<div>
<nav
className="navbar navbar-light navbar-expand-lg fixed-top bg-secondary text-uppercase"
id="mainNav"
>
<Link href="/">
<a className="navbar-brand js-scroll-trigger ">Navbar</a>
</Link>
<button
className="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarResponsive"
aria-controls="navbarResponsive"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon" />
</button>
<div className="collapse navbar-collapse" id="navbarResponsive">
<ul className="navbar-nav ml-auto">
<li className="nav-item mx-0 mx-lg-1">
<Link href="/about">
<a className="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger">
Blog
</a>
</Link>
</li>
<li className="nav-item mx-0 mx-lg-1">
<a
className="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger"
href="#"
>
More
</a>
</li>
<li className="nav-item mx-0 mx-lg-1">
<a
className="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger"
href="#"
>
About
</a>
</li>
</ul>
</div>
</nav>
<style jsx>{`
#media (min-width: 992px) {
#mainNav {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
transition: padding-top 0.3s, padding-bottom 0.3s;
}
}
.navbar-light .navbar-brand {
color: white;
font-weight: bold;
font-family: Montserrat;
font-size: 130%;
}
.navbar-light .navbar-nav .nav-link {
color: white;
font-family: Montserrat;
font-size: 90%;
font-weight: bold;
}
.bg-secondary {
background-color: #2c3e50 !important;
}
`}</style>
</div>
);
}
}
export default Navbar;
I used docker to put on mac the whole project in container so that I can switch between os without problems since I use a macbook pro as portable working station and my desktop windows pc for my home station.
Now everything works smoothly the only difference is that the fonts aren't really showing up like on mac. I checked this problem on Stackoverflow and someone wrote that if chrome doesn't find a font from google font it puts Times new Roman as default one like I see it as well. Now I don't really get why this happens since I load bootstrap I should have all font available here like on Mac. Maybe you could help me and tell me what I should change and why this happens.
Thanks so much guys!
Montserrat was not installed on my Windows machine and I needed to import the font family in the project. I thought I did that right with nextjs.. apprently not. However it works now locally.
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.
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>
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>