How to align PanelGrid to center? JSF-Primefaces - css

I know that there are many questions about this issue, but nothing worked for me properly.
I need to align my PanelGrid to center(horizontal).
this is my panelgrid
<p:panelGrid styleClass="panelGridCenter">
and my CSS:
.panelGridCenter td,.panelGridCenter tr {
text-align: center;
}
It just aligns the content to center, but not the panelGrid

The JSF <p:panelGrid> component renders a HTML <table> element which is by default a block level element. To center the block level element itself, you should set its horizontal margin to auto instead of attempting to center its inline contents.
.panelGridCenter {
margin: 0 auto;
}
See also:
Center a div in CSS

The above answer is technically correct but also incomplete.
If you want to center something like a div, the above technique of playing with the left and right margin as auto will work, provided that your DIV has limited width.
E.g. For you to start being any effect you would have to put something like a width=60%.
And then, once you realize you need to play with fixed widths... you immediately are prompted to the next question:
So what exactly should I type in as my fixed width?
That is why I believe the better answer for this question is:
CSS techniques like the one above, are OK for the small details on a web page.
But your coarse grained approach for centering anything on a web page should be to make use of a grid system.
Most grid systems use 12 cells.
If for example your grid system would be by default make 12 cells = 100% width.
You could center something by, for example placing your content to be centered in cells [5-8] leaving out as centurion space cells [1-4] and cells [9-12].
Here is an example based in prime faces grid system:
<h3 id="signInTitle" class="first">Sign in - FIXME - i18n</h3>
<form id="loginFormOld" (ngSubmit)="onLoginFormSubmit()">
<!-- (a) Start a grid system-->
<div class="ui-g ui-fluid">
<!-- (b) Eat the first four cells of the grid -->
<div class="ui-g-12 ui-md-4"></div>
<!-- (c) In the center location of the grid put in the Login form -->
<div class="ui-g-12 ui-md-4">
<div class="ui-inputgroup">
<span class="ui-inputgroup-addon"><i class="fa fa-user"></i></span>
<input id="emailInput" pInputText type="email" placeholder="Email" [(ngModel)]="eMail" name="eMail">
</div>
<div class="ui-inputgroup">
<span class="ui-inputgroup-addon"><i class="fa fa-key" aria-hidden="true"></i></span>
<input id="passwordInput" pInputText type="password" class="form-control" placeholder="Password" [(ngModel)]="password" name="password">
</div>
</div>
<!-- (d) Eat the rest of the first row of the grid without setting any contents -->
<div class="ui-g-12 ui-md-4"></div>
<!-- (e) Start the second row and eat the first four cells -->
<div class="ui-g-12 ui-md-4"></div>
<!-- (f) Position a form submit button on the fifth cell -->
<div class="ui-g-12 ui-md-1">
<button id="loginSubmit" pButton type="submit" label="Submit"></button>
</div>
</div>
</form>
The comments on the above form should make it pretty clear what I meant above.
The grid system will normally offer CSS classes to allow your UI to be working across multiple form factors of devices, although ... on this regard I am of the opinion that you can not make a good mobile UI using a desktop UI nor a good desktop UI using a mobile UI.
On my opinion you can get a good Tablet/Desktop UI cooked up, but you should write pages from scratch with the minimal an necessary contents for mobile. But that is a different discussion ... just to say, that the flex grid css classes will only take you so far.
A lot of potential in theory, much better than hard coding some arbitrary fixed length on your div elements ... but not a silver bullet for all of your problems either.

In case if you want right align
.rightAlign{
margin-left: auto;
}

Related

Pure css grid problem when changing the chrome screen size to mobile size

