Reusing nested classes in LESS for sprite icon reuse - css

I have a .less file that contains classes to manage my sprites, such as:
.icon-16 {
background: url('/Content/images/app/icons-16.png') no-repeat top left;
width: 16px;
height: 16px;
&.about { background-position: 0px 0px; }
&.add { background-position: 0px -16px; }
&.add2 { background-position: 0px -32px; }
}
Later on in another .less file that is being linked, I need to set background images using these sprites.
I know it is possible to reuse a class like this:
.myClass {
.mySharedClass;
}
However I'm unable to work out the correct syntax to reuse a class in a nested hierarchy.
What I would like to do is something like the following:
.myClass {
.icon-16.about;
}
Giving the following output (from both .icon-16 and .about):
.myClass {
background: url('/Content/images/app/icons-16.png') no-repeat top left;
width: 16px;
height: 16px;
background-position: 0px 0px;
}
However this doesn't compile.
How can I achieve this nested class reuse?
If what I'm trying to do is not possible, what would be the best alternative to allow my
sprites to be used in other classes?

Specific Solution in This Case
I recommend making a master mixin to generate what you need, as you need it. Here is a solution that works with your current version of LESS 1.3.1:
LESS
.make-icon-16(#form: all) {
background: url('/Content/images/app/icons-16.png') no-repeat top left;
width: 16px;
height: 16px;
#about: 0px 0px;
#add: 0px -16px;
#add2: 0px -32px;
.makePositioning() when (#form = all) {
&.about { background-position: #about; }
&.add { background-position: #add; }
&.add2 { background-position: #add2; }
}
.makePositioning() when (#form = about) {
background-position: #about;
}
.makePositioning() when (#form = add) {
background-position: #add;
}
.makePositioning() when (#form = add2) {
background-position: #about;
}
.makePositioning();
}
//to generate icon classes
.icon-16 {
.make-icon-16;
}
//to include as you want in your class
.myClass {
.make-icon-16(about);
}
CSS Output
.icon-16 {
background: url('/Content/images/app/icons-16.png') no-repeat top left;
width: 16px;
height: 16px;
}
.icon-16.about {
background-position: 0px 0px;
}
.icon-16.add {
background-position: 0px -16px;
}
.icon-16.add2 {
background-position: 0px -32px;
}
.myClass {
background: url('/Content/images/app/icons-16.png') no-repeat top left;
width: 16px;
height: 16px;
background-position: 0px 0px;
}
If you don't need or want the actual .icon-16 classes, skip the step that makes those as it is not necessary for you to do that.
More General Solution?
If your icons have the right logic to them, then this can be more generalized to accommodate any size icon.
LESS
.make-icon(#form: all, #size: 16) {
background: url('/Content/images/app/icons-#{size}.png') no-repeat top left;
width: #size*1px;
height: #size*1px;
#about: 0px 0px;
#add: 0px (#size*-1px);
#add2: 0px (#size*-2px);
.makePositioning() when (#form = all) {
&.about { background-position: #about; }
&.add { background-position: #add; }
&.add2 { background-position: #add2; }
}
.makePositioning() when (#form = about) {
background-position: #about;
}
.makePositioning() when (#form = add) {
background-position: #add;
}
.makePositioning() when (#form = add2) {
background-position: #about;
}
.makePositioning();
}
//to generate icon classes for 32px size
.icon-32 {
.make-icon(all, 32);
}
CSS Output
.icon-32 {
background: url('/Content/images/app/icons-32.png') no-repeat top left;
width: 32px;
height: 32px;
}
.icon-32.about {
background-position: 0px 0px;
}
.icon-32.add {
background-position: 0px -32px;
}
.icon-32.add2 {
background-position: 0px -64px;
}

Related

How to move text in a input field?

So I'm in the process of learning and trying to make my own website. I have most of the form how I would like it but, I'm not sure how to clear the placeholder text away from the svg img so it will be legible. Some help would be greatly appreciated.
Thanks in advance.
Screen Capture of my problem. Also if you would tell me if it looks okay that would be great also!
.inputTagz{
padding-left: 25px;
cursor: text;
font-size: 14px;
float: left;
width: 100%;
font-size: px;
padding-top: 11px;
padding-bottom: 11px;
margin-top:20px;
font-weight:700;
}
#name{
background-image: url("man.svg");
background-size: 30px 30px;
background-position: 11px 8px;
background-repeat: no-repeat;
}
#emailPhone{
background-image: url("mail.svg");
background-size: 30px 30px;
background-position: 11px 8px;
background-repeat: no-repeat;
}
#password{
background-image: url("lock.svg");
background-size: 30px 30px;
background-position: 11px 8px;
background-repeat: no-repeat;
}
#formDiv{
width: 450px;
float: left;
left: 50%;
}
you need to edit your place holder, you can use this
#emastrong textilPhone {
background-image: url("mail.svg");
background-size: 30px 30px;
background-position: 11px 8px;
background-repeat: no-repeat;
}
#password {
background-image: url("lock.svg");
background-size: 30px 30px;
background-position: 11px 8px;
background-repeat: no-repeat;
}
#emailPhone::-webkit-input-placeholder {
padding-left: 25px;
}
#emailPhone::-moz-placeholder {
padding-left: 25px;
}
#emailPhone:-moz-placeholder { /* Older versions of Firefox */
padding-left: 25px;
}
#emailPhone:-ms-input-placeholder {
padding-left: 25px;
}
#password::-webkit-input-placeholder {
padding-left: 25px;
}
#password::-moz-placeholder {
padding-left: 25px;
}
#password:-moz-placeholder { /* Older versions of Firefox */
padding-left: 25px;
}
#password:-ms-input-placeholder {
padding-left: 25px;
}
please check the latest update about how to edit the placeholder. Thank you, I hope it will help you.
try this code...
try this
CSS
input[type=text] {
padding-left: 25px; //change it base on your desired output
}
see my sample fiddle
Hey guys thanks for answering my question I greatly appreciate it. The style I was looking for was the input-placeholder CSS3 tag.
I just added these sets of tags to my page. Hopefully I can help someone like me.
input::-webkit-input-placeholder {
padding-left:20px;
}
input::-moz-placeholder {
padding-left:20px;
}
input:-moz-placeholder { /* Older versions of Firefox */
padding-left:20px;
}
input:-ms-input-placeholder {
padding-left:20px;
}
Please add this css
input[type='text'] {
padding-left: 25px;
max-width : calc(100% - 25px);
}
From what I can understand, you just need to remove the 'placeholder'attribute from the code for all three inputs in the form you created.
For your reference click here
You can wrap it inside a parent div with separate img and input tag as follows:
<div id="some_id">
<img src="http://images.brighthub.com/a3/d/a3d2a3f5888d96ddde78d526bf9448dddf2fb4aa_small.jpg">
<input type="text" placeholder="Enter Your Name" id="some_text_id">
</div>
EXAMPLE FIDDLE

