Ho to Create a Horizontally Scrollable and Responsive Navbar Using React-Bootstrap - navbar

Code:
return(
<Navbar collapseOnSelect bg="dark" variant="dark" >
<Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
<Nav className="me-auto">
<Nav.Link href="#features">Features</Nav.Link>
<Nav.Link href="#pricing">Pricing</Nav.Link>
<Nav.Link href="#features">Features</Nav.Link>
<Nav.Link href="#pricing">Pricing</Nav.Link>
<Nav.Link href="#features">Features</Nav.Link>
<Nav.Link href="#pricing">Pricing</Nav.Link>
<Nav.Link href="#features">Features</Nav.Link>
<Nav.Link href="#pricing">Pricing</Nav.Link>
<Nav.Link href="#features">Features</Nav.Link>
<Nav.Link href="#pricing">Pricing</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 href="#deets">More deets</Nav.Link>
<Nav.Link eventKey={2} href="#memes">
Dank memes
</Nav.Link>
</Nav>
</Navbar>
)
As you can see in the screenshot, items are cut off on the right.
Question 1: How can I fit (show all the items) the navbar within the screen size (by scaling the size up or down depending on the device size) without collapsing and without adding line breaks (no multiple lines)?
Question 2: The issue with resizing is the text would become too small to read if the nav items are too many and the device is very small. Option two: How can I make it so that the navbar can be scrolled through horizontally (with a button on the left and another button on the right)?
This is how the current scrolling behaviour looks like:
See the issues highlighted:

Here you go:
Basically using Navbar from react-bootstrap with horizontally scrollable is a bad idea. I implemented the same successfully but the risk of horizontally scrollable feature made the dropdowns (if you have) pop behind the division so it was not visible on the page.
Its known as overflow issue. That means you can't have overflow-x: scroll and overflow-y: visible at the same time on the same division. Here is the code that could help you
import { Dropdown } from "react-bootstrap";
const renderNavigationTabs = () => {
<Dropdown alignRight key={id} navbar={true} id="page-navigation-drop-down-align-right"
className="pnt-navigation-navitem small-margin-item">
<Dropdown.Toggle id="page-navigation-drop-down-button" className={ "pnt-navigation-navlink " +
(item.children.find((element)=> element.link === history.location.pathname) ? "pnt-navigation-navlink-active" :
"pnt-navigation-navlink-deactive")
}
>
<span className="header-user-name">{item.title}</span>
<CaretDownFill />
</Dropdown.Toggle>
<Dropdown.Menu popperConfig={{ strategy: "fixed" }} id="header-menu-fixed">
{item.children.map((ele, index) => {
return (
<Dropdown.Item key={index} className="tsad-dropdown-item" onClick={()=> {
changeToNewLink(ele.link);
}}
>
{ele.title}
</Dropdown.Item>
);
})}
</Dropdown.Menu>
</Dropdown>
}
<div className="page-navigation-layout">
<button className="page-button-navigation left" onClick={(e)=> scrollLeft(e)}>
<<
</button>
<div id="scrollbar-page-navigation" className={"pnt-navbar" + (props.sideNavToggle
? " page-navigation-active" : "" )}>
<div className="mr-auto pnt-navigation">
{renderNavigationTabs()}
</div>
</div>
<button className="page-button-navigation right" onClick={(e)=> scrollRight(e)}>
>>
</button>
</div>
Styling:
$tabs-navbar-margin: calc(100vw / 15);
$links-margin: calc(100vw / 48);
$small-link-margin: calc(100vw / 288);
.page-navigation-layout {
width: stretch;
width: -webkit-fill-available; /* Mozilla-based browsers will ignore this. */
width: -moz-available; /* WebKit-based browsers will ignore this. */
display: flex;
align-items: flex-end;
justify-content: space-between;
border-bottom: 3px solid rgba(146, 153, 156, 0.05);
margin-bottom: 20px;
.pnt-navbar {
// margin: 30px $tabs-navbar-margin 20px $tabs-navbar-margin;
margin: 30px 20px 0 20px;
padding: 0;
width: calc(100vw - 204px);
max-width: initial;
transition: 0.5s ease;
overflow-x: scroll;
overflow-y: visible;
scroll-behavior: smooth;
scrollbar-color: #9b9b9b #eceef2;
scrollbar-width: none;
.pnt-navigation {
display: flex;
flex-direction: row;
justify-content: space-between;
.pnt-navigation-navitem {
margin-right: $links-margin;
margin-left: $links-margin;
white-space: nowrap;
.pnt-navigation-navlink {
font-size: 1.125em;
font-weight: 500;
padding: 8px 0px 15px 0px;
}
.pnt-navigation-navlink-deactive {
opacity: 0.6;
border: none;
color: var(--color);
}
.pnt-navigation-navlink-active {
opacity: 1;
border: none;
border-bottom: 3px solid var(--primary-color);
color: var(--color);
}
&:first-child {
margin-left: 0;
}
&:last-child {
margin-right: 0;
}
}
.small-margin-item {
margin-right: $small-link-margin;
margin-left: $small-link-margin;
}
.show.dropdown {
border-radius: 5px 5px 0 0;
background-color: var(--reports-page-background);
}
}
&::-webkit-scrollbar {
height: 0px;
}
&::-webkit-scrollbar-track {
height: 0px;
background-color: #eceef2;
border-radius: 180px;
}
&::-webkit-scrollbar-thumb {
height: 0px;
background-color: #9b9b9b;
border-radius: 180px;
}
}
.page-navigation-active {
width: calc(100vw - 494px);
}
.page-button-navigation {
margin-bottom: 21px;
min-height: 22px;
min-width: 22px;
max-width: 22px;
max-height: 22px;
border-radius: 5px;
border: none;
padding: 0;
background-color: var(--menu-item-highlight-color);
display: flex;
justify-content: center;
align-items: center;
svg {
height: 18px;
width: 14px;
color: var(--color);
}
}
.left {
margin-left: calc(100vw / 24);
}
.right {
margin-right: calc(100vw / 24);
}
}
#page-navigation-drop-down-align-right {
.btn-primary,
.btn-primary.dropdown-toggle,
#tsad-dropdown-basic:active,
#tsad-dropdown-basic:focus {
background-color: transparent;
color: var(--color);
box-shadow: none;
display: flex;
margin: auto;
align-items: center;
border-radius: 0;
font-size: 1.125em;
font-weight: 500;
padding: 15px 20px 15px 20px;
line-height: 22px;
svg {
margin-left: 10px;
}
}
.btn-primary::after {
display: none;
}
.dropdown-item.active,
.dropdown-item:active,
.dropdown-item:hover,
.dropdown-item:focus {
background-color: var(--menu-item-highlight-color);
color: var(--color);
}
}
#header-menu-fixed {
// position: fixed;
padding: 20px 0px;
a {
padding: 10px 30px;
opacity: 0.8;
color: var(--color);
font-family: Montserrat;
font-size: 1em;
line-height: 20px;
}
}
#media screen and (max-width: 1280px) {
.page-navigation-layout {
.page-navigation-active {
width: calc(100vw - 204px);
}
}
}
#media screen and (max-width: 540px) {
.page-navigation-layout {
.pnt-navbar {
width: calc(100vw - 84px - 100vw / 12);
.pnt-navigation {
.pnt-navigation-navitem {
.pnt-navigation-navlink {
font-size: 1em;
}
}
}
}
.left {
margin-left: calc(100vw / 24);
}
.right {
margin-right: calc(100vw / 24);
}
.page-navigation-active {
width: calc(100vw - 84px - 100vw / 12);
}
}
}
.navbar-nav {
flex: 1;
justify-content: space-around;
}
So basically its all about overflow-x and Dropdown from react-bootstrap provides popperConfig which works like a charm: https://react-bootstrap.github.io/components/dropdowns/#dropdown-menu-props

