0

Moving elements

Hello I want to know how to move element based on its color for example when its green it stays at its place but when its black or red it goes Up in the page Using “HTML,CSS,JAVAScript”

21st Jul 2022, 1:52 AM
MANAYER .
7 Respuestas
+ 2
Did you change color with animation or in javascript? I think it is best to use javascript for it, because you can check current color, and when color is red than change position
21st Jul 2022, 12:24 PM
PanicS
PanicS - avatar
+ 1
You can change position of elements. Check this: https://www.w3schools.com/css/css_positioning.asp You didnt post code, so I dont know how color of element is defined, do you set it directly in css, or are color is changing on some click, animation.. You can also access color and background color in js and even change it, with "=" it set color without it can read color and store to variable. https://www.w3schools.com/jsref/prop_style_backgroundcolor.asp
21st Jul 2022, 5:51 AM
PanicS
PanicS - avatar
+ 1
The idea that im having is that the color randomly ( red, black,yellow, green) So when its red or black the div change the div position goes up
21st Jul 2022, 8:40 AM
MANAYER .
+ 1
Can you provide your attempt?
21st Jul 2022, 8:45 PM
Chris Coder
Chris Coder - avatar
+ 1
You never posted your code, so we dont know what exacly you are trying to do. I posted some code where you can see some of this feature implemented, so you can figure out and use it in your code, ofcourse with changing to fit your need. Please post your attempt, so we can understand better and help you, or if you dont know where to start look on some tutorial on internet (video will be best).
27th Jul 2022, 12:39 PM
PanicS
PanicS - avatar
0
Here is my code where I moved element when it have red background, hope this will help you. https://code.sololearn.com/WnD6IVP5c54S/?ref=app
21st Jul 2022, 10:15 PM
PanicS
PanicS - avatar
0
Thank you but It did’t work And your code keeps moving i want a one time movement Note:my div has alot of divs in top of it
27th Jul 2022, 8:58 AM
MANAYER .