I try to use pure css grid system like explained in the documentation but I'm not able to make it work on desktop resolution and mobile like Pixel 2 resolution.
Instead of going on 2 lines like this :
I got this letter-spacing problem and the div goes on the same line :
Like to code example
<div class="pure-g">
<div class="pure-u-sm-1-1 pure-u-md-1-1 pure-u-lg-9-24">
<div class="l-box">
<span class="fa-stack">
<i class="fa fa-circle fa-stack-1And5x"></i>
<strong class="fa-stack-1x label-white">4</strong>
</span>
<label>Test:</label>
</div>
</div>
<div class="pure-u-sm-1-1 pure-u-md-1-1 pure-u-lg-15-24">
<div class="l-box">
<input class="pure-radio" id="montant" name="montant" type="text" value="">
</div>
</div>
</div>
There is a problem with your grid system and your media queries.
sm specifies the behavior only for screen sizes with a width of at least 568px. Below that your problem occurs.
To solve this add the pure-u-1-1 class respectively - you could say it defines your standard behavior. This alone won't work though because you make use of another stylesheet for normalizing your CSS. Put your normalizing CSS file in front of the other stylesheet in your code, otherwise it overrides some of your other CSS rules (keyword cascading style sheet). Always mention your normalizing CSS files first!
Also in this case the pure-u-md-1-1 class seems obsolete because it does not specify another behavior than pure-u-sm-1-1. The latter already defines the same behavior for all screen sizes of at least 568px.

Is it considered bad practice to put a '.col-*-*' class directly on an element in Bootstrap 3?

I'm working in a codebase that is using Bootstrap 3. According to their documentation this is how you create a basic grid structure:
<div class="row">
<div class="col-md-8">.col-md-8</div>
<div class="col-md-4">.col-md-4</div>
</div>
The code base I'm currently working in applies the grid structure in the following way.
<div class="form-group">
<label class="control-label col-sm-4"> Name<span class="text-danger">*</span> </label>
<div class="col-sm-8">
<input type="text" class="col-xs-10" value="Default" name="panel:expandedContentContainer" id="id9428">
</div>
</div>
I've never seen the grid applied in this way and I just want to make sure this won't cause problems down the road. I have two questions. Is it okay to use '.col-- without a row? And is it okay to put '.col--' directly on elements?
In Bootstrap 3, the .row class will apply a negative margin of ($grid-gutter-width / 2) to both the left and right.
The .col-* classes will apply a padding of ($grid-gutter-width / 2) to both the left and right.
Adding the .col-* class to the sub elements will not necessarily cause you problems, but unless you override the padding on .col-* through your own CSS you will find elements will be indented more that you were perhaps hoping for.
Yes, you can use '.col--' without a row. Then it just isn't vertical align. more information about that: http://www.helloerik.com/the-subtle-magic-behind-why-the-bootstrap-3-grid-works
And yes it is okay to put 'col--' directly on element. I don't have any bad experience with that.

Bootstrap page body child rows are pushing beyond parent

I understand the problem, as described and answered here.
I have quite a complicated layout with a sidebar navigation, a top navigation, a fluid-container and then page-title and page-body structure for each page. So just adding another container did not solve the problem as suggested in that answer.
Once I get into the page-body, all the rows are stretching 'outside' the parent page-body.
Notice I have added padding to the default container-fluid to 'pull' all the content in from each side of the page. Removing them does not fix it.
I've tried every change I can think of except removing the padding from the default row, because I'm pretty sure that is a no-no.
Anyone have any idea how to get those pesky form controls to stay 'inside' the page body?
There is two solution either give an additional class to row and manipulate its layout or don't use row use <div class="col-md-*" /> without parent .row class div as many times u want and use <div class="clearfix"> if you want to break forcefully to next row
EDIT:-
For example
<div class="row">
<div class="col-md-4">div1</div>
<div class="col-md-4">div2</div>
<div class="col-md-4">div3</div>
</div>
<div class="row">
<div class="col-md-4">div4</div>
<div class="col-md-4">div5</div>
<div class="col-md-4">div6</div>
</div>
The same can be achieved without .row class
<div class="col-md-4">div1</div>
<div class="col-md-4">div2</div>
<div class="col-md-4">div3</div>
<div class="clearfix">div4</div>
<div class="col-md-4">div5</div>
<div class="col-md-4">div6</div>
<div class="col-md-4">div1</div>

What would cause the responsive features on this site not work on mobile?