Kendo legacy theme's problems

This is a self-answered question
I'd like to use Kendo legacy themes for my app, since default themes are extremely ugly. I chose Office 2007 theme. I've included the following files:
<link href="~/Content/kendo/legacy/telerik.common.css" rel="stylesheet" />
<link href="~/Content/kendo/legacy/telerik.office2007.min.css" rel="stylesheet" />
I came across several problems with this themes that I'm not able to get ride of them and any help is appreciated.
Aligning buttons. Custom buttons are higher in the grid than the Grid's buttons.
Paging. Current page's number is shown in the corner. Also pagination's buttons are reverse, and page number's box is too big.
Multi select's wheel doesn't stop, even after loading items!
And finally, window's minimize button isn't visible.
This is the CSS I have used for buttons:
.k-grid .k-button{
width: 10px;
min-width: 10px !important;
}
.k-grid-custom,
.k-grid-custom:hover{
background-image: url('/Content/Images/Icon/icon.png');
height: 20px;
background-position: center;
background-repeat: no-repeat;
}
.k-edit{
background-image: url('/Content/Images/Icon/Edit.png');
background-position: 0 0 ;
}
Well, I worked around the multiselect's problem with robbing some of CSS from kendo.common.css.
.k-multiselect-wrap {
position: relative;
border-width: 0;
border-style: solid;
border-radius: 4px;
border-color: #c5c5c5;
background-color: #FFF;
min-height: 2.04em;
}
.k-multiselect-wrap .k-input {
background-color: transparent;
height: 1.31em;
line-height: 1.31em;
padding: .18em 0;
text-indent: .33em;
border: 0;
margin: 1px 0 0;
float: left;
}
.k-multiselect-wrap li {
margin: 1px 0 1px 1px;
padding: .1em 1.6em .1em .4em;
line-height: 1.5em;
float: left;
position: relative;
}
.k-autocomplete .k-loading, .k-multiselect .k-loading {
position: absolute;
right: 3px;
bottom: 4px;
}
.k-multiselect .k-loading-hidden {
visibility: hidden;
}
.k-multiselect-wrap .k-select {
position: absolute;
top: 0;
bottom: 0;
right: 0;
padding: .1em .2em;
}
You can hide current page's number:
.k-pager-numbers .k-current-page {
display: none;
}
Page numbers' size:
.k-pager-wrap .k-dropdown {
width: 4.500em;
}
For pagination's arrows, if you're using left-to-right you won't have any problem. In case you're using right-to-left, k-rtl, replace following CSS in telerik.common.css, line #230:
.k-i-seek-w { background-position: -48px -192px; }
.k-i-arrow-w { background-position: -32px -192px; }
.k-i-arrow-e { background-position: -16px -192px; }
.k-i-seek-e { background-position: 0 -192px; }
.k-state-disabled .k-i-seek-w { background-position: -48px -208px; }
.k-state-disabled .k-i-arrow-w { background-position: -32px -208px; }
.k-state-disabled .k-i-arrow-e { background-position: -16px -208px; }
.k-state-disabled .k-i-seek-e { background-position: 0 -208px; }
.k-state-hover .k-i-seek-w { background-position: -48px -224px; }
.k-state-hover .k-i-arrow-w { background-position: -32px -224px; }
.k-state-hover .k-i-arrow-e { background-position: -16px -224px; }
.k-state-hover .k-i-seek-e { background-position: 0 -224px; }
For the minimize button in Kendo Window, it seems they forgot to add the CSS!
.k-i-minimize {background-position: -32px -368px; }
Use the following CSS to align custom buttons with grid's buttons.
.k-grid .k-button {
vertical-align: bottom;
}

