I want to align the bars to the bottom here: http://jsfiddle.net/7vdLV/67/
I tried using the following trick:
.graph { position: relative; }
.weekbar { position: absolute; bottom: 0; left: 0; }
However it breaks the graph, can anyone tell me how I should do it please in this scenario?
Tweaked the HTML a bit as well as the CSS and got this: http://jsfiddle.net/7vdLV/74/
<div class="graph">
<div class="weekbar"><div style="height: 10%;"></div></div>
<div class="weekbar"><div style="height: 20%;"></div></div>
<div class="weekbar"><div style="height: 30%;"></div></div>
<div class="weekbar"><div style="height: 40%;"></div></div>
</div>
As TylerH pointed out inline styles are considered bad practice so you would be better replacing them with classes i.e.
<div class="graph">
<div class="weekbar"><div class="h10"></div></div>
<div class="weekbar"><div class="h20"></div></div>
<div class="weekbar"><div class="h30"></div></div>
<div class="weekbar"><div class="h40"></div></div>
</div>
.h10 {
height: 10%;
}
Try transform:
-moz-transform: scaleY(-1);
-o-transform: scaleY(-1);
-webkit-transform: scaleY(-1);
transform: scaleY(-1);
filter: FlipV;
-ms-filter: "FlipV";
http://jsfiddle.net/L4A2h/1/
Just replace the .graph class with the following code
.graph {
width: 100%;
height: 200px;
background-color: #eaeaea;
-moz-transform: scaleY(-1);
-o-transform: scaleY(-1);
-webkit-transform: scaleY(-1);
transform: scaleY(-1);
filter: FlipH;
-ms-filter: "FlipH";
}
Hope this Helps
Simplest solution:
apply
.weekbar{
position:relative;
display:inline-block;
top:50%; // height of biggest bar
}
Check this JSFiddle
Or if ancient browser support is not a big deal you can make use of the ::before element as follows:
.graph::before{
content:"";
display:block;
height:50%; // height of the biggest bar
}
.weekbar{
display:inline-block;
}
check this JSFiddle
Make these edits to your CSS:
.graph { position:relative; }
.weekbar { position: relative; top: 100%; left: 0; }
Is this what you were looking to do?
http://jsfiddle.net/4HEEk/
You can use position:relative; for the parent and position:relative; also for the child and calculate the top value by this jQuery code:
$(document).ready(function() {
var parentHeight = $('.graph').height();
$('.weekbar').each(function() {
var height = parentHeight - $(this).height();
$(this).css('top',height*100/parentHeight + '%');
});
});
Here is a working fiddle
I would change float for display:inline-block; then set an "invisible" resetter div at the start of your graph to make sure all the elements start from the bottom (rather from the bottom of the tallest line.
.weekbar {
width: 3.1%;
margin-left: -4px;
margin-right: 2%;
display:inline-block;
background-color: #aeaeae;
}
.resetter{
height:100%;
display:inline-block;
width:0;
margin-right:-4px;
}
Have a look at this JSFiddle.
Also on a note about inline style usage (dont do it!). If you know that you have a discrete number of heights (ie. in your example they are all multiples of 10) i would suggest creating classes for them.
Related
I need code for this functionality.
By default, it should be like right headed arrow and when i click it should be down headed arrow.
Thanks,
Ram
You can do it by using javascript. If you don't know how to use javascript, refer to the code below.
<html>
<head>
<title>Title</title>
<script type="text/javascript>
function myFunction(){
document.getElementById('img').src = "down.jpg";
}
</script>
<body>
<img src="right.jpg" id="img" onclick="myFunction();"/>
</body>
</html>
Enjoy :D
As you can see, we fetch the element in js using its id and change its src attribute and set it to your another image. You can change the event which is onclick as per your needs. You can use ondblclick to trigger the function on double click. ^-^
This may help you #pbrc1995 :)
function myFunction(x) {
x.classList.toggle("change");
}
.container {
display: inline-block;
cursor: pointer;
}
.bar1, .bar2, .bar3 {
width: 35px;
height: 5px;
background-color: #333;
margin: 6px 0;
transition: 0.4s;
}
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
transform: rotate(-45deg) translate(-9px, 6px) ;
}
.change .bar2 {opacity: 0;}
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-8px, -8px) ;
transform: rotate(45deg) translate(-8px, -8px) ;
}
<p>Click on the Menu Icon to transform it to "X":</p>
<div class="container" onclick="myFunction(this)">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
Since you are not asking for a JavaScript solution, here's one without it.
div.arrow {
width:33px; height:30px;
background:url('https://i.stack.imgur.com/yMatp.png');
}
div.arrow:active{
width:51px; height:26px;
background:url('https://i.stack.imgur.com/M3Bew.png');
}
<div class="arrow"></div>
I'm trying to make different classes for alignment.
I want to be able to combine it like class="left bottom" using the transform:translate property.
The problem is that the property is being overridden by each other.
If you have a look at my fiddle and open up the debugger you will notice that translateX(50%) has been overridden by translateY(25%). Shouldn't they be combined like translate(50%,25%)?
.container {
background: gray;
height: 100px;
width: 100%;
}
.left {
transform: translateX(50%);
}
.bottom {
transform: translateY(25%);
}
<div class="container">
<div class="left bottom">
I should be aligned
</div>
</div>
https://jsfiddle.net/r2LmfqLs
This is perfectly correct, because you are changing the transform parameter.
You have to nest them:
.left.bottom {
transform: translateX(50%) translateY(25%);
}
Or combine them to one class:
.left-bottom {
transform: translateX(50%) translateY(25%);
}
No, there is only one transform property but two values, so which ever comes last...wins.
You could make one "combined" class...like so.
.container {
background:gray;
height:100px;
width:100%;
}
.left {
transform:translateX(50%);
}
.bottom {
transform:translateY(25%);
}
.left.bottom {
transform:translateX(50%) translateY(25%);
}
I'm trying to set up a fixed div to the left of a page, 24px from the left and stretching from top to bottom of the page. Inside this div will be navigation and a title. I'm trying to get the title rotated -90 degrees and centered positioned toward the bottom of the div.
Having a tough time figuring this out. Looked around a lot of places and not seeing a similar example. I've set up a fiddle with the current code: https://jsfiddle.net/xkLc9xuy/2/
HTML:
<div>
<article></article>
<footer></footer>
<header></header>
<nav data-secondary></nav>
<nav data-primary>
<div>Website Title</div>
</nav>
</div>
SCSS:
#mixin -position($position:relative, $top:0, $right:0, $bottom:0, $left:0) {
position: $position;
#if $position !=relative {
top: $top;
right: $right;
bottom: $bottom;
left: $left;
}
}
#mixin -transform($transform) {
-ms-transform: $transform;
-webkit-transform: $transform;
transform: $transform;
}
#mixin -transform-origin($origin) {
-ms-transform-origin: $origin;
-webkit-transform-origin: $origin;
transform-origin: $origin;
}
body{
*:not(script){
margin:0;
padding:0;
#include -position;
}
> div{
#include -position(absolute);
}
}
nav[data-primary]{
box-shadow:0 0 8px rgba(0,0,0,0.5);
width:40px;
#include -position(absolute, 0, auto, 0, 24px);
> div{
white-space:nowrap;
height:40px;
line-height:40px;
background-color:red;
#include -transform(rotate(-90deg));
#include -transform-origin(left bottom);
}
}
You may also take a look at writing-mode:
-webkit-writing-mode: vertical-lr;
/* old Win safari */
writing-mode: vertical-rl;/*FF*/
writing-mode: tb-lr;
/* writing-mode:sideways-lr;
or eventually scale(-1,-1) untill sideways-lr is working everywhere */
transform: scale(-1, -1);
https://jsfiddle.net/xkLc9xuy/20/
I'm trying to get a square div that says "read more" when hovering over a circle div with a picture inside it. Been trying different things and haven't found a working solution on google.
HTML
<div class = "portfolio" id = "first"> <!-- makes the circle -->
<a href = "cake-page.html">
<div class = "readm"> Read more </a> </div>
<img src = "cake.jpg" />
<p> The cake </p> </div>
CSS
.portfolio {
/* the circles on the portfolio-page */
position: relative;
border-radius: 100%;
display: inline-block;
height: 150px;
width: 150px;
border: 2px solid purple;
}
.portfolio.img {
opacity: 1;
transition: 1s ease;
background-size: 90px 0px;
overflow: hidden;
border-radius: 100px;
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
width: 150px;
height: 150px;
}
.portfolio:hover {
/* hover effect on portfolio circles */
opacity: 0.6;
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
transition: 1 ease;
visibility: visible;
}
So either the text pushed the image down or it stays in the top of the circle and I can't get it to hover together with the other hover effect. I want the "read more" to pop-up in a rectangular div when hovering over together with the other hover effect.
I did not include the div class "readm" since I can't get it to work. FYI I'm pretty new to this. Thanks.
A little tough without a working example and it'd be good to see the readm css since we need to see what isn't working. That said, have you tried something like this:
.readm {
opacity:0;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
}
.portfolio:hover .readm {
opacity:1;
}
Also I would place the start of that a tag inside the readm div.
First, you need to fix your markup.
You are closing the anchor ("a") tag before closing a DIV. That alone will make your CSS fail.
I presume you want to close the DIV like so:
<div class="readm">Read more</div>
I'm trying to create a cube with CSS. I actually think it's already there but I can't see it.
Feel free to edit the fiddle.
I don't understand why the perspective is not working.
Is this best practice?
Is it possible to rotate the cube as a whole??
Source: 24ways.
HTML:
<section class="container">
<div id="cube">
<figure class="front">1</figure>
<figure class="back">2</figure>
<figure class="right">3</figure>
<figure class="left">4</figure>
<figure class="top">5</figure>
<figure class="bottom">6</figure>
</div>
</section>
CSS:
.container {
margin: 200px auto;
width: 200px;
height: 200px;
position: relative;
-webkit-perspective: 800px;
}
#cube {
width: 100%;
height: 100%;
position: absolute;
-webkit-transform-style: preserve-3d;
}
#cube figure {
width: 198px;
height: 198px;
display: block;
position: absolute;
border: 1px solid #ddd;
background-color: rgba(0,0,0,0.2);
}
#cube .front { -webkit-transform: rotateY(0deg) translateZ(100px); }
#cube .back { -webkit-transform: rotateX(180deg) translateZ(100px); }
#cube .right { -webkit-transform: rotateY(90deg) translateZ(100px); }
#cube .left { -webkit-transform: rotateY(-90deg) translateZ(100px); }
#cube .top { -webkit-transform: rotateX(90deg) translateZ(100px); }
#cube .bottom { -webkit-transform: rotateX(-90deg) translateZ(100px); }
The problem could be that the hardware acceleration was not supported on your PC and it was on your mac... css3d transformations such as rotateX and rotateY require hardware accelerations.
in chrome go to your address bar and enter
chrome://gpu
you will see
3D CSS: Unavailable. Hardware acceleration disabled.
if this is the case then 3d cube is not visible.
Have a look at http://css3.bradshawenterprises.com/transforms/#transDemo3.
I have a wrapper around the cube that I rotate - in this case to keep it simple, I actually use three divs, one for X, one for Y and one for Z.
The playground underneath should show you how perspective etc work.
I used to work with a lot of 3D Transforms a while ago but recently noticed that CSS3 perspective does not have any effect on my web browsers including Chrome.
Tried the following and it helped in Google Chrome:
Navigate to "chrome://flags"
Find an item labeled "Override software rendering list" and disable it
Relaunch your browser
I know its a bit late but just in case it might help you...