Flexbox to fill available space not working inside React.js component - reactjs

I am trying to set up a simple flexbox layout with content that expands between header and footer, based on this example. It works fine when I put the appropriate HTML directly in the page template, but fails when I render the exact same HTML inside a React component.
Here is the plain HTML:
<div class="box">
<div class="header">
<p><b>header</b></p>
</div>
<div class="content">
<p>
<b>content</b>
(fills remaining space)
</p>
</div>
<div class="footer">
<p><b>footer</b> (fixed height)</p>
</div>
</div>
My style.css is this in all cases:
html, body {
height: 100%;
}
.box {
display: flex;
flex-flow: column;
height: 100%;
}
.header {
flex: 0 1 auto;
}
.content {
flex: 1 1 auto;
}
.footer {
flex: 0 1 40px;
}
That works great when served as static HTML. I should get the same thing if I serve just an empty page with a single root div and render the same thing with React using this HTML:
<div id="root">
</div>
and this JS:
class Boxes extends React.Component {
render() {
return (
<div className="box">
<div className="header">
<p><b>header</b></p>
</div>
<div className="content">
<p>
<b>content</b>
(fills remaining space)
</p>
</div>
<div className="footer">
<p><b>footer</b> (fixed height)</p>
</div>
</div>
);
}
}
ReactDOM.render(
React.createElement(Boxes, null),
document.getElementById('root')
);
But the center "content" pane no longer fills the available vertical space when I render with React. Instead it just sizes to the content.
This is with React 15.4.2 on Chrome/Mac.

The problem is you have a wrapper <div id="root"> which doesn't have any css. You should make root expand to the full height, and then the divs inside will expand as well:
#root {
height: 100%;
}

You can try : { height : 100vh}

Related

multiple page print formatting using react to print overlaps contents in footer and header of second page

Iam using React js react-to-print If contents are more then footer overlapping in page content
I got the solution By using html table and the over lapping content with page footer is solved by the css code It is Mentioned in the code section.
<table>
<thead><tr><td>
<div class="header-space"> </div>
</td></tr></thead>
<tbody><tr><td>
<div class="content">...</div>
</td></tr></tbody>
<tfoot><tr><td>
<div class="footer-space"> </div>
</td></tr></tfoot>
</table>
<div class="header">...</div>
<div class="footer">...</div>
// CSS
.header, .header-space,
.footer, .footer-space {
height: 100px;
}
.header {
position: fixed;
top: 0;
}
.footer {
position: fixed;
bottom: 0;
}

align div elements vertically

helo guys hope you're doing good. so i have problem with css i don't really understand it but i'm pushing muself beyond my limits to make it work.
so i have these 4 cards:
so if you can see the subvalue and date are not vertically aligned properly( for example in the first card the M and 2 are not under each others) what i want is to vertically align them on the right side
code.js:
<div className={styles.card}>
<div className={styles.title}>
{title}
</div>
<div className={styles.valueAndUnit}>
<div className={styles.value}>
{value}
</div>
<div className={styles.unit}>
{unit}
</div>
</div>
<div className={styles.subValue}>
{subValue}
</div>
<div className={styles.date}>
{date}
</div>
</div>
css code:
.subValue {
text-align: right;
margin-right: 10px;
min-height:25px;
}
.date {
min-height:25px;
color:lightslategrey;
text-align: right;
}
hope you guys can help
just do in your class like this .
.subValue {
text-align: right;
min-height:25px;
}

applying css using class name or ID attribute of html element in reactjs component

Hi I am using UI component made of bootstrap which uses class name on the html element to define its look and feel. I have written html inside component class Home.js as follows :
import React, { Component } from 'react';
import style from './css/main.css';
export default class Home extends Component{
render(){
return(
<div class="wrapper" >
<nav id="sidebar" >
<div class="sidebar-header">
<h3>Collapsible Sidebar</h3>
</div>
<ul class="list-unstyled components" >
<li class="active" >Home</li>
<li>About</li>
<li>
Pages
<ul class="collapse list-unstyled" id="homeSubmenu">
<li>Page</li>
<li>Page</li>
<li>Page</li>
</ul>
<li>Portfolio</li>
<li>Contact</li>
</li>
</ul>
</nav>
<div id="content">
<button type="button" id="sidebarCollapse" class="btn btn-info navbar-btn">
<i class="glyphicon glyphicon-align-left"></i>
Toggle Sidebar
</button>
</div>
</div>
);
}
}
I have defined all css styling in main.css and it is been imported in home.js as can be seen in the source code above. My main.css if as following:
.header{
background: #F8F8F8;
font-size: 15px;
font-weight: 700;
text-align: right;
}
.wrapper {
display: flex;
align-items: stretch;
}
#sidebar {
min-width: 250px;
max-width: 250px;
min-height: 100vh;
}
#sidebar.active {
margin-left: -250px;
}
But I see, styles are not been applied as expected using class name or ID. Is there anyway where I can use existing UI component in reactjs without much change As I want to achieve in the above example.
Your style now is js object so in order to pass value from that object you need to write:
<div className={style.wrapper} >
Also you should use className instead of class in React JSX
Your component should use className and not class.
Since, in JSX, class and for are invalid attributes, we have been asked to use className and htmlFor