Related

How can I get the div#graph_div to start its margin after the div#roi-div and div#win-div elements?

Currently the graph_div is positioned above the win and roi divs. What is causing it to do this and how can I fix it? See below for the code and screenshots from the inspection in chrome.
The html is using JSX, if it looks off. I did not include the entire component as it is mainly irrelevant to the issue.
#import '../utils/variables.scss';
// Media Queries
// S and XS Screens
#media screen and (max-width: 768px){
#graph_div{
#graphCarousel{
bottom: 0;
left: 0;
width: 100%;
}
a.carousel-control-prev, a.carousel-control-next{
transform: scale(0.5);
}
div.carousel-indicators{
position: fixed;
top:515px;
> button{
background-color: $lineleader-red !important;
border-radius: .1rem;
}
}
a.carousel-control-prev, a.carousel-control-next{
position: absolute;
top: 275px;
}
}
}
// Global Styling
#header{
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 3rem;
background: #F9FBFC;
margin-bottom: 1rem;
h6{
float: right;
img{
height: 12px;
}
}
}
#stats_div, #criteria_div, #graph_div{
margin: 1rem .5rem;
padding: 10px;
}
div.sysView{
border: 1px solid #dcdfe0;
> div{
padding: 0rem 1rem;
}
.bet-div, .record-div, .crit-div{
margin-bottom: 1rem;
h5:after{
border-bottom: 2.5px solid #dcdfe0;
content: '';
display: block;
width: 1.5rem;
}
}
.bet-div, .record-div{
display: inline-block;
width: 50%;
}
.record-div{
float: right;
width: auto;
}
.win-div, .roi-div {
margin: 1rem;
display: flex;
align-items: center;
justify-content: center;
height: 75px; /* adjust this to desired height */
width: 75px; /* adjust this to desired width */
div{
text-align: center;
}
}
.win-div, .roi-div {
position: relative;
margin-bottom: 30px;
}
.win-div {
float: left;
}
.roi-div {
float: right;
}
.green{
border:1px solid #dcdfe0;
background-color: #ecfdf3;
color: #15b86c;
}
.red{
border:1px solid #dcdfe0;
background-color: #fbe9eb;
color: $lineleader-red;
}
.up-caret{
position: absolute;
top: -18px;
height: 18px;
}
.down-caret{
position: absolute;
bottom: -18px;
height: 18px;
}
}
<div className='page-section'>
<div className='sysView'>
<div id="header">
<h4>{system.name}</h4>
<h6 onClick={()=>{navigate('/mlb/beta', {state:{system:system, type:"edit"}})}}>Edit <img src={forward} alt=""/></h6>
</div>
<div className="bet-div">
<h5>Bet</h5>
{system.bet}
</div>
<div className="record-div">
<h5>Record</h5>
{system.p > 0 ? (system.w +"-"+system.l+"-"+system.p) : (system.w+"-"+system.l)}
</div>
<div className="crit-div">
<h5>Criteria</h5>
{system && system.criteria &&
(system.criteria.map((crit,i)=>{
return(
<p key={i}>{crit.label}</p>
)
}))
}
</div>
<div id={`win-div-${system._id}`} className="win-div">
{system.w/(system.w+system.l)*100 > 55 && <img id={`win-caret-${system._id}`} src={greenCaret} alt=""/>}
<div>
<h5>Win</h5>
{system.roi !== "NaN" ? (system.w/(system.w+system.l)*100).toFixed(2) : 0}%
</div>
{system.w/(system.w+system.l)*100 < 55 && <img id={`win-caret-${system._id}`} src={redCaret} alt=""/>}
</div>
<div id={`roi-div-${system._id}`} className="roi-div">
{system.roi > 0 && <img id={`roi-caret-${system._id}`} src={greenCaret} alt=""/>}
<div>
<h5>Roi</h5>
<span>{system.roi !== "NaN" ? system.roi : 0}% </span>
</div>
{system.roi < 0 && <img id={`roi-caret-${system._id}`} src={redCaret} alt=""/>}
</div>
<div id="graph_div">
<Carousel id="graphCarousel" variant="dark">
<Carousel.Item>
<WLChart sznWL={sznWL} />
</Carousel.Item>
<Carousel.Item>
<WinPerChart sznWL={sznWL} />
</Carousel.Item>
<Carousel.Item>
<ProfitChart sznWL={sznWL} />
</Carousel.Item>
</Carousel>
</div>
</div>
</div>