I am using a Bootstrap Template, that you can see the live version here - https://02dc74ce3e31e56a52ebcc845dca58e87283aabe.googledrive.com/host/0Bxbofwq0kd4ReUt2YWVOYmt3WVU/
If you view it on a mobile device, you will see how the responsiveness of Bootstrap kicks in.
But when I applied it to my Rails app, the mobile version does not look the same.
Any ideas what may be causing the discrepancy?
You can see the differences especially in both the main 'content' area with the story (notice on my version you see multiple stories in the main view, but on the original you only see 1 story and you can read the content more easily). You can also see it when you press the buttons.
Press the 'blue' button to the right top of the original and you will notice that the sidepanel comes out at the top like it should. But on my version it still comes to the side and everything is small.
What am I missing?
Thanks.
Add this to your application.html.erb:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
You have made too many changes while you are implementing the html in your rails view.
Like original header have following content :
<header class="header">
<hgroup class="pull-left">
<h1 class="site-title">
<a href="index.html" title="Von" rel="home">
<i class="fa fa-lemon-o"></i> Von
</a>
</h1>
</hgroup>
<div class="btn btn-primary pull-right" id="togglesidebar">
<i class="fa fa-bars"></i>
</div>
</header>
But in your view instead of <hgroup class="pull-left"> you have <hgroup class="pull-left col-xs-3 col-sm-3 col-md-3 col-lg-3"> and for <div class="btn btn-primary pull-right" id="togglesidebar"> you have <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 masthead-group-3"> also You added two more element in between these two element that destroyed your all header view.
You haven't used middle section from html design it seems you write your own. In your <header class="entry-header"> You created div instead of image tag. So every thing started distorted here. You include header footer section for each main section. But it's not big issue. Try remove div for confirmed and unconfirmed and use image instead. SO you will have proper view. Also remove row class from view that you added so view look more symmetric.
In your about section. When you try to see on mobile view. width of main container <div style="display: inline-block;" class="col-sm-3 sidebar" id="secondary"> is calculated on the basis of it's child element like <div class="about">. As your child element is form and it's having width less than the width displayed on form so remaining section not having proper background color #1c171e. So try increase width of you form control or <h4>Submit Report</h4> like <h4>Submit Report </h4> (kind of hack)under about section You will get proper view for this also.
Judging by your css file, you have loaded similar css multiple times. Consider the fact that, if everything else suggested by the people above has been corrected, the placement of the css files in the application scss file could overwrite your correct code.
I would also check the viewport meta tag as suggested above
If you try calling the CSS and JS being used as individual standalone files, instead of minified, do you still have this issue? Order of these files will matter too. I've seen lots of quirky issues when one JS gets loaded before another, same goes for CSS.
P.S. I would leave this information as a 'Comment' vs. Answer but I don't have enough stack overflow credit yet to do so ;-)
Make sure that if you have using rails g scaffold that you remove the scaffold.css file.

Foundation 5 div heavy

I have started work on a new project and decided to give Foundation 5 a bash to see what it's like. The first thing I noticed in the documentation when creating forms with horizontal fields is they use a large number of divs for styling. So I tried an example below (second example I tried it without divs):
<!-- Example with extra divs -->
<div class="row">
<div class="large-2 columns">
<label>Contact</label>
</div>
<div class="large-6 columns left">
<select></select>
</div>
</div>
<!-- Example without extra divs -->
<div class="row">
<label class="large-2 columns">Contact</label>
<select class="large-6 columns left"></select>
</div>
These both achieve the same thing with slightly different styling. I was wondering if anyone could explain why I would use the first one (follows foundation documentation) and not the other ... with less html! I am guessing it has something to do with how foundation is used and I am just not up to speed with it enough yet.
Thanks
Having <label> in <div> will give you lot of flexibility in styling. Defining a class for <label> will restrict your styling options. For a <div> you can define height, background color, border, width, background image, gradient fill, margins, padding, and lot more. Whereas giving <label> a class name would not let you do those styling. You could try it.
Basically, a <div> works as a box or container holding some content element in it, and that gives you lot of power and flexibility in styling. Whereas defining classes for content element doesn't give you that flexibility and power.

Resources