CSS. Custom (x, y) positions for the each button from for-loop

So I have 24 buttons, now It looks like:
It should be something like this (I mean position of the buttons)
Here is my button's code:
$info = getdate();
$date = $info['mday'];
for($i=1;$i<=24;$i++)
{
if($i==$date)
{
Echo "<input type='button' class='imgClass' onclick='issokantisLangas();' value='".$i."' src='deze.png'/>";
}
else
{
Echo "<input type='button' class='imgClass1' src='deze.png' value='".$i."' disabled />";
}
}
Here is the CSS of the buttons:
<style type="text/css">
.imgClass {
background-image: url(deze.png);
background-position: 0px 0px;
background-repeat: no-repeat;
background-size:100% 100%;
width: 60px;
height: 60px;
border: 0px;
color:#ed1c24;
font-weight:bold;
font-size:20px;
}
.imgClass:hover{
background-position: 0px 0px;
border: 2px solid white;
}
.imgClass:active{
background-position: 0px 0px;
}
.imgClass1 {
background-image: url(deze.png);
background-position: 0px 0px;
background-repeat: no-repeat;
background-size:100% 100%;
margin: 10px 10px 10px 10px;
width: 60px;
height: 60px;
border: 0px;
color:#ed1c24;
font-weight:bold;
font-size:20px;
}
</style>
When I change this line margin: 10px 10px 10px 10px; with different numbers all the buttons move similar. I need to set for each button specific position. How to do that? Thank you.
You have to make the div which has the blue background and contains all the number boxes to have relative position using position:relative;, then the css of the number box imgClasses you have to add position:absolute; and when printing the tags via php, add the custom position yourself. Take a look at the style in the following code:
for($i=1;$i<=24;$i++)
{
if($i==$date)
{
Echo "<input type='button' style="top: 35px; right: 400px;" class='imgClass' onclick='issokantisLangas();' value='".$i."' src='deze.png'/>";
}
else
{
Echo "<input type='button' style="top: 35px; right: 400px;" class='imgClass1' src='deze.png' value='".$i."' disabled />";
}
}

