Project
adding circles that expands when users hover, on an image so it adds interesting animation to it.
Problem
After I was done I realized that depending on the screen display used, the elements (red balls) I put over the image are in different locations. How can I do this so it works on all devices except mobile.
You will get a better idea of what im doing when you see the demo
HTML
<div><img class="tree" title="source: imgur.com" src="http://i.imgur.com/1dDCOyq.png" alt="" />
<div class="circle-top-left">
<div class="circle__wrapper">
<div class="circle__content">
<p class="para">This is where sentence goes</p>
consulting 1
</div>
</div>
</div>
<div class="circle-top-right">
<div class="circle__wrapper">
<div class="circle__content">
<p class="para">This is where sentence goes</p>
consulting 3
</div>
</div>
</div>
<div class="circle-bot-right">
<div class="circle__wrapper">
<div class="circle__content">
<p class="para">This is where sentence goes</p>
consulting
</div>
</div>
</div>
<div class="circle-bot-left">
<div class="circle__wrapper">
<div class="circle__content">
<p class="para">This is where sentence goes</p>
consulting 4
</div>
</div>
</div>
</div>
CSS
.footer_top_holder {
border-top: #17171A solid 8px;
box-shadow: none;
}
/* Home page tree image CSS */
* {
box-sizing: border-box;
}
.tree {
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 50px;
margin-top: 50px;
}
.circle-top-left {
cursor: default;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
overflow: hidden;
font-size: 9px;
-webkit-backface-visibility: hidden;
position: absolute;
background: #b20312;
top: 103.5px;
left: 26.3%;
width: 60px;
height: 60px;
border-radius: 50%;
transition: all .5s ease-in-out;
margin: 0 0;
text-align: center;
}
.circle-top-left:hover {
width: 200px;
height: 200px;
padding: 2.5em;
color: transparent;
left: 160px;
top: 45px;
}
.circle-top-right {
cursor: default;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
overflow: hidden;
font-size: 9px;
-webkit-backface-visibility: hidden;
position: absolute;
background: #b20312;
top: 49.5px;
left: 52.5%;
width: 60px;
height: 60px;
border-radius: 50%;
transition: all .5s ease-in-out;
margin: 0 0;
text-align: center;
}
.circle-top-right:hover {
width: 200px;
height: 200px;
padding: 2.5em;
color: transparent;
left: 49%;
top: 35px;
}
.circle-bot-right {
cursor: default;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
overflow: hidden;
font-size: 9px;
-webkit-backface-visibility: hidden;
position: absolute;
background: #b20312;
top: 267.5px;
left: 75%;
width: 60px;
height: 60px;
border-radius: 50%;
transition: all .5s ease-in-out;
margin: 0 0;
text-align: center;
}
.circle-bot-right:hover {
width: 200px;
height: 200px;
padding: 2.5em;
color: transparent;
left: 74%;
top: 215px;
}
.circle-bot-left {
cursor: default;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
overflow: hidden;
font-size: 9px;
-webkit-backface-visibility: hidden;
position: absolute;
background: #b20312;
top: 379px;
left: 19.6%;
width: 60px;
height: 60px;
border-radius: 50%;
transition: all .5s ease-in-out;
margin: 0 0;
text-align: center;
}
.circle-bot-left:hover {
width: 200px;
height: 200px;
padding: 2.5em;
color: transparent;
left: 8%;
top: 320px;
}
.circle__wrapper {
display: table;
width: 100%;
height: 100%;
}
.title_subtitle_holder {
display: block;
padding: 30px 0;
position: relative;
}
.circle__content {
display: table-cell;
padding: 1em;
vertical-align: middle;
}
.para {
line-height: 25px;
display: none;
font-size: 15px;
color: white;
text-align: center;
vertical-align: middle;
}
.circle-top-right:hover .para,
.circle-bot-right:hover .para,
.circle-top-left:hover .para,
.circle-bot-left:hover .para {
display: block;
}
.circle-top-right:hover span,
.circle-bot-right:hover span,
.circle-top-left:hover span,
.circle-bot-left:hover span {
display: none;
}
Demo
You can get your element circles to start out on top of the image's circles by replacing your hard-coded left styles with the following:
.circle-top-left {
left: calc(50% - 260px);
}
.circle-top-right {
left: calc(50% + 29px);
}
.circle-bot-right {
left: calc(50% + 275px);
}
.circle-bot-left {
left: calc(50% - 335px);
}
CodePen 1
If you want the circles to always expand in place, replace your hard-coded left and top hover styles with the following:
.circle-top-left:hover, .circle-top-right:hover,
.circle-bot-right:hover, .circle-bot-left:hover {
transform: translate(-90px, -90px);
}
CodePen 2
Related
I need to make this Range slider responsive. Text is getting overlapped when i start using in mobile version. Please help me to achieve this.
I have tried to add it in Table responsive and adding some responsive divs but still it didn't workout.
It would be great if someone help me to find out the way to make it responsive. You can see executable code in
#import url(https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet);
#import url("https://fonts.googleapis.com/css?family=Dancing+Script");
.label-container {
margin-top: 0.5rem;
-webkit-flex-basis: 100%;
display: -webkit-flex;
-webkit-flex-wrap: nowrap;
-webkit-justify-content: space-between;
margin-bottom: 50px;
}
.label-slider {
color: #3949ab;
font-size: 14px;
font-weight: 700;
text-align: center;
-webkit-tap-highlight-color: transparent;
cursor: pointer;
}
.label-slider:nth-child(1) {
padding-left: 0px;
}
.label-slider:nth-child(2) {
padding-left: 18px;
}
.label-slider:nth-child(3) {
padding-left: 34px;
}
.label-slider:nth-child(4) {
padding-left: 32px;
}
.label-slider:nth-child(5) {
padding-left: 32px;
}
.slider-container {
width: 100%;
margin-top: 5px;
}
.slider {
-webkit-appearance: none;
-moz-appearance: none;
width: 100%;
height: 10px;
border-radius: 5px;
background: #dde5ff;
outline: none;
opacity: 0.7;
-webkit-transition: 0.2s;
transition: opacity 0.2s;
}
input[type="range"],
input[type="range"]::-moz-range-track {
-webkit-appearance: none;
-moz-appearance: none;
width: 100%;
border-radius: 5px;
background: #dde5ff;
outline: none;
transition: opacity 0.2s;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #2b8aeb;
cursor: pointer;
outline: none;
}
input[type="range"]::-moz-range-thumb {
-moz-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #1492ea;
cursor: pointer;
outline: none;
z-index: 10;
}
input[type="range"]:focus {
outline: none;
}
<body>
<p class="title">Range Sliders</p>
<h4>Range Slider without steps</h4>
<div class="slider-container">
<input type="range" min="0" max="4" class="slider">
</div>
<div class="label-container">
<div class="label-slider">None</div>
<div class="label-slider">1</div>
<div class="label-slider">2</div>
<div class="label-slider">3</div>
<div class="label-slider">4+</div>
</div>
</body>
Just replace width: 600px by max-width:600px; in container.
For the font-size, I would recommand you to set font size based in rem. and set breakpoints font-size on your html element to size as you wish. as this subject: Rem not compatible with media queries?
Ad I will also recommand you to remove container padding-left and right when you under a certain width of screen, this way, the scale will stay well align with your input.
Edit
To fix the the container label, I set them with position absolute.
First step add position relative on container:
.label-container{
position:relative;
}
Then add position: absolute on labels:
.label-slider{
position: absolute;
}
And finaly just Adjust correctly with absolute as follow:
.label-slider:nth-child(1) {
left:0;
}
.label-slider:nth-child(2) {
left:25%;
transform: translateX(-25%);
margin-left: 1%;
}
.label-slider:nth-child(3) {
left:50%;
transform: translateX(-50%);
margin-left: .5%;
}
.label-slider:nth-child(4) {
right: 25%;
transform: translateX(25%);
margin-left: 1%;
}
.label-slider:nth-child(5) {
right:0;
}
DEMO FULL
#import url(https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet);
#import url("https://fonts.googleapis.com/css?family=Dancing+Script");
body {
font-family: "Catamaran", sans-serif;
background: #2b8aeb;
}
.container {
font-family: "Catamaran", sans-serif;
max-width: 600px;
margin: 30px auto 0;
display: block;
background: #fff;
padding: 10px 50px 50px;
border-radius: 4px;
box-shadow 0 6px 16px rgba(0,0,0,0.15)
}
.title {
text-align: center;
font-family: "Dancing Script", cursive;
color: #3949ab;
font-size: 35px;
}
.label-container {
margin-top: 0.5rem;
-webkit-flex-basis: 100%;
display: -webkit-flex;
-webkit-flex-wrap: nowrap;
-webkit-justify-content: space-between;
margin-bottom: 50px;
position : relative;
}
.label-slider {
color: #3949ab;
font-size: 14px;
font-weight: 700;
text-align: center;
-webkit-tap-highlight-color: transparent;
cursor: pointer;
position: absolute;
}
.label-slider:nth-child(1) {
left:0;
}
.label-slider:nth-child(2) {
left:25%;
transform: translateX(-25%);
margin-left: 1%;
}
.label-slider:nth-child(3) {
left:50%;
transform: translateX(-50%);
margin-left: .5%;
}
.label-slider:nth-child(4) {
right: 25%;
transform: translateX(25%);
margin-left: 1%;
}
.label-slider:nth-child(5) {
right:0;
}
.slider-container {
width: 100%;
margin-top: 5px;
}
.slider {
-webkit-appearance: none;
-moz-appearance: none;
width: 100%;
height: 10px;
border-radius: 5px;
background: #dde5ff;
outline: none;
opacity: 0.7;
-webkit-transition: 0.2s;
transition: opacity 0.2s;
}
input[type="range"],
input[type="range"]::-moz-range-track {
-webkit-appearance: none;
-moz-appearance: none;
width: 100%;
border-radius: 5px;
background: #dde5ff;
outline: none;
transition: opacity 0.2s;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #2b8aeb;
cursor: pointer;
outline: none;
}
input[type="range"]::-moz-range-thumb {
-moz-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #1492ea;
cursor: pointer;
outline: none;
z-index: 10;
}
input[type="range"]:focus {
outline: none;
}
.ticks {
font-family: "Catamaran", sans-serif;
color: #3949ab;
font-size: 14px;
font-weight: 700;
display: flex;
justify-content: space-between;
height: 6px;
margin: 0 10px 0 15px;
counter-reset: count -1;
}
.ticks > div {
height: 100%;
width: 1px;
background: silver;
counter-increment: count 1;
}
.ticks > div:nth-child(5n - 4) {
height: 200%;
}
.ticks > div:nth-child(5n - 4)::before {
display: block;
content: counter(count,decimal);
transform: translate(-50%, 100%);
text-align: center;
width: 16px;
}
<body>
<div class="container">
<p class="title">Range Sliders</p>
<h4>Range Slider without steps</h4>
<div class="slider-container">
<input type="range" min="0" max="4" class="slider">
</div>
<div class="label-container">
<div class="label-slider">None</div>
<div class="label-slider">1</div>
<div class="label-slider">2</div>
<div class="label-slider">3</div>
<div class="label-slider">4+</div>
</div>
</div>
</body>
I want the avatar to fill the entire circle. it should be increased, but I do not know how.
Do position: absolute and remont, its position left top, but she's out of the circle.
.photo {
display: inline-block;
width: 62px;
height: 62px;
box-sizing: border-box;
background: #f5f4f7;
border-radius: 50%;
margin-right: 17px;
padding-top: 5px;
overflow: hidden;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.photo img {
-o-object-fit: contain;
object-fit: contain;
width: 100%;
height: 100%;
-o-object-position: 50% 50%;
object-position: 50% 50%;
}
<div class="photo">
<img src="https://i.pinimg.com/originals/bc/33/b5/bc33b5e3f3604819db0e4ca66a989c9e.jpg">
</div>
A simplified version:
.photo {
display: inline-block;
width: 62px;
height: 62px;
box-sizing: border-box;
background: #f5f4f7;
border-radius: 50%;
overflow: hidden;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.photo img {
display: block;
width: 100%;
height: auto;
transform: translateY(-50%); /*center photo*/
margin-top: 50%; /*vertically with these 2 lines*/
}
<div class="photo">
<img src="https://i.pinimg.com/originals/bc/33/b5/bc33b5e3f3604819db0e4ca66a989c9e.jpg">
</div>
Try setting the image as a background as shown:
.photo {
display: inline-block;
width: 62px;
height: 62px;
box-sizing: border-box;
background: #f5f4f7;
border-radius: 50%;
margin-right: 17px;
padding-top: 5px;
overflow: hidden;
background: url(https://i.pinimg.com/originals/bc/33/b5/bc33b5e3f3604819db0e4ca66a989c9e.jpg) no-repeat center;
background-size: cover;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<div class="photo">
</div>
1. Remove padding-top: 5px; from .photo.
2. Remove everything from .photo img except height and width.
.photo {
display: inline-block;
width: 62px;
height: 62px;
box-sizing: border-box;
background: #f5f4f7;
border-radius: 50%;
margin-right: 17px;
overflow: hidden;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.photo img {
width: 100%;
height: 100%;
}
<div class="photo">
<img src="https://i.pinimg.com/originals/bc/33/b5/bc33b5e3f3604819db0e4ca66a989c9e.jpg">
</div>
I've been creating a checkbox that has a custom background image. I want to hide the checkbox, but whenever I do I am unable to check it.
HTML:
<div class="arrow">
<label for="togglearrow"></label>
<input type='checkbox' id="togglearrow"/>
<div class="arrowmenu"></div>
</div>
CSS:
#togglearrow {
display: none;
cursor: pointer;
}
.arrow {
position: absolute;
display: block;
background: url('arrow.png') no-repeat;
background-size: 65%;
height: 35px;
bottom: 0;
}
.arrowmenu {
position: absolute;
background: url('test.png') no-repeat;
background-size: 65%;
height: 35px;
bottom: 0;
right: 20px;
}
label[for="togglearrow"] {
display: block;
cursor: pointer;
}
#togglearrow:checked + .arrowmenu {
display: block;
bottom: 0;
left: 50px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
I expect that the checkbox will be hidden and can still click on "tasks.png" to check the box, however, it results in the checkbox not being able to be checked.
Your <label> element doesn't have any dimensions.
Also, I am unsure which element tasks.png is referring to.
#togglearrow {
display: none;
}
.arrow {
position: relative;
display: block;
background: url('https://unsplash.it/100') no-repeat;
background-size: 65%;
height: 35px;
bottom: 0;
}
.arrowmenu {
position: absolute;
background: url('https://unsplash.it/300') no-repeat;
background-size: 65%;
height: 35px;
bottom: 0;
right: 20px;
}
label[for="togglearrow"] {
display: block;
cursor: pointer;
width: 40px;
height: 100%;
border: 1px solid yellow;
}
#togglearrow:checked + .arrowmenu {
display: block;
bottom: 0;
left: 50px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<div class="arrow">
<label for="togglearrow"></label>
<input type='checkbox' id="togglearrow"/>
<div class="arrowmenu"></div>
</div>
I have the following two elements: a caption and a slider that I want to be displayed in one line, but I don't manage to do that.
What could I fix?
Thanks!
#biasindex {
position: fixed;
bottom: 40px;
width: 100px;
height: 15px;
right: 200px; /* "#menu width" */
font-size: 14px; /* change this value to increase/decrease button size */
/* width: 2em;
height: auto;*/
z-index: 10;
float: left;
}
.slidercaption {
display: inline-block;
float: left;
}
.slidecontainer {
width: 100%;
float: left;
display: inline-block;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
display: inline-block;
float: left;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
<div id="biasindex"><div class="slidercaption">bias index: </div><div class="slidercontainer"><input type="range" min="1" max="100" value="50" class="slider" id="biasRange">
</div></div>
Use dispaly:flex to wrap element.
Also use .slidercontainer in css instead .slidecontainer
#biasindex{
display:flex;
}
.slidercaption {
display: inline-block;
float: left;
}
.slidercontainer{
width: 100%;
float: left;
display: inline-block;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
display: inline-block;
float: left;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
<div id="biasindex">
<div class="slidercaption">bias index: </div>
<div class="slidercontainer"><input type="range" min="1" max="100" value="50" class="slider" id="biasRange">
</div>
</div>
Use flexbox. Remove float and add display flex
Below is the modified code
#biasindex {
position: fixed;
bottom: 40px;
width: 100px;
height: 15px;
right: 200px; /* "#menu width" */
font-size: 14px; /* change this value to increase/decrease button size */
/* width: 2em;
height: auto;*/
z-index: 10;
/*float: left;*/
display: flex;
}
.slidercaption {
display: inline-block;
float: left;
}
.slidecontainer {
width: 100%;
float: left;
display: inline-block;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
display: inline-block;
float: left;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
I have a webpage where I have the parent div with relative positioning, and all text with absolute positioning. I have now noticed that I cannot move around the image at all. What should I do?
http://jsfiddle.net/uchn0m5k/1/
I want the image to be behind (in terms of Z Space) the text, but as I want to add more images, I do not wish to set it as the background image:)
.button {
background-color: #08aabe;
border: none;
color: #faead3;
padding: 0.2em 0.65em;
text-decoration: none;
font-size: 2.3vw;
margin-left: 5em;
letter-spacing: 0.02em;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
-o-transition: 0.3s;
transition: 0.3s;
}
img {
max-width: 100%;
user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-drag: none;
-webkit-user-select: none;
-ms-user-select: none;
}
.container {
position: relative;
height: 100vh;
}
/* Top left text */
.top-left {
position: absolute;
top: 8px;
left: 16px;
}
.top-left h1 {
margin: 0px;
font-size: 4.5vw;
color: #08aabe;
margin-left: 2.5em;
padding-top: 3em;
padding-bottom: 0.2em;
}
body {
margin: 0px;
font-family: sans-serif;
background-color: black;
}
#squiggle {
right: 30vw;
}
<div class="container">
<img id="squiggle" src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png" style=" height:30%;">
<div class="top-left">
<h1>Lorem Ipsum.</h1>
<a class="button" href="#">Button to clcik</a>
</div>
</div>
Did you try to do like this?
.button {
background-color: #08aabe;
border: none;
color: #faead3;
padding: 0.2em 0.65em;
text-decoration: none;
font-size: 2.3vw;
margin-left: 2em;
letter-spacing: 0.02em;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
-o-transition: 0.3s;
transition: 0.3s;
}
img{
max-width: 100%;
user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-drag: none;
-webkit-user-select: none;
-ms-user-select: none;
}
.container {
position: relative;
height:100vh;
}
/* Top left text */
.top-left {
position: absolute;
top: 8px;
left: 16px;
}
.top-left h1{
margin:0px;
font-size: 4.5vw;
color: #08aabe;
margin-left: 1em;
padding-top: 1em;
padding-bottom: 0.2em;
}
body{
margin: 0px;
font-family: sans-serif;
background-color:black;
}
#squiggle{
position:absolute;
left: 22vw;
top: 29px;
}
.container{
position:relative;
}
<div class="container">
<img id="squiggle" src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png" style=" height:30%;">
<div class="top-left">
<h1>Lorem Ipsum.</h1>
<a class="button"href="#">Button to clcik</a>
</div>
</div>
So, I think this is what you're asking for? I switched up the CSS and basically added z-indexes to the "container", "img" and "top-left" elements, which moved the image of the dice behind the "top-left" container.
img{
max-width: 100%;
position: absolute;
z-index: -2;
top: 120px;
left: 40px;
user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-drag: none;
-webkit-user-select: none;
-ms-user-select: none;
}
.container {
position: relative;
height:100vh;
z-index: -3;
}
/* Top left text */
.top-left {
position: absolute;
top: 8px;
left: 16px;
z-index: -1;
}
Hope this answers your question. If not, please let me know and I'd be happy to try to figure out a better solution!
Updated Answer:
You can view this codepen.
body {
background: black;
font-family: sans-serif;
}
.logo {
position: absolute;
top: 5em;
left: 5em;
z-index: -1;
}
.logo-text {
position: absolute;
top: 4em;
left: 4em;
z-index: 1;
}
h1.logo-text {
color: #fff;
}
<div class="container">
<div class="logo">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png">
</div>
<h1 class="logo-text">Lorem Ipsum</h1>
</div>