Not working show and hide accordion? where is problem

There is a "show preview" / "hide preview" button that appears in edit mode between the textarea and the preview container. This toggle allows, well, to show and hide this preview.
So of course I thought that would solve my problem, until I realize that all it does is to set a display: none on the container.
-> NOT WORKING :( WHY
.panel-item {
position: relative;
margin-top: -1px;
}
.panel-title {
cursor: pointer;
min-height: 110px;
border: 1px solid #FEE4CF;
border-radius: 6px;
padding: 15px 65px 15px 20px;
background-image: url(https://cdn.myshoptet.com/usr/www.manulo.cz/user/documents/upload/sablona/arrow-down.svg);
background-repeat: no-repeat;
background-position: right 20px center;
}
.flex-between-center {
display: flex;
align-items: center;
justify-content: space-between;
}
.panel-title > div:first-of-type {
max-width: 540px;
}
.flex-center-wrap {
display: flex;
align-items: center;
flex-wrap: wrap;
}
.in-doprava-a-platba .panel-title > div img {
margin-right: 20px;
}
img {
max-width: 100%;
height: auto;
}
.panel-body {
display: none;
padding: 0 20px 25px;
}
.type-page .content-wrapper-in ul {
list-style-type: none;
padding-left: 0;
}
.type-page .content-wrapper-in ul li {
font-size: 14px;
padding-left: 12px;
position: relative;
margin-bottom: 8px;
}
.type-page .content-wrapper-in ul li::before {
content: '';
width: 6px;
height: 6px;
display: block;
background-color: #AE6830;
border-radius: 50%;
position: absolute;
left: 0;
top: 6px;
}
.panel-show + .panel-body {
display: block;
}
#media screen and (max-width: 991px){
.panel-title {
background-size: 20px auto;
background-position: right 10px center;
padding: 15px 40px 15px 15px;
}
.panel-title > div > span, .panel-title > div > p {
font-size: 18px;
margin: 0 !important;
}
.panel-title.panel-show + .panel-body {
background-color: #FEE4CF;
display: block;
border: 1px solid #FEE4CF;
border-top: none;
border-radius: 0 0 6px 6px;
}
.panel-show + .panel-body {
display: block;
}
.panel-body {
padding: 0 20px 25px;
display: none;
}
.panel-body {
padding: 0 15px 25px;
}
}
<div class="panel-item">
<div class="panel-title flex-between-center">
<div class="flex-center-wrap"><img src="https://cdn.myshoptet.com/usr/446290.myshoptet.com/user/documents/upload/sablona/ppl.svg"> <span>PPL</span></div>
<div><span>99 Kč</span></div>
</div>
<div class="panel-body">
<ul>
<li>Když nakoupíte od 1900 Kč, máte dopravu zdarma. Jinak doručení stojí 99 Kč.</li>
<li>doručení a kontaktem na řidiče pro pohodlnější domluvu.</li>
<li>zkusí to ještě následující pracovní den. Následně váš balík uloží na nejbližší PPL zasielka.</li>
</ul>
</div>
</div>
where is problem not show and hide..
The quickest solution is
to change the .panel-title into an anchor tag <a>, making it an element that can receive focus.
and with CSS combinator selector +, the .panel-body can be toggled in/visible when the <a> loses/gets focus using the :focus pseudo selector.
I made those changes for you and added a second panel-item in <body> so you can see the accordion mechanism at work.
I also removed obsolete .panel-show references and cleaned up the #media.
Notice the two href="javascript:void(0)", without a href defined, an <a> cannot receive focus making the accordion fail to work...
Check the below snippet
/* NEW */
.panel-title {
/* To override standard <a> markup */
text-decoration: none;
color: currentColor;
}
.panel-title:focus+.panel-body {
/* make it visible */
display: block;
}
/**/
.panel-item {
position: relative;
margin-top: -1px;
}
.panel-title {
cursor: pointer;
min-height: 110px;
border: 1px solid #FEE4CF;
border-radius: 6px;
padding: 15px 65px 15px 20px;
background-image: url(https://cdn.myshoptet.com/usr/www.manulo.cz/user/documents/upload/sablona/arrow-down.svg);
background-repeat: no-repeat;
background-position: right 20px center;
}
.flex-between-center {
display: flex;
align-items: center;
justify-content: space-between;
}
.panel-title>div:first-of-type {
max-width: 540px;
}
.flex-center-wrap {
display: flex;
align-items: center;
flex-wrap: wrap;
}
.in-doprava-a-platba .panel-title>div img {
margin-right: 20px;
}
img {
max-width: 100%;
height: auto;
}
.panel-body {
display: none;
padding: 0 20px 25px;
}
.type-page .content-wrapper-in ul {
list-style-type: none;
padding-left: 0;
}
.type-page .content-wrapper-in ul li {
font-size: 14px;
padding-left: 12px;
position: relative;
margin-bottom: 8px;
}
.type-page .content-wrapper-in ul li::before {
content: '';
width: 6px;
height: 6px;
display: block;
background-color: #AE6830;
border-radius: 50%;
position: absolute;
left: 0;
top: 6px;
}
#media screen and (max-width: 991px) {
.panel-title {
background-size: 20px auto;
background-position: right 10px center;
padding: 15px 40px 15px 15px;
}
.panel-title>div>span,
.panel-title>div>p {
font-size: 18px;
margin: 0 !important;
}
/* Cleaned the clutter and removed obsolete code */
.panel-title:focus+.panel-body {
background-color: #FEE4CF;
display: block;
border: 1px solid #FEE4CF;
border-top: none;
border-radius: 0 0 6px 6px;
padding: 0 15px 25px;
}
/**/
}
<div class="panel-item">
<a class="panel-title flex-between-center" href="javascript:void(0)">
<div class="flex-center-wrap">
<img src="https://cdn.myshoptet.com/usr/446290.myshoptet.com/user/documents/upload/sablona/ppl.svg"> <span>PPL</span>
</div>
<div><span>99 Kč</span></div>
</a>
<div class="panel-body">
<ul>
<li>Když nakoupíte od 1900 Kč, máte dopravu zdarma. Jinak doručení stojí 99 Kč.</li>
<li>doručení a kontaktem na řidiče pro pohodlnější domluvu.</li>
<li>zkusí to ještě následující pracovní den. Následně váš balík uloží na nejbližší PPL zasielka.</li>
</ul>
</div>
<a class="panel-title flex-between-center" href="javascript:void(0)">
<div class="flex-center-wrap">
<img src="https://cdn.myshoptet.com/usr/446290.myshoptet.com/user/documents/upload/sablona/ppl.svg"> <span>PPL</span>
</div>
<div><span>99 Kč</span></div>
</a>
<div class="panel-body">
<ul>
<li>Když nakoupíte od 1900 Kč, máte dopravu zdarma. Jinak doručení stojí 99 Kč.</li>
<li>doručení a kontaktem na řidiče pro pohodlnější domluvu.</li>
<li>zkusí to ještě následující pracovní den. Následně váš balík uloží na nejbližší PPL zasielka.</li>
</ul>
</div>
</div>

turn div into link on mobile screen size

I have a navbar with some links. When I open the page with a small screen size a mobile menu replaces the default navbar.
When I open this mobile menu I want to turn the parent divs of the links into links too. Means when I click on this div I want to call the links route.
I provide a full working example of the mobile menu
$(document).ready(() => {
$("#btnMenu").click(() => {
toggleMenu();
});
$(".navbarLink").click(() => {
if ($("#navbarItems").hasClass("activeNavbar")) {
toggleMenu();
}
});
});
function toggleMenu() {
$("#navbarItems").toggleClass("activeNavbar");
toggleMenuBtn();
}
function toggleMenuBtn() {
$("#btnMenu").toggleClass("activeMenuBtn");
}
.link {
text-decoration: none;
}
body {
margin: 0;
}
#navbar {
height: 60px;
top: 0;
padding-left: 200px;
padding-right: 200px;
position: sticky;
background: #1e222a;
}
#navbarItems {
height: 100%;
display: flex;
align-items: center;
}
#logoLink {
display: flex;
align-items: center;
}
#navbarItems .navbarItemContainer:not(:first-child) {
margin-left: 30px;
}
.navbarItemContainer {
background: #1e222a;
}
.navbarLink {
font-weight: bold;
color: #ffffff;
}
.navbarLink:hover {
color: #3abcf3;
}
#btnMenuContainer {
height: 100%;
display: none;
}
#btnMenu {
cursor: pointer;
}
.menuBtnBar {
width: 35px;
height: 5px;
margin: 6px 0;
background-color: #ffffff;
transition: 0.4s;
}
.activeMenuBtn #barTop {
transform: rotate(-45deg) translate(-9px, 6px);
}
.activeMenuBtn #barCenter {
opacity: 0;
}
.activeMenuBtn #barBottom {
transform: rotate(45deg) translate(-8px, -8px);
}
#media(max-width: 1200px) {
#navbar {
padding-left: 150px;
padding-right: 150px;
}
}
#media(max-width: 1100px) {
#navbar {
padding-left: 0;
padding-right: 0;
}
#navbarItems .navbarItemContainer:not(:first-child) {
margin-left: 0;
}
#navbarItems .navbarItemContainer:not(:last-child) {
border-bottom: 1px solid #676767;
}
#btnMenuContainer {
display: flex;
align-items: center;
}
#btnMenu {
margin-left: 20px;
}
#navbarItems {
margin-left: 0;
display: none;
}
#logoLink {
display: inline-block;
}
.navbarItem {
width: 100%;
text-align: center;
padding: 30px 0;
}
#navbarItems.activeNavbar {
display: block;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="navbar">
<div id="btnMenuContainer">
<div id="btnMenu">
<div id="barTop" class="menuBtnBar"></div>
<div id="barCenter" class="menuBtnBar"></div>
<div id="barBottom" class="menuBtnBar"></div>
</div>
</div>
<div id="navbarItems">
<div class="navbarItemContainer">
<div class="navbarItem">
<a id="logoLink" class="link navbarLink" href="#">
<img class="img" src="http://icons.iconarchive.com/icons/ph03nyx/super-mario/128/Hat-Mario-icon.png">
</a>
</div>
</div>
<div class="navbarItemContainer">
<div class="navbarItem">
<a class="link navbarLink" href="#sectionTwo">
Link 2
</a>
</div>
</div>
<div class="navbarItemContainer">
<div class="navbarItem">
<a class="link navbarLink" href="#sectionThree">
Link 3
</a>
</div>
</div>
</div>
</div>
How can I expand the link in the center on its whole parent div when opening the mobile menu?
try simply replacing your mobile styles for
.navbarItem {
width: 100%;
text-align: center;
padding: 30px 0;
}
with
#navbarItems:first-child .navbarItem, .navbarLink {
width: 100%;
text-align: center;
padding: 30px 0;
}
this should apply those styles to the logo item as it currently does, and then apply the padding and width to the links themselves for the actual navbar links.
Moving the div into the <A> tag makes the whole space clickable on mobile.
<a class="link navbarLink" href="#sectionTwo">
<div class="navbarItem">
Link 2
</div>
</a>