Vertical alignment of Images inside DIV

I am retrieving a bulk images through response and I need to arrange them inside a div tag and all the images are placing one below the other but I need to arrange them vertical (i.e. side by side)
So how do I do that?
And I followed this tutorial but I can arrange only text?
http://phrogz.net/CSS/vertical-align/index.html
Can anyone suggest me the right way?
Here is my code:
$('#showfilelist').append("<div id=" + file.id + "><a href='uploads/" +
file.target_name + "' target='_blank' rel='gallery'><img src='thumbs/" +
file.target_name + "' border='0'/></a> </div>");
Here is what I'm getting the result
Plupload Css:
/*
Plupload
------------------------------------------------------------------- */
.plupload_button {cursor: pointer;}
.plupload_wrapper {
font: normal 11px Verdana,sans-serif;
width: 100%;
}
.plupload .plupload_container input {width: 98%;}
.plupload .plupload_filelist_footer {border-width: 1px 0 0 0}
.plupload .plupload_filelist_header {border-width: 0 0 1px 0}
div.plupload .plupload_file {border-width: 0 0 1px 0}
div.plupload div.plupload_header {border-width: 0 0 1px 0; position: relative;}
.plupload_file .ui-icon {
cursor:pointer;
}
.plupload_header_content {
background-image: url('../img/plupload.png');
background-repeat: no-repeat;
background-position: 8px center;
min-height: 56px;
padding-left: 60px;
position:relative;
}
.plupload_header_content_bw {background-image: url('../img/plupload-bw.png');}
.plupload_header_title {
font: normal 18px sans-serif;
padding: 6px 0 3px;
}
.plupload_header_text {font: normal 12px sans-serif;}
.plupload_filelist,
.plupload_filelist_content {
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
-moz-user-select:none;
-webkit-user-select:none;
user-select:none;
}
.plupload_cell {padding: 8px 6px;}
.plupload_file {
border-left: none;
border-right: none;
}
.plupload .ui-sortable-helper,
.plupload .ui-sortable .plupload_file {
cursor:move;
}
.plupload_scroll {
max-height: 180px;
min-height: 168px;
_height: 168px;
overflow-y: auto;
}
.plupload_file_size, .plupload_file_status {text-align: right;}
.plupload_file_size, .plupload_file_status {width: 52px;}
.plupload_file_action {width: 16px;}
.plupload_file_name {
overflow: hidden;
padding-left: 10px;
}
.plupload_file_rename {
width:95%;
}
.plupload_progress {width: 60px;}
.plupload_progress_container {padding: 1px;}
/* Floats */
.plupload_right {float: right;}
.plupload_left {float: left;}
.plupload_clear,.plupload_clearer {clear: both;}
.plupload_clearer, .plupload_progress_bar {
display: block;
font-size: 0;
line-height: 0;
}
.plupload_clearer {height: 0;}
/* Misc */
.plupload_hidden {display: none;}
.plupload_droptext {
background: transparent;
text-align: center;
vertical-align: middle;
border: 0;
line-height: 165px;
}
.plupload_buttons, .plupload_upload_status {float: left}
.plupload_message {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
}
.plupload_message p {
padding:0.7em;
margin:0;
}
.plupload_message strong {
font-weight: bold;
}
plupload_message i {
font-style: italic;
}
.plupload_message p span.ui-icon {
float: left;
margin-right: 0.3em;
}
.plupload_header_content .ui-state-error,
.plupload_header_content .ui-state-highlight {
border:none;
}
.plupload_message_close {
position:absolute;
top:5px;
right:5px;
cursor:pointer;
}
.plupload .ui-sortable-placeholder {
height:35px;
}
I believe what you want is float: left; on your images.
Functioning example: http://jsfiddle.net/NeMDZ/2/ (Try moving the middle divider. Flexible layout is optional.)
The basic CSS:
div.imgContain {
overflow:hidden; /* Only necessary if you need to style the containing box.
Forces box to expand to content's height. */
}
div.imgContain img {
float:left;
}
All the other CSS is optional. Style at will.
img {
display: inline-box;
}
The images will set in the same line as long they fit there. Be very careful with padding and margin values.
Images are block-level elements by default, so you will need float: left on your images (or whatever element your image is contained in) if you want them to be side-by-side. If you want to start a new line, create a spacer element like:
.spacer {
clear: both;
}
and then add <div class="spacer"></div> where you want to break a line of images and start a new one. You may need other attributes on your spacer to work in old browsers.

