How to change look and feel of g:paginate - html

I'm using the g:paginate tag to create pagination links for my list page. I'd like to use the bootstrap pagination unordered list for the UI of the tag. How can I add that?
The bootstrap pagination tag works like this:
<ul class="pagination">
<li>«</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>»</li>
</ul>
I'm using the g:paginate tag like this
<g:paginate controller="mycontroller" action="list" total="${total}" />

You can use this tagLib for grails
https://github.com/Aasiz/bootspaginate

The best solution is to override the pagination tag with your own custom implementation (that overrides the default) if the structure provided doesn't suit your needs. Otherwise, obviously, styling it with CSS is an option.
In your case, since you want to use Bootstrap I highly recommend you look at what the bootstrap plugin does in regards to customizing the paignation tag for use with bootstrap. I've personally used something very similar with bootstrap with great success.

.step {
padding: 10px;
color: black;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
}
.nextLink {
padding: 10px;
color: black;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
}
.prevLink {
padding: 10px;
color: black;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
}
.currentStep {
padding: 10px;
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
.step.gap {
display: none;
}
.step:hover:not(.active) {
background-color: #ddd;
}
Used in grails 3.8
for <g:paginate next="Next" prev="Back" maxsteps="0" controller="Users" action="userv" total="${totalCount}" params="${params}"/>

I am new to grails and I ran into the same problem, trying to apply a style to my g:paginate. I solved it with JQuery.
First encapsulate my directive g:paginate within a div with id gPaginate this in order to get the children it has, that is, go to each of the elements of my directive.
<div id="gPaginate">
<g:paginate maxsteps="4" controller="reservations" action="searchReservations" total="${totalReservations}" max="5" params="${parameters}" prev="<" next=">" />
</div>
<nav id="pagination2" aria-label="Paginación">
<ul id='gPaginate2' class='pagination'></ul>
</nav>
Then I created my list and I was adding each child of my directive in another div with an ul to which its id is gPaginate2 to validate by adding a and validating if the item (child) contains the currentStep style then assign my class page- link active
In short it is to pass the items of the paginate directive to another one but with the style you want and finally hide the g: paginate I hope it serves you I leave you the JQuery code.
$(document).ready(function() {
$('#gPaginate').children().each(function(index,html) {
if($(this).hasClass('currentStep')){
$('#gPaginate2').append("<li id='item"+index+"' class='page-item active'>");
}else{
$('#gPaginate2').append("<li id='item"+index+"' class='page-item'>");
}
$(this).clone().appendTo($("#item"+index));
});
$('#gPaginate2').children().each(function() {
$(this).children('a').removeClass("step");
$(this).children('a').addClass("page-link");
$(this).children('span').removeClass("step gap");
$(this).children('span').addClass("page-link");
});
$('#gPaginate').hide();
});
result

One option is to use the pagination CSS present in main.CSS (asset:stylesheet) which is default provided by grails and has been written to work with g:paginate. It makes pagination look and feel far better without any extra effort .

Building on Rahul's answer, here's what i ended up with for anyone looking for options:
CSS:
.pagination span, .pagination a {
display: inline-block;
width: 20px;
height: 20px;
text-decoration: none;
background-color: whitesmoke;
transition: background-color .3s;
border: 1px solid #ddd;
padding: 5px;
text-align: center;
border-radius: 2px;
margin: 0 1px;
color: rgba(0, 0, 0, 0.54);
font-weight: bold;
}
.step.gap {
display: none;
/* ^ if we don't want to see the dots*/
}
.nextLink, .prevLink {
}
.pagination .currentStep {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
a:hover:not(.active) {
background-color: #ddd;
}
HTML:
<div class="pagination">
<g:paginate total="${totalCount}" next=">" prev="<"
controller="search" max="${max}"
params="${params}"></g:paginate>
</div>

Related

Best way to extend a SASS class with inner selector (subclass)

Im styling the following HTML to display messages:
<div className="message">
<div className="message_label">
A message
</div>
</div>
Using the following SCSS class:
.message {
margin: 10px;
border-radius: 10px;
border: 3px solid lightblue;
&_label {
color: #444;
padding: 5px;
}
}
Following BEM, I want to create another modificator version for error messages:
<div className="message--error">
<div className="message_label">
This is an error!
</div>
</div>
This version will just change the previous colors to red so I want to extend the previous SCSS class:
.message {
margin: 10px;
border-radius: 10px;
border: 3px solid lightblue;
&_label {
color: #444;
padding: 5px;
}
&--error {
#extend .message;
border: 3px solid red;
&_label {
color: red; // This is not working
}
}
}
But the selector message_label is not working, since its an inner selector and the #extend doesnt affect it, as explained in SCSS Docs. Whats the best way to extend a class including inner selector?
You can check the DEMO here.
The reason this isn't working is because all #extend does is share some css properties across different classes. So in this case, I would expect it to create a selector like:
.message, .message--error {
margin: 10px;
border-radius: 10px;
border: 3px solid lightblue;
}
.message_label {
color: #444;
padding: 5px;
}
.message--error {
border: 3px solid red;
}
.message--error_label {
color: red;
}
You can see at the bottom of the above css how your color: red might actually end up in a style sheet.
Finally, please do not format your scss like this. It would be a nightmare to maintain and understand.
Answer
My suggestion to answer your question is to just use .message and .message--error on the same element, similar to how Bootstrap does things

Exclude class from CSS property :not() doesn't work

I'm trying to make all links on the web page look in a specific way. However, it shouldn't apply to navbar links. I tried to exlude navbar using a:not(.navbar), however, it didn't work: the style applies to all links, including Link 1 in navbar:
html:
<body>
<div class=".navbar">
Link 1
</div>
Link 2
Link 3
</body>
css:
body a:not(.navbar) {
font-size: 100%;
color: black;
text-decoration: none !important;
border-bottom: 6px solid red;
}
body a:not(.navbar):hover {
border-bottom: none;
background-color: #80b3ff;
color: white;
text-decoration: none !important;
}
codepen
The .navbar class is applied to the container DIV of the navbar (not to the links), so your selectors need to be
div:not(.navbar) a { ... }
and
div:not(.navbar) a:hover
BUT you need a container div for the other links (without a class) for this to work, which I inserted in my snippet below. And you had a little error in your class attribute in HTML: It's class="navbar" - without the dot.
div:not(.navbar) a {
font-size: 100%;
color: black;
text-decoration: none !important;
border-bottom: 6px solid red;
}
div:not(.navbar) a:hover {
border-bottom: none;
background-color: #80b3ff;
color: white;
text-decoration: none !important;
}
<body>
<div class="navbar">
Link 1
</div>
<div>
Link 2
Link 3
</div>
</body>

What is causing uneven spacing between these buttons of mine?

I can't figure out what is causing the uneven spacing that you see in the image http://i.imgur.com/AZoXzYf.png (can't embed images yet ... sorry)
which comes from http://playclassicsnake.com/Scores. My relevant CSS is
.page-btn { background: #19FF19; color: #FFF; border: 0; border: 3px solid transparent; }
.page-btn.cur-page { border-color: #FFF; cursor: pointer; }
.page-btn + .page-btn { margin-left: 5px; }
and I've inspected the elements to make sure there's nothing fishy. What's the deal?
You have a new line character in your HTML just after your first button:
<button class="page-btn cur-page">1</button>
<button class="page-btn">2</button><button class="page-btn">3</button>
Make it all in 1 line and it will start to work without any extra spaces:
<button class="page-btn cur-page">1</button><button class="page-btn">2</button><button class="page-btn">3</button>
Your CSS is perfectly fine and doesn't need to be altered as mentioned by others..
Hi now try to this css
#page-btns-holder {
width: 80%;
margin-top: 12px;
font-size: 0;
}
div#page-btns-holder * {
font-size: 14px;
}
.page-btn {
background: #19FF19;
color: #FFF;
border: 0;
border: 3px solid transparent;
display: inline-block;
vertical-align: top;
font-size: 14px;
}
Define your btn display inline-block and remove space to inline-block element define your patent font-size:0; and child define font-size:14px; as like this i give you example
Remove Whitespace Between Inline-Block Elements
Try to make the font-size of the parent content 0, also try setting letter-spacing to 0.

removing strange clickboxes on image-link

I'm using bootstrap to make some buttons containing images.
But when I click them, a strange horizontal line appears, as well as a dotted bounding box on FF.
i have tried outline: none;,but it doesn't change anything...
how can i re-arrange the html (or edit the css) to fix this? I don't want those boxes (especially the horizontal one in the middle)
thanks
html
<div class="button frontbutton col-md-4">
<a href="/tips">
<img src="url.png" class="buttonPic">
<span data-i18n="buttons.tips">Tips</span>
</a>
</div>
css
.frontbutton {
padding: 15px;
}
.button {
display: inline-block;
color: #444;
border: 1px solid #CCC;
background: rgba(210, 210, 210, 0.62);
box-shadow: 0 0 5px -1px rgba(0,0,0,0.2);
margin: 0px;
cursor: pointer;
vertical-align: middle;
text-align: center;
}
a {
color: #199ACE;
outline: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
img.buttonPic {
width: 95%;
}
thanks
https://jsfiddle.net/pLkyqz0x/
UPDATE
while making the fiddle, i noticed what caused the gray bar (box shadow on a:active)
but the red box on FF remains....
This is the a:focus { } style. So you can remove it by setting a:focus { outline: none; } however this is not considered best practice as the focus style is an accessibility requirement. You should instead redefine focus styles that work for you. (For further reading on why this is bad practice: http://www.outlinenone.com/)

grouping CSS elements

I'm having a real hard time wrapping my brain around grouping different selectors and styles into one coherent setup.
I found this one set of CSS/HTML code that is exactly what I need (http://jsfiddle.net/joshnh/daFDn/) but I'm at a loss how I can utilize it with my setup.
body {
padding: 50px;
}
ul {
border: 1px solid #444;
display: inline-block;
height: 301px;
position: relative;
width: 400px;
}
li {
font: bold 16px/100px sans-serif;
height: 100px;
}
a {
border-right: 1px solid #444;
border-top: 1px solid #444;
color: red;
display: block;
text-align: center;
text-decoration: none;
width: 99px;
}
li:first-child a {
border-top: none;
}
li:nth-child(2) a {
color: blue;
}
li:nth-child(3) a {
color: green;
}
a:hover {
background: red;
color: #fff;
}
li:nth-child(2) a:hover {
background: blue;
color: #fff;
}
li:nth-child(3) a:hover {
background: green;
color: #fff;
}
img {
background: red;
display: none;
height: 301px;
position: absolute;
right: 0;
top: 0;
width: 300px;
}
li:nth-child(2) img {
background: blue;
}
li:nth-child(3) img {
background: green;
}
a:hover + img,
img:hover {
display: block;
}
I have a WordPress site, using Headway Themes (GUI theme creator). I want to create a section on one page that does exactly what the Fiddle does. I also don't want any other similar HTML elements to be affected by the CSS in that fiddle. (i.e. I use LI's elsewhere on the site and don't want them "font: bold 16px/100px sans-serif;" like this example).
For me, this truly baffles my mind and would seriously appreciate some guidance on how to structure this correctly.
I'm sure I need to create an ID (because this page will be unique to the rest of the site) but I'm not sure that this is correct syntax for an ID:
#switch ul {border: 1px solid #444;display: inline-block;height: 301px; position: relative;width: 400px;}, li {font: bold 16px/100px sans-serif;height: 100px;}
(as an example but is essentially what I want to do)
Just had a quick stab at this - As you say, you'll need to add something to limit those selectors to the scope you're interested in. An id is one way of doing this - in that case you would need to update your selectors to look something like: http://jsfiddle.net/2osg7a31/
Two things to look out for:
- ul#switch instead of #switch ul (since you're applying the styles to the ul that has an id of #switch, rather than a ul with a descendant of #switch)
- Make sure all styles for the descendants are limited to the #switch id too, not just those applied directly to the ul tag.
I'd suggest using a class instead of an id might be a better idea, since you're only adding the identifier to allow styling, rather than to try and identify the element uniquely: http://jsfiddle.net/0h54wseL/
Yes, you'll need to use and id or preferably a class which is better if you want to repeat that specific fiddle in other pages of your website. The way to do it is to add a .switch in every css entry for the list style. Then in your HTML put the whole ul inside a div with class="switch".
HTML:
<div class="switch">
<ul>
<li>
Item 1
<img src="" alt=""/>
</li>
<li>
Item 2
<img src="" alt=""/>
</li>
<li>
Item 3
<img src="" alt=""/>
</li>
</ul>
</div>
Here is the fiddle to explain : http://jsfiddle.net/zyd1822w/1/
Also check this link for more info about essential css selectors.
I hope this helps.