Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
I am trying to make an analog clock with HTML,CSS and Javascript but I donĀ“t know how to fix the clock hands when rotateing
.line {
border-left: 2px solid gray;
height: 65px;
transform: translate(100px);transform-origin: 100px;
}
This should do. Hope it helps you!
const secondHand = document.querySelector('.second-hand');
const minHand = document.querySelector('.min-hand');
const hourHand = document.querySelector('.hour-hand')
function setDate() {
const now = new Date();
const timeInterval = 6;
const seconds = now.getSeconds();
const secondDegree = seconds * timeInterval;
secondHand.style.transform = `rotate(${secondDegree}deg)`;
const mins = now.getMinutes();
const minDegree = ((mins / 60) * 360) + 90;
minHand.style.transform = `rotate(${minDegree}deg)`;
const hours = now.getHours();
const hourDegree = ((hours / 12) * 360) + 90;
hourHand.style.transform = `rotate(${hourDegree}deg)`;
}
setInterval(setDate, 1000);
html {
/* background: #ededed url(https://unsplash.it/1500/1000?image=881&blur=5); */
background-size: cover;
font-family: 'helvetica neue';
text-align: center;
font-size: 10px;
}
body {
margin: 0;
font-size: 2rem;
display: flex;
flex: 1;
min-height: 100vh;
align-items: center;
}
.clock {
width: 30rem;
height: 30rem;
border: 20px solid white;
border-radius: 50%;
margin: 50px auto;
position: relative;
padding: 2rem;
box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1), inset 0 0 0 3px #EFEFEF, inset 0 0 10px black, 0 0 10px rgba(0, 0, 0, 0.2);
}
.clock-face {
position: relative;
width: 100%;
height: 100%;
transform: translateY(-3px);
/* account for the height of the clock hands */
}
.center {
position: absolute;
background-color: yellow;
top: 50%;
right: 49%;
width: 8px;
height: 8px;
border-radius: 50%;
}
.hand {
width: 50%;
height: 6px;
background: black;
position: absolute;
border-radius: 5px;
top: 50%;
transform-origin: 100%;
transform: rotate(90deg);
transition: all 0.5s;
transition-timing-function: cubic-bezier(0, 2.58, 1, 0.6);
}
<div class="clock">
<div class="clock-face">
<div class="hand hour-hand"></div>
<div class="hand min-hand"></div>
<div class="hand second-hand"></div>
<div class="center"></div>
</div>
</div>
Related
I'm sure the answer is right in front of me, but I have searched and searched for hours and have been unable to come up with a fix. I am wondering how to have my background image fill the whole screen. It fills most of the screen, except where the header would be. I can get the full screen background image, only when I comment out the "Form" component. When I go to inspect the portion that is not filled, it says it shows as html, which I suspect is pulled from the index.html file in the public folder. I would greatly appreciate any and all help on this.
App.js
import React from 'react';
import './App.css';
import Form from './Form';
import wallstreet from './images/wallstreet.png';
function App() {
return (
<div className="App">
<div className="overlay"
style={{backgroundImage: `url(${wallstreet})`}} />
<Form />
</div>
);
}
export default App;
App.css
#import url('https://fonts.googleapis.com/css2?family=PT+Sans&display=swap');
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'PT Sans', sans-serif;
}
.overlay {
position: fixed;
min-width: 100%;
min-height: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
Form.js
import React, { useState } from 'react';
import FormSignup from './FormSignup';
import FormSuccess from './FormSuccess';
import './Form.css';
const Form = () => {
const [isSubmitted, setIsSubmitted] = useState(false)
function submitForm() {
setIsSubmitted(true);
}
return (
<>
<div className="form-container">
<span className="close-btn">x</span>
<div className="form-content-left">
<img className='form-img' src='images/bullish.png' alt='bullish' />
</div>
{!isSubmitted ? (<FormSignup submitForm=
{submitForm} />) : <FormSuccess />}
</div>
</>
);
};
export default Form;
Form.css
.form-container {
margin: 100px auto;
width: 1000px;
box-shadow: 0 5px 8px 0 rgba(0, 0, 0, 0.2), 0 7px 20px 0 rgba(0, 0, 0, 0.2);
position: relative;
border-radius: 10px;
height: 600px;
display: grid;
grid-template-columns: 1fr 1fr;
}
.close-btn {
position: absolute;
top: 2%;
right: 3%;
font-size: 1.5rem;
z-index: 1;
color: #fff;
cursor: pointer;
}
.form-content-left {
background: linear-gradient(
90deg,
rgb(39, 176, 255) 0%,
rgb(0, 232, 236) 100%
);
border-radius: 10px 0 0 10px;
position: relative;
}
.form-img {
width: 80%;
height: 80%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.form-img-2 {
width: 60%;
height: 60%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.form-success {
text-align: center;
font-size: 24px;
margin-top: 80px;
color: #fff;
}
.form-content-right {
border-radius: 0 10px 10px 0;
position: relative;
background: linear-gradient(90deg, rgb(40, 40, 40) 0%, rgb(17, 17, 17) 100%);
}
.form {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 90%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.form h1 {
font-size: 1rem;
text-align: start;
width: 80%;
margin-bottom: 1rem;
color: #fff;
}
.form-inputs {
margin-bottom: 0.5rem;
width: 80%;
}
.form-inputs p {
font-size: 0.8rem;
margin-top: 0.5rem;
color: #f00e0e;
}
.form-label {
display: inline-block;
font-size: 0.8rem;
margin-bottom: 6px;
color: #fff;
}
.form-input {
display: block;
padding-left: 10px;
outline: none;
border-radius: 2px;
height: 40px;
width: 100%;
border: none;
}
.form-input::placeholder {
color: #595959;
font-size: 12px;
}
.form-input-btn {
width: 80%;
height: 50px;
margin-top: 10px;
border-radius: 2px;
background: linear-gradient(
90deg,
rgb(39, 176, 255) 0%,
rgb(0, 232, 236) 100%
);
outline: none;
border: none;
color: #fff;
font-size: 1rem;
}
.form-input-btn:hover {
cursor: pointer;
background: linear-gradient(
90deg,
rgb(39, 143, 255) 0%,
rgb(12, 99, 250) 100%
);
transition: all 0.4s ease-out;
}
.form-input-login {
font-size: 0.8rem;
margin-top: 10px;
color: #fff;
width: 80%;
text-align: center;
}
.form-input-login a {
text-decoration: none;
color: #27cdff;
font-weight: 6
00;
}
Did you try 100vh and 100vw along with position absolute.
also search if any of the parent element is having relative position
I'm trying to replicate this effect with pure CSS:
So far I've tried doing:
.parent {
height: 90vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.hoverable-element {
border: 0.1rem solid #000;
background: #fff;
padding: 1rem 2rem;
transform: translate(0, 0);
box-shadow: 0 0 0 #000;
transition:
box-shadow 200ms ease-out,
transform 200ms ease-out;
}
.hoverable-element:hover {
transform: translate(-0.5rem, -0.5rem);
box-shadow:
0.1rem 0.1rem 0 #000,
0.2rem 0.2rem 0 #000,
0.3rem 0.3rem 0 #000,
0.4rem 0.4rem 0 #000,
0.5rem 0.5rem 0 #000;
}
<div class="parent">
<button class="hoverable-element">Hoverable Button</button>
</div>
But this method repeats a lot of unnecessary code, as well as not properly doing what I intended.
I want the button "shadow" or hover-effect-thingy to be bordered with a white background (as shown in the image). Other than that I'm clueless as to where to start
here is an idea with pseudo element and skew transformation:
.parent {
height: 90vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.hoverable-element {
border: 1px solid #000;
background: #fff;
padding: 1rem 2rem;
position: relative;
transition: transform 0.5s;
}
.hoverable-element::before,
.hoverable-element::after {
content: "";
position: absolute;
border: inherit;
transition: inherit;
}
.hoverable-element::before {
height: 1rem;
top: 100%;
left: -1px;
right: -1px;
transform-origin: top left;
transform: skewX(45deg) scaleY(var(--s, 0));
}
.hoverable-element::after {
width: 1rem;
left: 100%;
top: -1px;
bottom: 0;
border-bottom:none;
transform-origin: bottom left;
transform: skewY(45deg) scaleX(var(--s, 0));
}
.hoverable-element:hover {
transform: translate(-0.5rem, -0.5rem);
--s: 1;
}
<div class="parent">
<button class="hoverable-element">Hoverable Button</button>
</div>
I have a React Login screen with black background set using CSS Styling. The login screen is quite elementary at this point which comprises of 3 input tag username, password and submit respectively.
All i am trying to do right now is change the background of the login screen with slide down effect (height 0 to height $loginScreenHeight) whenever the mouse moves.
I got it working as expected but with a slight side-effect. The side-effect is whenever the mouse moves the initial background goes away momentarily and the new background starts sliding down.
I want the new background to start sliding on top of the old background and cover it up. Can some Css expert please throw a light on what i am missing here?
Following is my code.
import React from "react";
import axios from "axios";
import { connect } from "react-redux";
import { userlogin } from "./../action/userLogin";
class Login extends React.Component {
state = {
email: "",
passwd: "",
loginStatus: "",
mouseOverLogin: false
};
enteruname = e => this.setState({ email: e.target.value });
enterpasswd = e => this.setState({ passwd: e.target.value });
submitCredentials = e => e.preventDefault();
render() {
return (
<div
className="login"
onMouseMove={() => this.setState({ mouseOverLogin: true })}
>
<form
onSubmit={this.submitCredentials}
className={
this.state.mouseOverLogin ? "loginForm animateLogin" : "loginForm"
}
>
<p>Login</p>
<hr />
<input
className="uname"
placeholder="Enter Username"
type="email"
name="email"
value={this.state.email}
onChange={this.enteruname}
/>
<input
className="passwd"
placeholder="Enter Password"
type="password"
name="passwd"
value={this.state.passwd}
onChange={this.enterpasswd}
/>
<button className="loginBtn">Login</button>
</form>
</div>
);
}
}
export default connect()(Login);
CSS File:-
.login {
width: 100vw;
height: 100vh;
overflow: hidden;
position: absolute;
top: 0vh;
left: 0vw;
}
.loginForm {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
top: 25vh;
left: 38vw;
width: 27vw;
height: 54vh;
background: rgba(0, 0, 0, 0.7);
position: relative;
z-index: 1000;
border-radius: 20px;
}
.login form input {
margin: 0 auto;
width: 24vw;
height: 6vh;
border-radius: 20px;
outline: none;
background: rgba(42, 27, 61, 0.6);
color: white;
text-align: center;
font-size: 1.2rem;
}
.uname {
position: absolute;
top: 18vh;
}
.uname:focus,
.passwd:focus {
background: rgba(42, 27, 61, 0.6);
}
.passwd {
position: absolute;
top: 28vh;
}
.loginBtn {
position: absolute;
width: 50%;
height: 5vh;
left: 25%;
text-decoration: none;
outline: none;
top: 38vh;
border-radius: 20px;
background: rgba(42, 27, 61, 0.6);
color: white;
}
.login form input::placeholder {
color: white;
text-align: center;
font-size: 1.2rem;
}
.login form p {
color: white;
font-size: 25px;
width: 24vw;
position: absolute;
top: 5vh;
left: 2vw;
}
.animateLogin {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 25vh;
left: 38vw;
width: 27vw;
animation: slideDown 2s 1 forwards ease-in-out;
z-index: 0;
// transition: all 280ms ease-in-out;
}
#keyframes slideDown {
from {
height: 0;
background: rgba(0, 0, 0, 0.7);
}
to {
background: $navlink;
height: 54vh;
}
}
hr {
position: absolute;
top: 12vh;
width: 24vw;
height: 1px;
background: white;
}
the height change to 0 is a problem because the "old background" is set on the element with 0 height.
I wrote 2 POC that can help you:
.a,
.b {
margin: 10px;
padding: 10px;
height: 30px;
text-align: center;
border: solid 1px blue;
background: green;
position: relative;
}
.a:hover {
animation: slidebg 2s;
box-shadow: inset 0 50px 0 0 blue;
}
#keyframes slidebg {
0% {
box-shadow: inset 0 0 0 0 blue;
}
100% {
box-shadow: inset 0 50px 0 0 blue;
}
}
.b-bg {
position: absolute;
height: 0;
top: 0;
left: 0;
background: blue;
width: 100%;
}
.b span {
position: relative;
z-index: 10;
}
.b:hover .b-bg {
animation: slidebg2 2s;
height: 100%;
}
#keyframes slidebg2 {
0% {
height: 0;
}
100% {
height: 100%;
}
}
<div class="a">link</div>
<div class="b">
<div class="b-bg"></div>
<span>link</span>
</div>
Current Situation Image
Here is what I have got. But I want that rectangle facebook image behind the red region (currently it is just behind the text 'Please')
#mlnk{
text-decoration:none;
position:relative;
top:40%;
left:0%;
color: #b5c5d6;
}
.container-corner-img{ /* **THIS IS TO BE PUSHED BACK** */
height: 40%; width: 70%;
position: absolute;
top: 5px; left:-75px;
}
.container{
width:50%;
height:30%;
background: linear-gradient(#8B9DC1, #3b5998);
padding:100px;
border-radius:12px;
position: relative;
font-family: sans-serif;
}
h1{ /* **THIS NEEDS TO BE BROUGHT TO FRONT** */
margin-left: auto;
margin-right: auto;
padding: 8px;
border-radius: 4px;
box-shadow: 0 4px 6px 0 rgba(0,0,0,0.2);
transition: 0.4s ease;
background-color: red;
margin-top: 0;
}
img{
height: 80%;
width: 50%;
}
<div class="container">
<div class="container-corner-img">
<img src="fbminimal.png">
</div>
<h1>
<a id="mlnk" href = "#link"> Please login to your facebook account first</a>
</h1>
</div>
I have commented the css definitions in CAPS that needs to be focused according to me.
To bring the heading to the front, you have to set z-index to a larger value. To be able to use z-index on an element it needs to have a different position than static. So use relative. Moreover, do not use the center-tag since it is deprecated. The layout should be controlled by CSS only.
#mlnk {
text-decoration: none;
position: relative;
top: 40%;
left: 0%;
color: #b5c5d6;
}
h3 {
color: midnightblue;
padding: 4px;
box-shadow: 0 2px 4px 0 #38434e;
background: #3c64ad;
}
.container-corner-img {
/* **THIS IS TO BE PUSHED BACK** */
height: 40%;
width: 70%;
position: absolute;
top: 5px;
left: -75px;
/* opacity: 0.4; */
}
.container {
width: 50%;
height: 30%;
background: linear-gradient(#8B9DC1, #3b5998);
padding: 100px;
border-radius: 12px;
position: relative;
font-family: sans-serif;
/* z-index: 1; */
margin: 0 auto;
}
h1 {
/* **THIS NEEDS TO BE BROUGHT TO FRONT** */
margin-left: auto;
margin-right: auto;
padding: 8px;
border-radius: 4px;
box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.2);
transition: 0.4s ease;
background-color: red;
/* rgba(0,0,80,0.2); */
margin-top: 0;
/* Add this */
position: relative;
z-index: 1000;
}
h1:hover {
box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.2), 0 6px 8px 0 rgba(0, 0, 0, 0.19);
transition: 0.4s ease;
}
img {
height: 80%;
width: 50%;
/* z-index: 0; */
}
.center {
text-align: center;
margin: 0 auto;
}
<div class="center">
<div class="container">
<div class="container-corner-img">
<img src="https://stocknews.com/wp-content/uploads/2017/07/facebook-fb-alternate.jpg">
</div>
<h1>
<a id="mlnk" href="#link"> Please login to your facebook account first</a>
</h1>
<h3>You need to Log In</h3>
</div>
</div>
Here is a restricted code pen containing the problem code: http://codepen.io/Jraghon/pen/YqgKYR
I'm trying to make a fixed, mobile-first, resonsive header. I have everything working, except for some sizing issues. Specifically, I want the div that actually holds the content to be at least as high as the viewport minus the size of the header.
I have ensured that all of the div's ancestors have height: 100%. Moreover, js shows that they are all the correct height. However, the dc-container is not as tall as it should be, and I can't figure out why.
Answer
For lack of a better answer, I am using the answer from this question (although I wish there were a way to make it stretch without tables):
Make nested div stretch to 100% of remaining container div height
Here is the final pen: http://codepen.io/Jraghon/pen/pyYojr
The problem is that you have a circular definition:
.site-content {
min-height: calc(100% - 66px);
height: auto; /* Depends on contents */
}
.site-content > .dc-container {
height: 100%; /* Depends on parent */
min-height: 100%; /* Depends on parent */
}
Instead, you should use
.site-content {
height: calc(100% - 66px);
}
.site-content > .dc-container {
height: auto;
min-height: 100%;
}
$(document).ready(function() {
$('#header__icon').click(function(e) {
e.preventDefault();
$('body').toggleClass('with--sidebar');
gooo();
});
$('#site-cache').click(function(e) {
$('body').removeClass('with--sidebar');
gooo();
});
});
function gooo() {
$('.x0').html('html x: ' + $('html').outerWidth());
$('.x1').html('html y: ' + $('html').outerHeight());
$('.x2').html('body x: ' + $('body').outerWidth());
$('.x3').html('body y: ' + $('body').outerHeight());
$('.x4').html('site-container x: ' + $('.site-container').outerWidth());
$('.x5').html('site-container y: ' + $('.site-container').outerHeight());
$('.x6').html('site-pusher x: ' + $('.site-pusher').outerWidth());
$('.x7').html('site-pusher y: ' + $('.site-pusher').outerHeight());
$('.x8').html('header dc-container x: ' + $('.header .dc-container').outerWidth());
$('.x9').html('header dc-container y: ' + $('.header .dc-container').outerHeight());
$('.x10').html('site-content x: ' + $('.site-content').outerWidth());
$('.x11').html('site-content y: ' + $('.site-content').outerHeight());
$('.x12').html('content dc-container x: ' + $('.site-content .dc-container').outerWidth());
$('.x13').html('content dc-container y: ' + $('.site-content .dc-container').outerHeight());
}
$(function() {
$(window).resize(gooo).trigger('resize');
});
/* VARIABLES */
html,
body {
font-family: 'Roboto', sans-serif;
line-height: 1.4;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.site-container {
height: 100%;
}
.site-pusher {
height: 100%;
position: absolute;
left: 0;
right: 0;
bottom: 0;
-moz-transition-duration: 0.3s;
-o-transition-duration: 0.3s;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.dc-container {
overflow: hidden;
*zoom: 1;
margin: auto;
width: 100%;
max-width: 960px;
height: 100%;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 66px;
line-height: 66px;
-moz-transition-duration: 0.3s;
-o-transition-duration: 0.3s;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.header .dc-container {
color: #fff;
background-color: #0288D1;
}
.site-content {
margin-top: 66px;
height: calc(100% - 66px);
}
.site-content .dc-container {
height: auto;
min-height: 100%;
background-color: #B3E5FC;
}
.header__logo {
color: #fff;
font-weight: 700;
padding: 0 25px;
float: left;
}
.menu {
position: fixed;
left: -250px;
top: 0;
bottom: 0;
width: 250px;
background-color: #0277BD;
-moz-transition-duration: 0.3s;
-o-transition-duration: 0.3s;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.menu a {
padding: 0 10px;
color: #fff;
height: 40px;
text-align: center;
line-height: 40px;
display: block;
border-bottom: 1px solid #0288D1;
}
.menu a:hover {
color: #B3E5FC;
}
.header__icon {
position: relative;
display: block;
float: left;
width: 50px;
height: 66px;
cursor: pointer;
}
.header__icon:after {
content: '';
position: absolute;
display: block;
width: 1rem;
height: 0;
top: 26px;
left: 15px;
-moz-box-shadow: 0 0px 0 1px #fff, 0 6px 0 1px #fff, 0 12px 0 1px #fff;
-webkit-box-shadow: 0 0px 0 1px #fff, 0 6px 0 1px #fff, 0 12px 0 1px #fff;
box-shadow: 0 0px 0 1px #fff, 0 6px 0 1px #fff, 0 12px 0 1px #fff;
}
.site-cache {
position: fixed;
top: 0;
bottom: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.6);
-moz-transition-duration: 0.3s;
-o-transition-duration: 0.3s;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.with--sidebar {
overflow: hidden;
}
.with--sidebar .header,
.with--sidebar .site-pusher {
left: 250px;
right: -250px;
}
.with--sidebar .menu {
left: 0;
}
.with--sidebar .site-cache {
right: 0;
left: 250px;
}
<div class="site-container">
<div class="site-pusher">
<header class="header">
<div class="dc-container">
<a href='#' class="header__logo" id='header__logo'><b>LOGO</b></a>
<nav class="menu">
Home
About
Blog
Contact
</nav>
</div>
</header>
<div class="site-content">
<div class="dc-container">
<div class="x0"></div>
<div class="x1"></div>
<br>
<div class="x2"></div>
<div class="x3"></div>
<br>
<div class="x4"></div>
<div class="x5"></div>
<br>
<div class="x6"></div>
<div class="x7"></div>
<br>
<div class="x8"></div>
<div class="x9"></div>
<br>
<div class="x10"></div>
<div class="x11"></div>
<br>
<div class="x12"></div>
<div class="x13"></div>
</div>
<!-- END container -->
</div>
<!-- END site-content -->
<div class="site-cache" id="site-cache"></div>
</div>
<!-- END site-pusher -->
</div>
<!-- END site-container -->
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
You can use viewport sizes. vw means viewport width, and vh viewport height:
.selector {
height: 100vh; /** 100% of viewport height **/
}
You can use calc() to substract the height of the header:
.header {
height: 50px;
}
.selector {
height: calc(100vh - 50px); /** 100% of viewport height - 50 px header height **/
}