Reduce sprite CSS with LESS?

The repition of code needed to produce CSS sprite effects seems to be a perfect case for the use of LESS.
But other than standardising the base ,hover and active increments (below) I can't see any further way to reduce the lines of code needed.
Can anyone suggest futher improvements:
#sprite-base:0px;
#sprite-hover:20px;
#sprite-active:40px;
.zone-user .region-user-second ul.text-size li.one a {
background: url("../img/sprite-accessibility.gif") no-repeat scroll 0px #sprite-base transparent;
}
.zone-user .region-user-second ul.text-size li.two a {
background: url("../img/sprite-accessibility.gif") no-repeat scroll -25px #sprite-base transparent;
}
etc ...
.zone-user .region-user-second ul.text-size li.one a:hover {
background: url("../img/sprite-accessibility.gif") no-repeat scroll 0px #sprite-base - #sprite-hover transparent;
}
.zone-user .region-user-second ul.text-size li.two a:hover {
background: url("../img/sprite-accessibility.gif") no-repeat scroll -25px #sprite-base - #sprite-hover transparent;
}
.zone-user .region-user-second ul.text-size li.one a.active {
background: url("../img/sprite-accessibility.gif") no-repeat scroll 0px #sprite-base - #sprite-active transparent;
}
.zone-user .region-user-second ul.text-size li.two a.active {
background: url("../img/sprite-accessibility.gif") no-repeat scroll -25px #sprite-base - #sprite-active transparent;
}
etc ...
You are failing to take advantage of one of the greatest features of LESS which is nesting your rules. It makes it easier to identify what is going on and in my opinion it is easier to read. Also you do write considerably less code. Here is how I would nest the rules you have shown in your question:
#sprite-base:0px;
#sprite-hover:20px;
#sprite-active:40px;
.zone-user .region-user-second ul.text-size li a {
background: url("../img/sprite-accessibility.gif") no-repeat scroll transparent;
&.one {
background-position: 0px #sprite-base;
&:hover {
background-position:0px (#sprite-base - #sprite-hover);
}
&.active {
background-position:0px (#sprite-base - #sprite-active);
}
}
&.two {
background-position:-25px #sprite-base;
&:hover {
background-position:-25px (#sprite-base - #sprite-hover);
}
&.active {
background-position:-25px (#sprite-base - #sprite-active);
}
}
}
Well this is what i would do. ( without LESS ..or More.. )
Working example: http://jsfiddle.net/lollero/gE7df/
CSS:
.Element {
background-image: url('path/to/img.jpg');
background-repeat: no-repeat;
}
.E-1 { background-position: 0px 0px; }
.E-1:hover { background-position: -20px 0px; }
.E-2 { background-position: 0px -25px; }
.E-2:hover { background-position: -20px -25px; }
.E-3 { background-position: 0px -55px; }
.E-3:hover { background-position: -20px -55px; }
HTML:
<div class="Element E-1"></div>
<div class="Element E-2"></div>
<div class="Element E-3"></div>
Edit: I think I had a brain fart or something.. I fixed a huge error in my css example.

Resources