I've got several class names and they are all 99% identical - except the background image. The classname always matches the image filename:
Example (see .icon_hero_rank-19):
.brawler .rank.icon_hero_rank-19 {
background-image: url("/images/ranks/icon_hero_rank-19.png");
position: absolute;
top: 85%;
left: 0;
width: 40px;
height: 45px;
line-height: 45px;
background-size: contain;
display: inline-block;
text-align: center;
font-weight: normal;
vertical-align: middle;
font-family: "BrawlStarsDeputy";
color: white;
font-size: 1.5rem;
text-shadow: 0px 3px 2px rgba(0, 0, 0, 0.8);
letter-spacing: 1px;
z-index: 10;
}
The question:
So is there a way to reuse the class name as variable in my CSS or what do you recommend?
One can use predefined variable names for the selectors and for the CSS properties like this:
$icon-list: (
icon_hero_rank-00,
icon_hero_rank-19
);
#each $icon in $icon-list {
.brawler .rank.#{$icon}{
background-image: url("/images/ranks/#{$icon}.png");
position: absolute;
top: 85%;
left: 0;
width: 40px;
height: 45px;
line-height: 45px;
background-size: contain;
display: inline-block;
text-align: center;
font-weight: normal;
vertical-align: middle;
font-family: "BrawlStarsDeputy";
color: white;
font-size: 1.5rem;
text-shadow: 0px 3px 2px rgba(0, 0, 0, 0.8);
letter-spacing: 1px;
z-index: 10;
}
}
Sure, you can use for loop
Take a look at this
$string-template: "icon_hero_rank-";
$start: 0;
#for $i from 1 through 8 {
.brawler .rank.#{$string-template}#{$i+$start} {
background-image: url("/images/ranks/#{$string-template}#{$i+$start}.png");
position: absolute;
top: 85%;
left: 0;
width: 40px;
height: 45px;
line-height: 45px;
background-size: contain;
display: inline-block;
text-align: center;
font-weight: normal;
vertical-align: middle;
font-family: "BrawlStarsDeputy";
color: white;
font-size: 1.5rem;
text-shadow: 0px 3px 2px rgba(0, 0, 0, 0.8);
letter-spacing: 1px;
z-index: 10;
}
}
Building on the answer your already posted, kentor, you could considerably condense your compiled CSS by using attribute selectors to set all the shared styles only one time and then set the background image in the #each function.
.brawler div[class*="icon_hero_"].rank {
position: absolute;
top: 85%;
left: 0;
width: 40px;
height: 45px;
line-height: 45px;
background-size: contain;
display: inline-block;
text-align: center;
font-weight: normal;
vertical-align: middle;
font-family: "BrawlStarsDeputy";
color: white;
font-size: 1.5rem;
text-shadow: 0px 3px 2px rgba(0, 0, 0, 0.8);
letter-spacing: 1px;
z-index: 10;
}
$icon-list: (
rank-00,
rank-19
);
#each $icon in $icon-list {
.brawler div[class$="#{$icon}"].rank{
background-image: url("/images/ranks/#{$icon}.png");
}
}
That way, you don't end up with the shared styles repeated a bunch of times in your stylesheet.
Related
I have a header that needs to have a greeting div inside of it. And that div has to be styled with :before and :after. I cannot add it via HTML. But when you resize the window, everything gets messed up. And I have no idea how to stop it from happening, without changing the font-size.
Can someone please take a look and tell me if there's something I can do? Thank you!
.header {
background-image: url('http://lorempixel.com/1300/800/');
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
min-height: 765px;
}
.title {
position: absolute;
top: 50%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
padding: 0px 20px 7px 20px;
border: 1px solid #fff;
outline: 2px solid #000;
box-shadow: 0 0 15px 0 rgba(0, 0, 0, .375);
font-size: 3em;
font-weight: 700;
color: #fff;
line-height: 1.3;
}
.title:before {
font-family: FontAwesome;
content: "\f051";
font-size: 1.5em;
vertical-align: bottom;
}
.title:after {
content: "Hello hello";
position: absolute;
font-size: 17px;
font-weight: 400;
text-transform: uppercase;
display: block;
top: 15px;
left: 75px;
line-height: 1;
}
<div class="header">
<div class="title">
Hello
</div>
</div>
you may try this code, removed the absolute position :
.header {
background-image: url('http://lorempixel.com/1300/800/');
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
min-height: 765px;
text-align:center;
}
.title {
position: relative;
display:inline-block;
margin-top:15%;
padding: 0px 20px 7px 20px;
border: 1px solid #fff;
outline: 2px solid #000;
box-shadow: 0 0 15px 0 rgba(0, 0, 0, .375);
font-size: 3em;
font-weight: 700;
color: #fff;
line-height: 1.3;
}
.title:before {
font-family: FontAwesome;
content: "\f051";
font-size: 1.5em;
vertical-align: bottom;
}
.title:after {
content: "Hello hello";
position: absolute;
font-size: 17px;
font-weight: 400;
text-transform: uppercase;
display: block;
top: 15px;
left: 75px;
line-height: 1;
}
<div class="header">
<div class="title">
Hello
</div>
</div>
Please refer to this image as a visual aid for my question.
I want the text input with "Sindre", the other input, and the buttons, to be placed higher, so they vertically align with the Icehotel logo. How can I do this?
Here's my code...
HTML
<div id="header-content">
<br>
<a href="/index">
<img draggable="false" src="{url}/app/tpl/skins/{skin}/images/logo.gif" style="position:relative; margin-left: 20px; <div align=; color: #FA0000;margin-top: 15px;margin-left: 180px">
</a>
<input id="username" name="log_username" placeholder="Username" style="position:relative; margin-left: 20px;padding:5px;box-shadow:3px 3px 5px black;border: 0;width:250px;background: #3b8ba4;border-radius: 6px;color: #baedf5;" type="text">
<input id="password" name="log_password" placeholder="Password" style="position:relative;margin-left: 1px;padding:5px;box-shadow:3px 3px 5px black;border: 0;width:250px;background: #3b8ba4;border-radius: 6px;color: #baedf5;" type="password">
<a href="{url}/api.php">
<button class="login green" name="login" style="height:34px;" type="submit">Let's go!</button>
</a>
<a>
<button class="login red" style="height:34px; margin-left: 4px" type="sumbit">Forgot your password?</button>
</a>
</div>
CSS
pre, blockquote {
border: 1px solid #999;
page-break-inside: avoid
}
thead {
display: table-header-group
}
tr, img {
page-break-inside: avoid
}
img {
max-width: 100%!important
}
#page {
margin: .5cm
}
p, h2, h3 {
orphans: 3;
widows: 3
}
h2, h3 {
page-break-after: avoid
}
}
html {
height: 100%
}
body {
height: 100%;
margin: 0;
padding: 0;
color: #e0eff5;
background-attachment: fixed;
background-color: #013448;
background-image: url('http://localhost/app/tpl/skins/aura/habboweb/planet.png');
background-image: url('http://localhost/app/tpl/skins/aura/habboweb/planet.png'), -webkit-radial-gradient(190px 190px, circle farthest-side, #0297c8 0, #013448 480px);
background-image: url('http://localhost/app/tpl/skins/aura/habboweb/planet.png'), -moz-radial-gradient(190px 190px, circle farthest-side, #0297c8 0, #2D3877 480px);
, -ms-radial-gradient(190px 190px, circle farthest-side, #0297c8 0, #013448 480px);
, radial-gradient(circle farthest-side at 190px 190px, #0297c8 0, #013448 480px);
min-height: 755px
}
i, cite, em, var, address, dfn {
font-style: italic;
}
body {
font-family: "Ubuntu Condensed", Arial, serif;
font-weight: normal;
min-height: 0;
}
#footer a {
color: #a1b5c8;
text-decoration: none;
font-size: 13px;
}
body {
font-size: 1em;
line-height: 1.4;
}
.form__input, .form__select {
box-shadow: inset 0 2px 0 0 #9ebecc;
line-height: 1.2;
padding: 5px 12px;
width: 100%;
font-size: 16px;
}
.button b, .new-button i {
position: absolute;
display: block;
left: 2px;
top: 3px;
right: 2px;
height: 9px;
background-color: #4a9fb4;
z-index: 0
}
.button:hover, .new-button:hover {
background-color: #418491
}
.button:hover b, .new-button:hover i {
background-color: #46a9bf
}
.button span, .new-button b {
position: relative;
z-index: 100
}
.button:active, .button-active, .new-button:active {
left: 1px;
top: 1px;
box-shadow: 2px 2px rgba(0, 0, 0, 0.4)
}
.button.dimmed {
-ms-filter: "alpha(opacity=50)";
filter: alpha(opacity=50);
-moz-opacity: .5;
opacity: .50
}
.button.large {
height: 100px;
background-color: #c78800;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px solid #5f4416
}
.button.large:hover {
background-color: #d99b00
}
.button.large:hover b {
background-color: #f7ce00
}
.button.large b {
left: 4px;
top: 4px;
right: 4px;
height: 48px;
background-color: #f0bb00;
-webkit-border-radius: 2px 2px 0 0;
-moz-border-radius: 2px 2px 0 0;
border-radius: 2px 2px 0 0
}
.button.large span {
display: block;
font-size: 27px;
font-weight: bold;
text-transform: uppercase;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
line-height: 54px
}
.button.large span.sub {
display: block;
font-size: 17px;
font-weight: bold;
line-height: 42px;
text-transform: none
}
.button.large.not-so-large {
height: 48px
}
.button.large.not-so-large b {
height: 20px
}
.button.large.not-so-large span {
text-transform: none;
font-size: 22px;
line-height: 46px
}
header, footer {
width: 100%;
background: #101016;
background: rgba(16, 16, 22, 0.85);
position: fixed;
z-index: 999
}
#login-errors {
width: 100%;
height: 35px;
background-color: #c00;
color: #fff;
font-size: 17px;
font-weight: bold;
text-align: center;
line-height: 35px
}
#login-errors a {
color: #000
}
#footer-content {
float: left;
margin-left: 50px
}
#footer-content.partner-logo-present {
margin-left: 20px
}
#footer {
width: 100%;
min-width: 780px;
margin-top: 19px
}
header {
top: 0;
min-height: 99px
}
header #border-left {
position: absolute;
width: 500px;
height: 1px;
left: 0;
bottom: 0;
border-bottom: 1px solid #7aa3b9
}
header #border-right {
position: absolute;
width: 100%;
height: 1px;
left: 220px;
bottom: 0;
border-bottom: 1px solid #7aa3b9
}
footer {
height: 69px;
bottom: 0;
border-top: 1px solid #7aa3b9
}
#top-bar-triangle, #top-bar-triangle-border {
position: absolute;
left: 163px;
bottom: -29px
}
#top-bar-triangle {
font-size: 0;
height: 0;
line-height: 0;
border-style: solid;
float: left;
margin: 0;
border-color: #101016 transparent;
border-color: rgba(16, 16, 22, 0.85) transparent;
border-width: 29px 29px 0 29px
}
#top-bar-triangle-border {
background-image: url('http://localhost/images/new_index/images/v3/top_bar_arrow_border.out.png');
width: 58px;
height: 29px
}
header #habbo-logo {
position: absolute;
width: 190px;
height: 52px;
background-image: url('http://localhost/app/tpl/skins/aura/images/logo.png');
left: 32px;
top: 27px
}
#login-form-container {
position: relative
}
header form {
position: relative;
left: 239px;
top: 0;
width: 740px;
height: 99px
}
#login-columns {
position: relative
}
header form.captcha {
height: 200px
}
header form.captcha #login-recaptcha {
height: 103px;
margin-top: 8px
}
#login-recaptcha .field-error, #login-recaptcha #captcha-overlay {
display: none
}
#login-column-1 {
position: absolute;
left: 0;
top: 11px;
width: 205px;
height: 70px
}
#login-column-2 {
position: absolute;
left: 214px;
top: 11px;
width: 134px;
height: 70px
}
#login-column-3 {
position: absolute;
left: 358px;
top: 32px;
width: 205px;
height: 55px
}
Set vertical-align: middle; on the inputs and remove the margin-top from the inline styles in the logo <img> tag.
While I'm at this, though...General cleanup of this code is probably a good idea. I would like to caution you to avoid mixing inline styles and CSS. Also, the <br> tag should probably be replaced with padding - that line break and the inline styles are there only for design purposes and design is handled in CSS. Keeping as much design out of the HTML will help you (or someone else) easily make changes to this site later, if needed. The <img> tag's styles also include two margin-left values. I would remove one to avoid confusion. Lastly, I think you will want to remove <div align=; from the <img> tag's styles. As far as I know, this doesn't accomplish anything.
Hope that helps!
First of all, I'm running Meteor with neo64:Bootstrap and a custom theme.
I've got a button which shows like this after I make an arbitrary change in my css and it hotpushes the new code:
Then after a page reload the button looks like this:
Both times chrome shows this as the computed values:
-webkit-box-shadow: rgba(0, 0, 0, 0.227451) 0px 6px 10px 0px, rgba(0, 0, 0, 0.188235) 0px 10px 30px 0px;
-webkit-font-smoothing: antialiased;
-webkit-transform: matrix(1, 0, 0, 1, 0, 0);
background-color: rgb(255, 152, 0);
border-bottom-left-radius: 100%;
border-bottom-right-radius: 100%;
border-top-left-radius: 100%;
border-top-right-radius: 100%;
bottom: -28px;
box-shadow: rgba(0, 0, 0, 0.227451) 0px 6px 10px 0px, rgba(0, 0, 0, 0.188235) 0px 10px 30px 0px;
box-sizing: border-box;
color: rgb(255, 255, 255);
cursor: pointer;
display: inline-block;
font-family: FontAwesome;
font-size: 32px;
font-stretch: normal;
font-style: normal;
font-variant: normal;
font-weight: normal;
height: 56px;
line-height: 32px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
padding-bottom: 15px;
padding-left: 15px;
padding-right: 15px;
padding-top: 15px;
position: relative;
text-align: center;
text-rendering: auto;
transform: matrix(1, 0, 0, 1, 0, 0);
width: 41.140625px;
This is the code that makes up the button:
// BUTTONS
.fab {
margin: 0;
padding: 15px;
width: 56px;
height: 56px;
border-radius: 100%;
cursor: pointer;
transform: none;
& {
.shadow-z-3();
}
&:hover {
.shadow-z-4();
background-color: lighten(#brand-primary, 40%);
}
&:active {
.shadow-z-5();
}
&.fab-mini {
width: 40px;
height: 40px;
padding: 13px;
font-size: 15px;
}
&.fab-bottom {
position: relative;
bottom: -28px;
}
&.inverse {
background-color: #brand-primary;
color: #white;
&:hover {
background-color: lighten(#brand-primary, 10%);
}
}
i {
position: relative;
top: -5px;
}
}
The plus is a Font Awesome fa-plus.
These are the classes for my button (in Jade):
i.fa.fa-fw.fa-2x.fa-plus.fab.inverse.fab-bottom(data-toggle="modal"
data-target="#createModal" data-backdrop="static" data-keyboard="false")
Added the Jade of the page:
.row
.col-sm-6
.panel.panel-default
.panel-heading
h2.panel-title {{_ "dataA"}}
.list-group
.list-group-item
+each availableShifts
+availableShiftCard
.col-sm-6
.panel.panel-default
.panel-heading
h2.panel-title {{_ "dataB"}}
.list-group
.list-group-item
+each ownShifts
+ownShiftCard
.text-center
i.fa.fa-fw.fa-2x.fa-plus.fab.inverse.fab-bottom(data-toggle="modal"
data-target="#createModal" data-backdrop="static" data-keyboard="false")
What am I doing wrong?
.
Here is my link http://jsfiddle.net/ashadee/xhaLqvav/.
Html code
Eat your lunch<br>
CSS
a{
font-size: 1.2em;
white-space: normal;
}
a.rectangle
{
width: 70%;
height: 5%;
border: 1px solid black;
padding: 5%;
margin-top: 0%;
background-color: #FAFAFA;
opacity: 0.4;
display: block;
text-decoration: none;
text-align: center;
font-family: Comic Sans MS;
box-shadow: 10px 10px 5px #888888;
}
how will I make the design like the one in the image? Should I use canvas property.
demo - http://jsfiddle.net/victor_007/xhaLqvav/2/
use pseudo element :after and :before for styling right box and rounded
a {
font-size: 1.2em;
white-space: normal;
}
a.rectangle {
width: 70%;
height: 5%;
border: 2px solid black;
padding: 5%;
margin-top: 0%;
background-color: #FAFAFA;
opacity: 0.4;
display: block;
text-decoration: none;
text-align: center;
font-size: 32px;
font-family: Comic Sans MS;
box-shadow: 10px 10px 5px #888888;
position: relative;
}
a:before {
content: '';
border-right: 2px solid black;
height: 100%;
position: absolute;
background: orange;
width: 50px;
top: 0;
bottom: 0;
left: 0;
}
a:after {
content: '';
width: 30px;
height: 30px;
border-radius: 50%;
background: black;
position: absolute;
left: 35px;
top: 50%;
transform: translatey(-50%)
}
Stanford
<br>
I've encountered a problem that eludes me. I have an absolutely positioned pseudo-selector :before inside of a relatively positioned container that is positioned correctly in everything but IE9 and 10.
I've spent some time researching the problem and tried to implement thirtydot's solution mentioned here.
Here's a sample of the code: http://jsfiddle.net/66d25/20/
In all other browsers, the quotes appear correctly in the top left corner of the containing blockquote paragraph. In IE9/10 the quotes are improperly positioned in the middle top of the quote bubble.
I tried to add overflow:visible to the containing p tag but that didn't fix the problem. I have also included my scss below. Any insights into this problem would be greatly appreciated.
blockquote {
border-left: none;
padding: 0;
margin: 2em 0 1em 0;
position: relative;
&:after, &:before {
top: 100%;
border: solid transparent;
content: '';
height: 0;
width: 0;
position: absolute;
pointer-events: none;
display:block;
}
p {
color: shade($charcoal, 20%);
margin: 0;
background: #fff;
#include border-radius(5px);
#include box-shadow(inset 0 2px 0 rgba(70, 130, 180, 0.7), -5px -4px 25px rgba(0, 0, 0, 0.3));
font-size: emCalc(17px);
color: adjust-lightness($charcoal, 20%);
font-weight: 400;
line-height: 1.5em;
font-style: italic;
text-indent: 2em;
position: relative;
padding: 1em;
overflow:visible;
&:before {
content: "\201C";
font-family: serif;
font-style: normal;
font-weight: 700;
position: absolute;
font-size: 5.5em;
top: 15px;
left: -50px;
color: $blue;
text-shadow: 7px 14px 10px rgba(0, 0, 0, 0.1);
display: block;
height: 25px;
width: 25px;
}
}
footer {
padding-top: 1em;
cite {
text-align: right;
text-transform: uppercase;
font-weight: 700;
font-size: 1.25em;
font-style: normal;
color: $vblue;
text-shadow: 0 1px 1px rgba(255,255,255,0.7);
&:before {
content: '';
}
}
&:before {
content: '';
position: absolute;
border-style: solid;
border-width: 15px 15px 0;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
margin-left: -15px;
bottom: 33px;
left: 80%;
}
}
}
Removing:
p {
text-indent: 2em;
}
solves the issue on IE11: http://jsfiddle.net/66d25/22/
To position the quote back where you intend to place it can be achieved with:
p {
text-indent: 34px; /* font-size is 17px so 2em=34px*/
}
Demo: http://jsfiddle.net/66d25/23/
So the problem is with em unit and it's fine with pixels. Go figure why IE does that...