Rendering a list of objects left to right in React

I am working on my first React project, a project as part of a Udacity course.
The task (or this part of it) is to initially render a series of book objects horizontally in three shelves.
I have managed to render the shelves and the books within them, however the books within each shelf are being rendered top to bottom rather than left to right.
One of the solutions I have seen posted is to use display: inline; in the CSS file but I have done that with no success.
How can I fix the code so that books within shelves are rendered horizontally?
I have included the ListBooks.js and App.css files. Let me know if I need to add anything else.
ListBooks.js
import React, { Component } from 'react';
import PropTypes from 'prop-types'
import './App.css'
const shelves = [
{
key: 'currentlyReading',
name: 'Currently Reading'
},
{
key: 'wantToRead',
name: 'Want To Read'
},
{
key: 'read',
name: 'Read'
}
];
class ListBooks extends Component {
static propTypes = {
books: PropTypes.array.isRequired
}
state = {
showSearchPage: false,
query: ''
}
render() {
const { books } = this.props
function getBooksForShelf(shelfKey) {
return books.filter(book => book.shelf === shelfKey);
}
return(
<div className="app">
{this.state.showSearchPage ? (
<div className="search-books">
<div className="search-books-bar">
<a className="close-search" onClick={() => this.setState({ showSearchPage: false })}>Close</a>
<div className="search-books-input-wrapper">
{/*
NOTES: The search from BooksAPI is limited to a particular set of search terms.
You can find these search terms here:
https://github.com/udacity/reactnd-project-myreads-starter/blob/master/SEARCH_TERMS.md
However, remember that the BooksAPI.search method DOES search by title or author. So, don't worry if
you don't find a specific author or title. Every search is limited by search terms.
*/}
<input type="text" placeholder="Search by title or author"/>
</div>
</div>
<div className="search-books-results">
<ol className="books-grid"></ol>
</div>
</div>
) : (
<div className="list-books">
<div className="list-books-title">
<h1>My Reads</h1>
</div>
<div className="list-books-content">
<div>
{ shelves.map((shelf) => (
<div key={shelf.key} className="bookshelf">
<h2 className="bookshelf-title">{shelf.name}</h2>
<div className="bookshelf-books">
<ol className="books-grid">
<li>
{ getBooksForShelf(shelf.key).map((book) => (
<div key={book.id} className="book">
<div className="book-top">
<div className="book-cover" style={{ width: 128, height: 193, backgroundImage: `url(${book.imageLinks.thumbnail})` }}></div>
<div className="book-shelf-changer">
<select>
<option value="none" disabled>Move to...</option>
<option value="currentlyReading">Currently Reading</option>
<option value="wantToRead">Want to Read</option>
<option value="read">Read</option>
<option value="none">None</option>
</select>
</div>
</div>
<div className="book-title">{book.title}</div>
<div className="book-authors">{book.author}</div>
</div>
))}
</li>
</ol>
</div>
</div>
)) }
</div>
</div>
<div className="open-search">
<a onClick={() => this.setState({ showSearchPage: true })}>Add a book</a>
</div>
</div>
)}
</div>
)
}
}
export default ListBooks
App.css
html, body, .root {
height: 100%;
}
body {
line-height: 1.5;
}
body, .app {
background: white;
}
/* main page */
.list-books-title {
padding: 10px 0;
background: #2e7c31;
text-align: center;
}
.list-books-title h1 {
font-weight: 400;
margin: 0;
color: white;
}
.list-books-content {
padding: 0 0 80px;
flex: 1;
}
.bookshelf {
padding: 0 10px 20px;
}
#media (min-width: 600px) {
.bookshelf {
padding: 0 20px 40px;
}
}
.bookshelf-title {
border-bottom: 1px solid #dedede;
}
.bookshelf-books {
text-align: center;
}
.open-search {
position: fixed;
right: 25px;
bottom: 25px;
}
.open-search a {
display: block;
width: 50px;
height: 50px;
border-radius: 50%;
background: #2e7d32;
background-image: url('./icons/add.svg');
background-repeat: no-repeat;
background-position: center;
background-size: 28px;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
font-size: 0;
}
/* search page */
.search-books-bar {
position: fixed;
width: 100%;
top: 0;
left: 0;
z-index: 5;
display: flex;
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 0 6px rgba(0,0,0,0.23);
}
.search-books-input-wrapper {
flex: 1;
background: #e9e;
}
.search-books-bar input {
width: 100%;
padding: 15px 10px;
font-size: 1.25em;
border: none;
outline: none;
}
.close-search {
display: block;
top: 20px;
left: 15px;
width: 50px;
height: 53px;
background: white;
background-image: url('./icons/arrow-back.svg');
background-position: center;
background-repeat: no-repeat;
background-size: 28px;
font-size: 0;
}
.search-books-results {
padding: 80px 10px 20px;
}
/* books grid */
.books-grid {
list-style-type: none;
padding: 0;
margin: 0;
display: inline;
justify-content: center;
flex-wrap: wrap;
}
.books-grid li {
padding: 10px 15px;
text-align: left;
}
.book {
width: 140px;
}
.book-title,
.book-authors {
font-size: 0.8em;
}
.book-title {
margin-top: 10px;
}
.book-authors {
color: #999;
}
.book-top {
position: relative;
height: 200px;
display: flex;
align-items: flex-end;
}
.book-shelf-changer {
position: absolute;
right: 0;
bottom: -10px;
width: 40px;
height: 40px;
border-radius: 50%;
background: #60ac5d;
background-image: url('./icons/arrow-drop-down.svg');
background-repeat: no-repeat;
background-position: center;
background-size: 20px;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
.book-shelf-changer select {
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
}
/* book cover */
.book-cover {
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
background: #eee;
}
.book-cover-title {
padding: 20px 10px 0;
text-align: center;
font-size: 0.8em;
}
Try setting your shelf element, with display flex as it is suggested in your comments...
.list-books-content li {display: flex; flex-direction: row;}

Cover image with dynamic height CSS

I am trying to find solution for the problem.
I have following block
As you can image takes more space than content. But in general image looks nice.
I want to get the same behavior but to crop/cover image according to the text size. Currently this block doesn't have fixed height. So I guess it is impossible to get desired result without fixed height.
My html
<article id="post-313" class="col-md-12 l-post post post--short post-type--post">
<div class="l-post-thumbnail col-md-4 col-xs-12">
<div class="post-thumbnail">
<img src="http://martinsolutionsrd.com/wp-content/uploads/2016/05/para1.png" alt="Image for Remove all comments from your project" class="post-thumbnail__image">
</div>
</div>
<div class="l-post-description col-md-8 col-xs-12">
<div class="post-description">
<div class="post-title">
<h3 class="post-title__header">
<a class="post-title__link" href="#">Remove all comments from your project</a>
</h3>
</div>
<div class="post-meta">
<a href="#" class="post-meta__link is-first-item">
<span class="post-meta__icon fa fa-user"></span>
CROSP
</a>
<a href="#" class="post-meta__link">
<span class="post-meta__icon fa fa-calendar"></span>
June 27, 2016
</a>
<a href="#" class="post-meta__link">
<span class="post-meta__icon fa fa-comment"></span>
2
Comments
</a>
</div>
<div class="post-content">
<p class="post-content__text">
Sometimes you need to do such weird things like remove all comments from your project.
This may mean that you have reached the highest level of writing code, so no one need comments to understand written in the source files. Sometimes you need to do such weird things like remove all comments from your project.
This may mean that you have reached the highest level of writing code, so no one need comments to understand written in the source files.
</p>
</div>
<div class="post-footer">
<div class="post-categories">
<div class="post-categories__links-wrapper">
<span class="post-categories__icon fa fa-folder-open"></span>
<a href="http://crosp.net/category/software-development/regex/" class="post-categories__link is-last-item">
Regex
</a>
</div>
</div><!-- Inline block fix width
--><div class="post-more">
Read More
</div>
</div>
</div>
</div>
</article>
My CSS
/* Post module */
.l-post {
margin-bottom: 1.875em;
padding: 0 !important; }
#media only screen and (max-width: 560px) {
.l-post.post--short {
padding-right: 0;
padding-left: 0; } }
.l-post-thumbnail {
padding: 0;
margin: 0; }
/* Post content */
#media only screen and (max-width: 560px) {
#main-content {
padding: 0; } }
.l-sidebar {
margin-bottom: 2.5em; }
.l-header {
height: 90%;
width: 100%; }
#media only screen and (max-width: 560px) {
.l-header {
height: 100%; } }
#media only screen and (min-width: 1440px) {
.l-header {
height: 60%; } }
#media only screen and (min-width: 1600px) {
.l-header {
height: 40%; } }
.l-header-content {
font-size: 1.6rem;
display: table;
width: 100%;
position: relative; }
.l-header-content .header-content__wrapper {
width: 100%;
height: 100%;
display: table-cell;
vertical-align: middle; }
.l-footer {
position: relative;
padding: 3rem 0;
background-color: #081c24; }
.l-footer .social-icons {
padding-right: 1.875em;
text-align: right; }
#media only screen and (max-width: 992px) {
.l-footer .social-icons {
display: block;
margin: 2rem 0;
text-align: center; } }
.l-footer .copyright {
text-align: left; }
#media only screen and (max-width: 992px) {
.l-footer .copyright {
text-align: center;
display: block; } }
.l-blog-pagination {
text-align: center; }
.l-search-form {
width: 100%; }
.l-search-form .search-form__input {
width: 50%; }
#media only screen and (max-width: 480px) {
.l-search-form .search-form__input {
display: block;
width: 70%;
margin: 0 auto; } }
#media only screen and (max-width: 480px) {
.l-search-form .search-form__submit {
margin: 0.625em auto;
display: block; } }
/* Post module */
.post {
overflow: hidden;
background-color: #fff;
border: 1px solid #c8c8c8;
-moz-box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.19), 0 2px 10px 0 rgba(0, 0, 0, 0.19);
-webkit-box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.19), 0 2px 10px 0 rgba(0, 0, 0, 0.19);
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.19), 0 2px 10px 0 rgba(0, 0, 0, 0.19);
-webkit-transition: all 0.7s;
-moz-transition: all 0.7s;
-o-transition: all 0.7s;
transition: all 0.7s;
/* Image submodule */
/* Title submodule */
/* Content submodule */
/* Meta submodule */
/* Footer submodule */
/* Description submodule */
/* Categories submodule */
/* More submodule */
/* States */ }
.post-thumbnail {
overflow: hidden;
height: 100%; }
.post-thumbnail__image {
max-width: 150%;
width: 140%;
height: auto; }
.post-title {
display: block;
margin-bottom: 0.625em;
margin-top: 0.9375em; }
.post-title__header {
color: #52b3d9;
font-weight: 700; }
.post-title__link {
color: #337ab7; }
.post-content {
line-height: 1.4; }
.post-meta {
margin: 0.5625em 0;
color: #68c3a3; }
.post-meta__link {
white-space: nowrap;
margin-right: 0.75em;
color: #797e83; }
.post-meta__link:hover {
color: #52b3d9; }
.post-meta__icon {
font-size: 1.25em;
margin-right: 0.2em; }
.post-footer {
width: 100%;
padding: 0;
margin-top: 1.25em; }
.post-description {
padding: 0.3125em 1.5625em 1.5625em 0.625em; }
#media only screen and (max-width: 560px) {
.post-description {
padding-left: 0.3125em;
padding-right: 0.3125em; } }
.post-categories {
margin: 0;
width: 60%;
word-wrap: break-word;
vertical-align: middle;
display: inline-block; }
#media only screen and (max-width: 768px) {
.post-categories {
width: 100%;
display: block; } }
.post-categories__link {
color: #797e83; }
.post-categories__link:hover {
color: #52b3d9; }
.post-categories__link::after {
content: "/"; }
.post-categories__link.is-last-item::after {
content: ""; }
.post-categories__icon {
display: inline-block;
color: #797e83;
margin-right: 0.25em;
font-size: 1.25em; }
.post-categories__links-wrapper {
vertical-align: middle;
display: inline-block; }
.post-more {
margin: 0;
width: 40%;
display: inline-block;
text-align: right; }
#media only screen and (max-width: 768px) {
.post-more {
margin-top: 1.5rem;
width: 100%;
display: block;
text-align: center; } }
.post:hover {
-moz-box-shadow: 0 6px 15px 0 rgba(0, 0, 0, 0.19), 0 5px 17px 0 rgba(0, 0, 0, 0.19);
-webkit-box-shadow: 0 6px 15px 0 rgba(0, 0, 0, 0.19), 0 5px 17px 0 rgba(0, 0, 0, 0.19);
box-shadow: 0 6px 15px 0 rgba(0, 0, 0, 0.19), 0 5px 17px 0 rgba(0, 0, 0, 0.19); }
/* Post info module used in header mostly */
.post-info {
text-align: center;
padding: 1.25em 1.25em; }
.post-info__header {
text-align: center;
font-size: 1.375em;
color: #f7f7f7;
background-color: rgba(48, 56, 67, 0.6);
border: 1px solid #6e6e6e;
border-radius: 10px;
padding: 0.45455em 1.13636em;
display: inline-block;
-webkit-transition: all 0.7s;
-moz-transition: all 0.7s;
-o-transition: all 0.7s;
transition: all 0.7s; }
.post-info__header:hover {
border: 1px solid #52b3d9; }
#media only screen and (max-width: 560px) {
.post-info__header {
padding: 0.45455em 0.68182em; } }
.post-info__date-link {
color: #52b3d9; }
.post-info__date-link:visited, .post-info__date-link:active, .post-info__date-link:focus {
color: #52b3d9; }
.post-info__date-link:hover {
color: #68c3a3; }
.post-info__category-link {
color: #52b3d9; }
.post-info__category-link:visited, .post-info__category-link:active, .post-info__category-link:focus {
color: #52b3d9; }
.post-info__category-link:hover {
color: #68c3a3; }
You can find working example (open in fullscreen) JSFiddle
I tried to set fixed height, and set image properties to
&__image {
width: auto;
height: 100%;
}
But it produces following result. As you can see only top left part is visible.
I have only idea to make image absolute and set width and height to 120%, for instance in order to cover image. But I am not really want to make images absolute positions (get of normal flow).
Please suggest the best solution to get desired and nice looking result.
Thanks.
UPDATE
I am not big fan of bootstrap components, so I use only grid.
I am looking for pure css solution.
As you're using bootstrap, you should use bootstap's default Media object. Best solution. Check their documentation here : http://getbootstrap.com/components/#media
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="..." alt="...">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
...
</div>
</div>
Not sure if you mean that you want the image to have an equal height as the text div, but I made an equalHeight function for you in jsfiddle https://jsfiddle.net/ux6k02g9/3/
let me know if this is what you mean :-)
jquery code:
$(document).ready(function(){
if ($(window).width() >= 1){
equalHeight();
}
});
$(window).resize(function(){
if ($(window).width() >= 1){
equalHeight();
}
});
function equalHeight()
{
var tallest = 0;
$('.l-post-description').each(function() {
/*if ($(this).find('.article-text').height() > tallest) {
tallest = $(this).height();
} */
if($(this).height() > tallest){
tallest = $(this).height();
}
//$(this).find('.col .item').css('min-height', tallest + 'px');
});
console.log(tallest);
$('.post-thumbnail__image').css('height', tallest + 'px');
}
$(document).ready(function(){
if ($(window).width() >= 1){
equalHeightt();
}
});
$(window).resize(function(){
if ($(window).width() >= 1){
equalHeightt();
}
});
This is best done with just CSS and as little DOM as possible.
My favorite trick is to put the after element next to the siblings, adding dipslay: flex to the parent. Now set width: 200% for both children and left: -50% for :: after.
body{
overflow-x: hidden;
}
.gradient, .gradient img {
width: 200%;
height: clamp(20rem, 70vw, 60rem);
margin: 0;
overflow: hidden;
}
.gradient{
display: flex;
}
.gradient::after{
pointer-events: none;
content: "";
height: inherit;
object-fit: cover;
width: inherit;
display: block;
background: linear-gradient(180deg, #336b25, #aa9210 41.07%, #aa2f10 76.05%);
mix-blend-mode: screen;
position: relative;
top: 0;
left: -50%;
z-index: 3;
}
<div class="gradient">
<img src="https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg"/>
</div>