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
Related
So I looked at how CSS "shares" its properties here : https://stackoverflow.com/a/199719/13707884
This was written in 2008 so I figured maybe CSS does allow for inheritance now & sure enough there is an article on it here :
https://coderwall.com/p/lqjd1w/css-class-inheritance-in-css
So I am trying out the code as mentioned in the link on "coderwall":
[class*=“row-“] {
border: 5px solid lightskyblue;
}
.row-1 {
color: blue;
}
.row-2 {
color: darkred;
}
<div class="row-1">AAA</div>
<div class="row-2">AAA</div>
However, this does not seem to be working. What could I be doing wrong here?
Your quotation marks in your first selector are invalid.
[class*="row-"] {
border: 5px solid lightskyblue;
}
.row-1 {
color: blue;
}
.row-2 {
color: darkred;
}
<div class="row-1">AAA</div>
<div class="row-2">AAA</div>
I am using less css for a basic website when i was trying to use &extend of less its showing no matches element when the element do exists.
I created a dummy environment same problem exists. Here is my code
style.less
#import 'style1.less';
#colorgreen: #00ff00;
#colorred: #ff0000;
#fontsize: 20px;
#bsolid: solid;
#bdash: dashed;
.container {
border: 1px#bsolid #ccc;
padding: 10px;
.myclass {
border: 1px#bdash #ccc;
padding: 10px;
h1 {
color: #colorred;
font-size: #fontsize;
}
p {
color: #colorred;
font-size: #fontsize;
}
}
}
.extend {
border: 1px solid #ccc;
padding: 10px;
h2 {
color: green
}
p {
&: extend(h2);
font-style: italic;
}
}
<div class="container">
<div class="myclass">
<h1>Second Heading</h1>
<p>LESS enables customizable, manageable and reusable style sheet for web site.</p>
</div>
<div class="importClass">
<p>This is imported CSS.</p>
</div>
<div class="extend">
<h2>First in extend</h2>
<p>Second in extend</p>
</div>
</div>
As the official Less Website indicates, the Less compiler looks at the compiled CSS selector when processing extend.
Essentially the extend looks at the compiled css, not the original less.
So, when trying to extend a nested selector, we should provide the full selector in the extend and not just the inner selector. In the example in question, the compiled CSS selector would be .extend h2 and so when the extend statement has only h2 provided as input, it wouldn't match and not output anything.
So, the below would compile successfully and work as per expectation.
.extend{
border: 1px solid #ccc;
padding: 10px;
h2{
color: green
}
p{
&:extend(.extend h2);
font-style: italic;
}
}
When compiled, it would result in the below CSS:
.extend {
border: 1px solid #ccc;
padding: 10px;
}
.extend h2,
.extend p {
color: green;
}
.extend p {
font-style: italic;
}
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.
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>
I have a simple "fill the gaps" excercise in html. There are gaps, looking like this:
Earth closest star is _ _ _ _.
The gaps are not supposed to be fillable on the computer - the document is supposed to be printed with the gaps enpty. But they have a content so, when howered, answers may be checked.
I use border-bottom property to make the gaps. There is a text filled in the gaps but it is white, so the user only can see it on hover.
The CSS:
span.gap {
color: white;
border-bottom: 1px solid black;
}
span.gap:hover {
color: gray;
}
The HTML:
Stephen Hawking is famous for his research of <span class="gap">black holes</span>.
Stackoverflow only helps you if you ask <span class="gap">simple questions</span>.
Browser seems to fix the color from white to black, so the gap content is visible in the printed document. How should I hide the text then?
I cannot use the visibility property, because the border must be visible.
Of all of the image replacement techniques, there are a few that will work without adding extra elements. All of them will require setting a width on the span if you want it to appear inline.
http://jsfiddle.net/TZD84/
span.gap {
display: inline-block;
width: 8em;
white-space: pre;
overflow: hidden;
border-bottom: 1px solid black;
text-indent: 110%;
}
span.gap:hover {
color: gray;
text-indent: 0;
}
If you need to support older browsers, there's always the negative text-indent method
http://jsfiddle.net/TZD84/1/
span.gap {
display: inline-block;
width: 8em;
overflow: hidden;
border-bottom: 1px solid black;
text-indent: -10em;
}
span.gap:hover {
color: gray;
text-indent: 0;
}
You can use CSS media types to handle different display/media situations. I.e add something like this to your CSS:
#media print { .gap { /* add your styles */ }}
Also, in combination with this you could add a separate span that would display only for print. Like:
HTML:
Stackoverflow only helps you if you ask
<span class="gap">simple questions</span>
<span class="print-gap"></span>.
CSS:
span.gap, span.print-gap {
color: white;
border-bottom: 1px solid black;
}
span.gap:hover {
color: gray;
}
#media screen {
span.print-gap { display: none; }
}
#media print {
span.gap { display: none; }
span.print-gap { display: inline-block; width: 100px; }
}