Layout structure - card layout and toolbar with angularjs md

How can I with use of AngularJS Material Design lib achieve page structure such as described in the official Layout structure guideline and exemplified in the screenshot below? I want to have centralised card breaking the edges of the page toolbar. Codepen example would be highly appreciated.
Edit: related thread: Angular Material Design layout
I figured I'd post this to help others trying to do the same thing with Materialize CSS. You can change the height of the nav-bar, and the size/placement of card.
Demo
HTML
<nav>
<div class="nav-wrapper">
<i class="material-icons">list</i>
</div>
<div class="nav-wrapper">
</div>
</nav>
<
<<div class="row" id="card-placement"> <!-- id added here -->
<div class="col s12 m8 offset-m2">
<div class="card grey lighten-5">
<div class="card-content grey-text text-darken-1">
<h5 class="head">Title</h5> <!-- class added here -->
<div class="divider"></div>
<p>Stuff goes here</p>
</div>
</div>
</div>
</div>
CSS
/* Moves card up into navbar */
#card-placement{
margin-top:-60px
}
/* Moves Title position up to be level with nav bottom */
.head {
margin-top: -2px;
}
nav {
color: #fff;
background-color: #ee6e73;
width: 100%;
height: 112px;
line-height: 56px;
}
.nav-wrapper {
margin-left: 20px;
}
You can easily do this with a little CSS
.card_position{
margin-top:-70px
}
Add this class to the card element.

Vertical inline-block?

Currently I have something like this. The "Page" and "Row" elements are created dynamically using javascript.
The problem rises when there are multiple Pages, and a Row in the Page 1 is deleted, for example. The empty space should be filled by the element that is below, if the empty space is at the end of the page, then the first element of the next page should fill the empty space, and so on. At the end it should look like this.
I can solve this rearranging/recreating the entire PageCont.
Is there a way I can achieve this using pure CSS? So the rearranging would be handled by the rendering engine of the browser.
Something like this inline-block but with vertical direction.
Any help is highly apreciated.
​HTML:
<div class="PageCont">
<div class="Page">
<div class="Row">1</div>
<div class="Row">2</div>
<div class="Row">3</div>
<div class="Row">4</div>
</div>
<div class="Page">
<div class="Row">5</div>
<div class="Row">6</div>
<div class="Row">7</div>
<div class="Row">8</div>
</div>
<div class="Page">
<div class="Row">9</div>
</div>
</div>​
CSS:
.PageCont
{
height: 300px;
width: 350px;
border:2px solid red
}
.Page
{
float:left;
margin-left:10px;
}
.Row
{
height:50px;
width:50px;
background-color:blue;
color:white;
margin-top:10px;
}
​
The operation could be successfully performed trivially if it included horizontal wrapping, with plain simple CSS. However since this case involves vertical wrapping javascript be necessary with your current implementation. If you were to use columns you wouldn't need the javascript and CSS is all that's needed.
Here is a fiddle where I've implemented it http://jsfiddle.net/eQvaZ/
The HTML is as follows:
<body>
<div class="pageCont">
<div class="Row">C1</div>
<div class="Row">C2</div>
<div class="Row" id="to-remove">C3</div>
<div class="Row">C4</div>
<div class="Row">C5</div>
<div class="Row">C6</div>
<div class="Row">C7</div>
</div>
<div>Removing C3 in 5 seconds...</div>
</body>
The CSS:
.pageCont{
column-count:2;
column-rule:0px;
-webkit-column-count: 2;
-webkit-column-rule: 0px;
-moz-column-count: 2;
-moz-column-rule: 0px;
padding:10px;
height: 250px;
width: 200px;
border:2px solid red
}
.Row {
height:50px;
width:50px;
background-color:blue;
color:white;
margin-bottom:10px;
}
The bit of JavaScript to remove an item:
setTimeout( function(){
var to_remove = document.getElementById('to-remove');
to_remove.parentNode.removeChild(to_remove);
}, 5000);
Let me know if you have any questions regarding this implementation.

Resources