I'm wondering how I resize css loaders like resize it for mobile users cause I noticed the loaders don't resize for mobile users they just stay the same size no matter the size of the page, I want it to resize itself like text and stuff does. Here's an example of a css loader if you're confused:
http://jsfiddle.net/hdznz09a
#floatBarsG{
position:relative;
width:234px;
height:28px;
margin:auto;
margin-top: 13%;
}
.floatBarsG{
position:absolute;
top:0;
background-color:rgb(0,0,0);
width:28px;
height:28px;
animation-name:bounce_floatBarsG;
animation-duration:1.5s;
animation-direction:normal;
transform:scale(.3);
}
#floatBarsG_1{
left:0;
animation-delay:0.6s;
}
#floatBarsG_2{
left:29px;
animation-delay:0.75s;
}
#floatBarsG_3{
left:58px;
animation-delay:0.9s;
}
#floatBarsG_4{
left:88px;
animation-delay:1.05s;
}
#floatBarsG_5{
left:117px;
animation-delay:1.2s;
}
#floatBarsG_6{
left:146px;
animation-delay:1.35s;
}
#floatBarsG_7{
left:175px;
animation-delay:1.5s;
}
#floatBarsG_8{
left:205px;
animation-delay:1.64s;
}
#keyframes bounce_floatBarsG{
0%{
transform:scale(1);
background-color:rgb(0,0,0);
}
100%{
transform:scale(.3);
background-color:rgb(255,255,255);
}
}
<div id="floatBarsG">
<div id="floatBarsG_1" class="floatBarsG"></div>
<div id="floatBarsG_2" class="floatBarsG"></div>
<div id="floatBarsG_3" class="floatBarsG"></div>
<div id="floatBarsG_4" class="floatBarsG"></div>
<div id="floatBarsG_5" class="floatBarsG"></div>
<div id="floatBarsG_6" class="floatBarsG"></div>
<div id="floatBarsG_7" class="floatBarsG"></div>
<div id="floatBarsG_8" class="floatBarsG"></div>
</div>
You could use the:
transform: scale(0.5);
on your:
<div id="floatBarsG">
element like shown below
#floatBarsG{
position:absolute;
width: 33%;
height:28px;
margin-left: -117px;
left: 50%;
margin-top: 13%;
transform: scale(0.5);
}
in combination with media querys for your desired width's / devices
Articles about media querys:
https://wiki.selfhtml.org/wiki/CSS/Media_Queries
http://www.w3schools.com/cssref/css3_pr_mediaquery.asp
JSFIDDLE Example: http://jsfiddle.net/hdznz09a/3/ (Try resizing your browser window)
As said in comments:
use dynamic size like vh or vw
float:left; your minitinysquares and
don't to absolute and left values
don't use #ID, use classes instead (code reusability)
#floatBarsG{
position:absolute;
left:50%; top: 50%;
transform: translate(-50%, -50%);
}
.floatBarsG{
float:left;
background-color:rgb(0,0,0);
width:3vh; /* Use responsive units */
height:3vh;
min-width: 20px; /* prevent making them too small */
min-height: 20px;
animation:bounce_floatBarsG 1.5s infinite;
transform:scale(.3);
}
.floatBarsG._1{animation-delay:0.6s;}
.floatBarsG._2{animation-delay:0.75s;}
.floatBarsG._3{animation-delay:0.9s;}
.floatBarsG._4{animation-delay:1.05s;}
.floatBarsG._5{animation-delay:1.2s;}
.floatBarsG._6{animation-delay:1.35s;}
.floatBarsG._7{animation-delay:1.5s;}
.floatBarsG._8{animation-delay:1.64s;}
#keyframes bounce_floatBarsG{
from{
transform:scale(1);
background-color:rgb(0,0,0);
}
to{
transform:scale(.3);
background-color:rgb(255,255,255);
}
}
<div id="floatBarsG">
<div class="floatBarsG _1"></div>
<div class="floatBarsG _2"></div>
<div class="floatBarsG _3"></div>
<div class="floatBarsG _4"></div>
<div class="floatBarsG _5"></div>
<div class="floatBarsG _6"></div>
<div class="floatBarsG _7"></div>
<div class="floatBarsG _8"></div>
</div>
Related
So I'm not that great at programming sorry, but I use stack overflow and other sources to add site functionality and learn a little more each time. I'm using a Flexible Grid System to display my main content, specifically to re-arrange navigational buttons on the page.
This works great for me, but I've been using an ancient onMouseOver effect to display text when the user moves over an image button link and I'm not happy with the way it looks, and using flex creates issues with text legibility when the sizing gets small.
Ideally, I'd like to use a css overlay on my buttons so I can replace the image with text and format it to my liking. I've tried MANY different overlay solutions, but they all seem to use grid layouts and I can't get them to work with my flex layout for some reason.
Either the images get cropped, or the text can't completely cover the image due to layering issues, or (If I use the grid layout) I lose the flexible resizing capabilities that I really like on the site.
I'm hoping that this is a really simple fix. I'm assuming I need to add a container to my flex layout to place the content over the top of the image, but a hint to where to start would be really appreciated.
Here's a link to the buttons in the flex layout with no overlay:
https://megaauctions.net/megaflextest.htm
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MEGA Main Flex Buttons</title>
<link rel="stylesheet" href="css/test-code-buttons-no-action-compact.css" type="text/css"/>
</head>
<body>
<div class="buttoncontainer">
<buttonhomea class="buttonhomea column grad-yellow">
<a href=#><img src="http://www.megaauctions.net/images/btn-auctions.gif" /></a>
</buttonhomea>
<buttonhomeb class="buttonhomeb column grad-babyblue">
<img src="http://www.megaauctions.net/images/btn-buying.gif" />
</buttonhomeb>
<buttonhomec class="buttonhomec column grad-salmon">
<img src="http://www.megaauctions.net/images/btn-selling.gif" />
</buttonhomec>
</div>
</body>
</html>
and the CSS...
.buttoncontainer {
margin: 0 auto;
top: 0px;
display: flex;
position: relative;
flex-wrap: wrap;
justify-content: space-evenly;
text-align: center;
background: url('http://www.megaauctions.net/images/bkg-subs-deep.gif');
}
.column {
--columns: 12; /* number of columns in the grid system */
--width: var(--width-mobile, 0); /* width of the element */
padding: 0px;
margin: 9px 1px 2px 1px;
flex-basis: calc(var(--width) / var(--columns) * 94%);
}
/****** VIEWPORTS START ******/
#media (min-width: 350px) {
.column {
--width-mobile: var(--width-mobile);
--width: var(--width-mobile);
}
.buttonhomea img, .buttonhomeb img, .buttonhomec img {
width:100%;
max-width:157px;
}
}
#media (min-width: 512px) {
.column {
--width-tabletp: var(--width-tablet);
--width: var(--width-tabletp);
}
.buttonhomea img, .buttonhomeb img, .buttonhomec img {
width:100%;
max-width:157px;
}
}
#media (min-width: 650px) {
.column {
--width-tablet: var(--width-mobile);
--width: var(--width-tablet);
}
.buttonhomea img, .buttonhomeb img, .buttonhomec img {
width:100%;
max-width:300px;
}
}
#media (min-width: 900px) {
.column {
--width-desktop: var(--width-tablet);
--width: var(--width-desktop);
}
.buttonhomea img, .buttonhomeb img, .buttonhomec img {
width:100%;
max-width:315px;
}
}
/****** VIEWPORTS END ******/
.buttonhomea, .buttonhomeb, .buttonhomec {
--width-mobile: 12;
--width-tabletp: 4;
--width-tablet: 4;
--width-desktop: 4;
height: 100%;
}
.grad-yellow {
background-color:#f3d250;
background-image:linear-gradient(140deg,#f3d250,#EEA315);
}
.grad-babyblue {
background-color:#90CCF4;
background-image:linear-gradient(140deg,#90CCF4,#578FEE);
}
.grad-salmon {
background-color:#F78888;
background-image:linear-gradient(140deg,#F78888,#E7298C);
}
code in fiddle:
https://jsfiddle.net/mattcomps/gfb7k43h/
...and an overlay example of what I'm trying to achieve:
https://megaauctions.net/megaflextestbuttonaction.htm
<html>
<head>
<title>CSS Grid Cards</title>
<link rel="stylesheet" href="css/test-code-buttons-working-grid-compact.css" type="text/css"/>
</head>
<body>
<div class="container">
<section class="cards">
<a href="#" class="card grad-yellow">
<div class="card__overlay grad-yellow">
<div class="card__title">Auctions</div>
<div class="card__description">
Description goes here.
</div>
</div>
<div class="card__image" style="background-image:url('http://www.megaauctions.net/images/btn-auctions.gif')"></div>
<div class="card__content">
</div>
</a>
<a href="#" class="card grad-babyblue">
<div class="card__overlay grad-babyblue">
<div class="card__title">Buying</div>
<div class="card__description">
Description goes here.
</div>
</div>
<div class="card__image" style="background-image:url('http://www.megaauctions.net/images/btn-buying.gif')"></div>
<div class="card__content">
</div>
</a>
<a href="#" class="card grad-salmon">
<div class="card__overlay grad-salmon">
<div class="card__title">Selling</div>
<div class="card__description">
Description goes here.
</div>
</div>
<div class="card__image" style="background-image:url('http://www.megaauctions.net/images/btn-selling.gif')"></div>
<div class="card__content">
</div>
</a>
</section>
</div>
</body>
</html>
and the CSS...
.container{
background-image:url(http://www.megaauctions.net/images/bkg-subs-deep.gif)
}
.cards{
display:grid;
gap:1rem;
margin:0 auto;
padding:1rem;
}
#media (min-width:59em){
.cards{
grid-template-columns:repeat(2,1fr)
}
}
.card{
display:grid;
grid-template-columns:repeat(2,1fr);
grid-template-rows:300px 1fr auto;
color:#fff;
}
#media (min-width:31.25em){
.card{
grid-template-columns:160px (2,1fr);
grid-template-rows:1fr auto
}
}
#media (min-width:50em){
.card{
grid-template-columns:300px (2,1fr)
}
}
#media (min-width:59em){
.card{
grid-template-columns:160px(2,1fr)
}
}
.card__overlay{
min-height:300px;
display:none
}
#media (min-width:59em){
.card__overlay{
position:relative;
opacity:0;
display:grid;
justify-items:center;
align-items:center;
grid-column:1/4;
grid-row:1/3;
transition:opacity .3s ease-in-out}
}
.card:hover .card__overlay{
min-height:300px;
opacity:1
}
.card__content span{
display:inline-block;
border:2px solid #fff;
padding:1rem 3rem;
color:#fff;
}
.card__image{
grid-column:1/3;
grid-row:1/2;
min-height:157px;
background:no-repeat
}
#media (min-width:31.25em){
.card__image{
grid-column:1/4;
grid-row:1/3
}
}
.card__content{
grid-column:1/3;
grid-row:2/3;
padding:1.5rem}
#media (min-width:31.25em){
.card__content{
grid-column:2/4;
grid-row:1/2}
}
.grad-yellow {
background-color:#f3d250;
background-image:linear-gradient(140deg,#f3d250,#EEA315);
}
.grad-babyblue {
background-color:#90CCF4;
background-image:linear-gradient(140deg,#90CCF4,#578FEE);
}
.grad-salmon {
background-color:#F78888;
background-image:linear-gradient(140deg,#F78888,#E7298C);
}
code in fiddle:
https://jsfiddle.net/mattcomps/2eLzkwts/
Thanks!
Hope this answers your query
JSFIDDLE
what i have done is giving relative style to the parent buttonhomea .
then on hover showing the hidden div.
.card__overlay{
position: absolute;
width: 100%;
height: 100%;
top: 0;
opactity:0;
z-index:-1;
}
.buttonhomea{
position:relative;
}
.buttonhomea:hover .card__overlay{
opacity:1;
z-index:1;
}
and added html
<div class="card__overlay grad-yellow">
<div class="card__title">Auctions</div>
<div class="card__description">
Description goes here.
</div>
</div>
under each buttonhomea class
i want to move an img by button click. I know this question has been asked a lot, but i couldnt use them.
Heres the relevant HTML:
<button class="ggE" (click)="gegenEnemy(chosenHero, actualEnemy);moveFist(); ...
<div class="col">
<img id="img" class="fist" src="...">
This is the function (typescript):
moveFist(): void {
document.getElementById('img').classList.add('fist');
}
And my css, which makes the picture move from left to right:
.fist {
width: 70px;
height: 70px;
position: relative;
animation-name: example;
animation-duration: 2s;
}
#keyframes example {
0% {left:50px; top:20px;}
100% {left:450px; top:20px;}
}
So why cant i connect it with a button click?
First of all validate your HTML code
<button class="ggE" onclick="moveFist();">button</button>
<div class="col">
<img id="img" class="" src="https://via.placeholder.com/150">
<div>
Edits:
function moveFist(){
document.getElementById("img").classList.remove("fist");
// element.offsetWidth = element.offsetWidth;
// Do this instead:
void img.offsetWidth;
document.getElementById("img").classList.add("fist");
}
set the width of img by it's offset width that is,
img.offsetWidth;
Can you something like this ?
function moveFist(){
document.getElementById("img").classList.remove("fist");
// element.offsetWidth = element.offsetWidth;
// Do this instead:
void img.offsetWidth;
document.getElementById("img").classList.add("fist");
}
img{
width: 70px;
height: 70px;
position: relative;
left:50px;
animation-duration: 2s;
top:20px;
}
.fist{
position:relative;
animation-name: example;
}
#keyframes example {
0% {left:50px; top:20px;}
100% {left:450px; top:20px;}
}
<button class="ggE" onclick="moveFist()">button</button>
<div class="col">
<img id="img" class="" src="https://via.placeholder.com/150">
<div>
I have 9 divs inside a flex container.
What I'm trying to achieve is an effect where the div you're hovering over 'pushes' the divs on the right further right and the divs on the left further left. I'd like to do this using nth-child selector so that I only have to write 2 styles for each div.
For now, I just have it partialy working on the red div as a proof of concept.
Achieving the first part was easy, when you hover over the red div, the 4 divs to the right of it are pushed to the right using translateX(30px)
That css looks like this.
.team-card:nth-child(5):hover ~ .team-card:nth-child(n+4){
transform: translateX(30px);
}
Per this article on css tricks, https://css-tricks.com/useful-nth-child-recipies/, doing the first 4 should also be easy.
.team-card:nth-child(5):hover ~ .team-card:nth-child(-n+4){
transform: translateX(-30px);
}
But this doesn't work. I've tried removing the first css selector, thinking that maybe you couldn't have more than a single hover psuedo-state on a class. But that didn't do anything.
Then I removed the hover state so I just had this.
.team-card:nth-child(-n+4){
background-color:yellow;
}
And that worked. So does nth-child using -n not work when it has a psuedo-state?
Is there a pure css solution to achieve this effect when hovering? Or will I have to resort to javascript?
EDIT:
Here is the fiddle that I forgot to link to.
https://jsfiddle.net/q0x51kmw/1/
You can do this very simply, without the transform property:
.team-cards-container {
display: flex;
margin: 55px 2.5%;
height: 300px;
}
.team-card {
flex: 1;
transition: all .2s ease-in-out;
}
.team-card:hover {
margin-right: 30px;
}
/*Colors*/
.team-card:nth-child(3n+1) {background-color: #949300}
.team-card:nth-child(3n+2) {background-color: #8A1B61}
.team-card:nth-child(3n+3) {background-color: #236192}
.team-card:nth-child(5) {background: #ff0000}
<div class="team-cards-container">
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
</div>
Is this what you mean?
.team-cards-container hover moves all children -30px
current (child) .team-card hover overwrites to 0px
all next siblings to current .team-card hover are overwritten +30px
.team-cards-container{
display:flex;
width:95%;
margin-left:auto;
margin-right:auto;
padding-top:55px;
}
/*Colors*/
.team-card:nth-child(3n+1){
height:300px;
width:230px;
background-color:#949300;
}
.team-card:nth-child(3n+2){
height:300px;
width:230px;
background-color:#8A1B61;
}
.team-card:nth-child(3n+3){
height:300px;
width:230px;
background-color:#236192;
}
/*Middle*/
.team-card:nth-child(5){
background:red;
}
/*Universals*/
.team-card{
transition: all .2s ease-in-out;
}
.team-cards-container:hover .team-card {
transform: translateX(-30px);
}
.team-cards-container .team-card:hover {
transform: translateX(0);
}
.team-card:hover ~ .team-card {
transform: translateX(30px);
}
<div class="team-cards-container">
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
</div>
css do not allow you to style previous sibling element. You are using '~' but '~' can only be used to style next sibling elements
you are doing it the wrong way
replace your css with this
.team-cards-container{
display:flex;
width:95%;
margin-left:auto;
margin-right:auto;
padding-top:55px;
}
/*Colors*/
.team-card:nth-child(3n+1){
height:300px;
width:230px;
background-color:#949300;
}
.team-card:nth-child(3n+2){
height:300px;
width:230px;
background-color:#8A1B61;
}
.team-card:nth-child(3n+3){
height:300px;
width:230px;
background-color:#236192;
}
/*Middle*/
.team-card:nth-child(5){
background:red;
}
/*Universals*/
.team-card{
transition: all .2s ease-in-out;
}
.team-cards-container:hover > .team-card{
transform:translateX(-20px);
}
.team-card:hover{
transform:translateX(0px)!important;
}
.team-card:hover~.team-card{
transform:translateX(20px)!important;
}
Here is <div> with style:
<div style="transform: translateX(1565px) translateY(159px) translateZ(0px)">
</div>
I want to add class that can calculate existing value of translateX and subtract 140(for example) from it. Is it possible to do that?
Regards, Nick
Maybe you would consider using css variables? With them you can define just the offset value in a class, and use that value inside the main class that calculates the actual translation. In the example below you can see that i defined small utility classes just modify the offset value.
/* for visual purposes */
.box {
width: 50px;
height: 50px;
background-color: grey;
margin: 10px;
}
.box{
--offset: 0px;
transform: translateX(calc(15px + var(--offset))) translateY(2px) translateZ(0px);
}
.smallOffset{
--offset: 10px;
}
.bigOffset{
--offset: 40px;
}
.negativeOffset{
--offset: -20px;
}
<div class="box"></div>
<div class="box smallOffset"></div>
<div class="box bigOffset"></div>
<div class="box negativeOffset"></div>
Unfortunately, the support for css variables is not perfect, as IE is not supported at all. For more details about usage of --variable, var(--variable) and related, please refer to the docs.
Use calc()
.decrease{
transform: translateX(calc(1565px - 140px)) translateY(159px) translateZ(0px);
}
<div class="decrease">
div
</div>
With media-query:
.decrease{
transform: translateX(1565px) translateY(159px) translateZ(0px);
}
#media only screen and (max-width: 600px) {
.decrease {
transform: translateX(calc(1565px - 140px)) translateY(159px) translateZ(0px);
}
}
<div class="decrease">
div
</div>
Using Less and parameter:
#translateX : 1565px;
.decrease{
transform: translateX(#translateX) translateY(159px) translateZ(0px);
}
#media only screen and (max-width: 600px) {
.decrease {
transform: translateX(calc(#translateX - 140px)) translateY(159px) translateZ(0px);
}
}
I have this little CSS3 animation going on in my webapp, its a panel in the bottom left side of the screen. I use Linux so I can't try out the animations in Safari, however my project leader is of course a Mac user and he complained right away it didn't work.
So, here are my two files. I'll paste everything in here that I'm working on, and in the bottom I have a jsfiddle that tried to reproduce it with plain css and fewer HTML tags. :)
Here's the less file.
.panel {
position:absolute;
left:20px;
bottom:20px;
background-image : url("./images/filter_bg.png");
width:476px;
height:126px;
z-index:1;
cursor:pointer;
}
.filter {
position:relative;
float:left;
z-index: 2;
width:119px;
height:119px;
vertical-align:24px;
overflow:hidden;
&.activeLive {
background-image: url("./images/filter_active1.png");
}
&.activeSee {
background-image: url("./images/filter_active2.png");
}
&.activeEat {
background-image: url("./images/filter_active3.png");
}
&.activeDo {
background-image: url("./images/filter_active4.png");
}
}
.filter:hover > .filter-hover {
position:absolute;
height:34px;
width:119px;
-moz-transition:-moz-transform 180ms;
-webkit-transition:-webkit-transform 180ms;
-o-transition:-o-transform 180ms;
transition:transform 180ms;
background-image:url("./images/filter_hoverlabel_bg.png");
}
.filter:hover > .filter-hover {
transform: translate(0,-24px);
}
.filter-hover{
position: relative;
bottom:-26px;
text-align:center;
line-height: 32px;
}
.filter-icon{
width:68px;
height:68px;
margin: 24px auto auto;
&.inactive1{
background-image:url("./images/filter_icon1_inactive.png");
}
&.inactive2{
background-image:url("./images/filter_icon2_inactive.png");
}
&.inactive3{
background-image:url("./images/filter_icon3_inactive.png");
}
&.inactive4{
background-image:url("./images/filter_icon4_inactive.png");
}
&.active1{
background-image:url("./images/filter_icon1_active.png");
}
&.active2{
background-image:url("./images/filter_icon2_active.png");
}
&.active3{
background-image:url("./images/filter_icon3_active.png");
}
&.active4{
background-image:url("./images/filter_icon4_active.png");
}
}
.filter-text{
text-align:center;
}
It adds a class to the divs when clicked upon, I use angular for this. So don't care to much about that.
<div class="panel" ng-controller="PanelCtrl">
<div class="{{liveEnabled ? 'filter activeLive' : 'filter'}}" ng-click="liveButton()">
<div class="{{liveEnabled ? 'filter-icon active1' : 'filter-icon inactive1'}}"></div>
<div class="filter-hover">
Bo
</div>
</div>
<div class="{{seeEnabled ? 'filter activeSee' : 'filter'}}" ng-click="seeButton()">
<div class="{{seeEnabled ? 'filter-icon active2' : 'filter-icon inactive2'}}"></div>
<div class="filter-hover">
<span class="filter-text">Se</span>
</div>
</div>
<div class="{{eatEnabled ? 'filter activeEat' : 'filter'}}" ng-click="eatButton()">
<div class="{{eatEnabled ? 'filter-icon active3' : 'filter-icon inactive3'}}"></div>
<div class="filter-hover">
<span class="filter-text">Äta</span>
</div>
</div>
<div class="{{doEnabled ? 'filter activeDo' : 'filter'}}" ng-click="doButton()">
<div class="{{doEnabled ? 'filter-icon active4' : 'filter-icon inactive4'}}"></div>
<div class="filter-hover">
<span class="filter-text">Göra</span>
</div>
</div>
</div>
I made this fiddle: http://jsfiddle.net/j97ahnkv/ wich tries to show out what I'm trying to do.
It's not working in Safari because it still requires the -webkit prefix on transform.
You have to add it to this rule:
.filter:hover > .filter-hover {
-webkit-transform: translate(0, -24px);
transform: translate(0,-24px);
}