Vertical menu with rotated text at 100% height - html

I've followed this How to make vertically rotated links in HTML? but I've to improve this solution.
I need to have a vertical menu that fits the entire height of the windows and divides it in three part (cause I've three menu links to show).
How can I update the code suggested in that solution?

Try this:
CSS
#container {
overflow: hidden;
width: 50px;
height: 100%;
position: absolute;
top: 0;
left: 0;
display: table;
}
.section {
position: relative;
height: 33.33333%;
display: table-row;
background: #ccc;
text-align: center;
}
.section .link {
display: table-cell;
vertical-align: middle;
line-height: 50px;
white-space:nowrap;
max-width:50px;
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-ms-transform: rotate(270deg);
-o-transform: rotate(270deg);
}
.section:hover { background: #ddd }
HTML
<div id="container">
<div class="section">aaa</div>
<div class="section">bbb</div>
<div class="section">ccc</div>
</div>
DEMO JSFiddle

My suggestion is to use display: table CSS property as follow:
EDITED
HTML
<div class="container">
<div class="container-child">row 1</div>
<div class="container-child">row 2</div>
<div class="container-child">row 3</div>
</div>
CSS
html, body {
text-align: center;
width: 100%;
height: 100%;
}
.container {
display: table;
width: 100%;
height: 100%;
}
.container-child {
display: table-row;
-ms-transform:rotate(270deg); /* IE 9 */
-moz-transform:rotate(270deg); /* Firefox */
-webkit-transform:rotate(270deg); /* Safari and Chrome */
-o-transform:rotate(270deg); /* Opera */
}
CODE
the transform: rotate() allows you to rotate the orientation of the text.

Related

Hexagon with 90deg rotate does not grow inside container

I have the following problem with my hexagons. With the code below it works fine and the hexagon stays within its container.
.hexagon-2 .content {
position: absolute;
z-index: 2;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
padding: 30px;
text-align: center;
}
.wrapper {
width: 100%;
/* This is the only value you need to change */
}
.container-2 {
position: relative;
width: 100%;
padding-bottom: 86.6%;
/* This sets the height of the div to 86% of its width */
border: 1px dashed green;
/* Just for demonstration purposes*/
transform: rotate(90deg);
}
.hexagon-2 {
position: absolute;
/* so .hexagon isn't pushed out of .container by the padding */
left: 25%;
width: 50%;
height: 100%;
margin: 0 auto;
/* center .hexagon inside .container*/
background-color: red;
/* color of the hexagon */
}
.hexagon-2:before,
.hexagon-2:after {
display: block;
position: absolute;
/* otherwise :after is below the hexagon */
top: 0;
content: '';
width: 100%;
height: 100%;
background-color: inherit;
}
.hexagon-2:before {
-webkit-transform: rotate(60deg);
-moz-transform: rotate(60deg);
-ms-transform: rotate(60deg);
transform: rotate(60deg);
}
.hexagon-2:after {
-webkit-transform: rotate(120deg);
-moz-transform: rotate(120deg);
-ms-transform: rotate(120deg);
transform: rotate(120deg);
}
<div class="container">
<div class="row">
<div class="col-lg-6">
<div class="wrapper">
<div class="container-2">
<div class="hexagon-2">
<span class="content">Test test test</span>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="wrapper">
<div class="container-2">
<div class="hexagon-2">
<span class="content">Test test test</span>
</div>
</div>
</div>
</div>
</div>
</div>
As long as I leave the hexagon that way, it works exactly as it should. However, when I rotate the hexagon 90 degrees, it goes wrong.
When I add this line to the .container-2 class:
transform: rotate(90deg);
The hexagons behave like this:
Because of the rotate they no longer fill out the container. Is there a clean way to solve this. I have already tried everything with these hexagons but no luck so far.
Anybody got an idea that I can stil rotate the hexagon but that it stil fills out the container?
Thanks
Just off the top of my head looking at this the reason it's not filling out the container is because the width of the hexagon is different. If you want it to fill exactly the same size when it is rotating make sure point to point is the same width as flat edge to flat edge. I did a quick check and point to point is 310 pixels and flat edge to flat edge is 263 pixels. Hope this helps.

HTML and CSS irregular triangle image gallery

I need to create an image gallery, in which the individual images are irregular triangles (emphasis on irregular).
I found limited examples on how to achieve triangle images via html and css, without modifying the images themselves. One example I found in this CodePen https://codepen.io/thebabydino/pen/liDCz was a step in the right direction, but looking at it, I can't find a way to make the images irregular triangles.
The result I am trying to achieve is this:
<div class='pageOption'>
<a href='#' class='option'>
<img src='~/images/team/pic_paggas/A.png'>
</a>
<a href='#' class='option'>
<img src='~/images/team/pic_paggas/D.png'>
</a>
</div>
This is the basic HTML I will be using and the CSS is:
.pageOption {
overflow: hidden;
position: relative;
margin: 0 auto;
width: 40em;
height: 27em;
}
.option, .option img {
width: 100%;
height: 100%;
}
.option {
overflow: hidden;
position: absolute;
transform: skewX(-55.98deg);
}
.option:first-child {
left: -.25em;
transform-origin: 100% 0;
}
.option:last-child {
right: -.25em;
transform-origin: 0 100%;
}
.option img {
opacity: .75;
transition: .5s;
}
.option img:hover {
opacity: 1;
}
.option img, .option:after {
transform: skewX(55.98deg);
transform-origin: inherit;
}
Mind that the HTML and CSS I have may not be the optimal for my problem. I think the shape of the images I am using (rectangular) have something to do with this.
Would be better if the solution is better supported across browsers.
You can do it with skew like below if you cannot use clip-path:
.box {
overflow: hidden;
width: 200px;
height: 200px;
display:inline-block;
}
.triangle {
width: 100%;
height: 100%;
transform: skewX(-20deg) skewY(45deg); /* 27deg instead of 20deg to have a regular triangle */
transform-origin: bottom left;
overflow: hidden;
background-size:0 0;
}
.triangle.bottom {
transform-origin: top right;
}
.triangle:before {
content: "";
display: block;
width: inherit;
height: inherit;
background-image: inherit;
background-size:cover;
background-position:center;
transform: skewY(-45deg) skewX(20deg); /* We invert order AND signs*/
transform-origin: inherit;
}
.triangle:hover {
filter:grayscale(100%);
}
.adjust {
margin-left:-120px;
}
body {
background:#f2f2f2;
}
<div class="box">
<div class="triangle" style="background-image:url(https://picsum.photos/id/155/1000/800)"></div>
</div>
<div class="box adjust">
<div class="triangle bottom" style="background-image:url(https://picsum.photos/id/159/1000/800)"></div>
</div>

Div float next to non float div

I have a container div for the main content but am trying to have a sidebar float to the left of it. For example (http://www.bureautonic.com/en/) the menu button.
This is the code
.main-wrapper {
position: relative;
top: 50%;
height: 500px;
}
.container {
position: relative;
height: 100%;
}
.body {
height: 100%;
}
.slider {
display: block;
width: 940px;
height: 500px;
margin-right: auto;
margin-left: auto;
float: none;
}
.img {
position: absolute;
width: 100%;
height: 100%;
max-height: 100%;
}
.tagline {
position: absolute;
left: 50%;
top: 50%;
z-index: 1;
display: block;
width: 332px;
margin-right: auto;
margin-left: auto;
padding: 1em 3em;
border: 1px solid white;
-webkit-transform: translate(-50%, 0px) translate(0px, -50%);
-ms-transform: translate(-50%, 0px) translate(0px, -50%);
transform: translate(-50%, 0px) translate(0px, -50%);
font-family: 'Josefin Sans', sans-serif;
color: white;
text-align: center;
text-decoration: none;
text-transform: none;
}
.header {
margin-top: 33px;
margin-bottom: -61px;
}
.brand {
font-family: Cardo, sans-serif;
text-align: center;
}
<body class="body">
<div class="w-section container">
<div class="w-container header">
<h1 class="brand">The One And Only</h1>
</div>
<div class="w-container main-wrapper">
<div data-animation="outin" data-duration="500" data-infinite="1" data-easing="ease-in-cubic" data-hide-arrows="1" class="w-slider slider">
<div class="w-slider-mask">
<div class="w-slide slide">
<div class="tagline">
<h1>Marc Cain</h1>
<h3>F/W 2015-16</h3>
</div>
<img width="846" src="http://uploads.webflow.com/567a26541a69a693654038a1/567b15da06a9675444fc740d_marc_cain_campaign.jpg" class="img">
</div>
</div>
<div class="w-slider-arrow-left">
<div class="w-icon-slider-left"></div>
</div>
<div class="w-slider-arrow-right">
<div class="w-icon-slider-right"></div>
</div>
<div class="w-slider-nav"></div>
</div>
</div>
</div>
</body>
I'm using webflow and uploaded the site for you guys http://the-one-and-only.webflow.io/
I originally tried making another absolute div with a set width and 100% height, but the menu button wasn't relative to the main container. Any help would be appreciated.
Give this a look, it mimics what http://www.bureautonic.com/en/ has for their menu
$(function() {
$('#menu-container').click(
function() {
ToggleMenu();
}
);
});
function ToggleMenu() {
var $menu = $('#menu');
var newleft = +$menu.css('left').replace('px', '') <= -150 ? '0' : '-300px';
$('#menu').css('left', newleft);
}
#menu,
#content {
width: 300px;
height: 200px;
}
#menu-container {
display: inline-block;
height: 200px;
width: 30px;
background-color: yellow;
position: relative;
}
#menu {
display: inline-block;
position: absolute;
}
#content {
display: inline-block;
position: relative;
overflow: hidden;
background-color: red;
}
#menu {
transition: left 1s;
left: -300px;
background-color: orange;
}
#menu-label {
-moz-transform: translateX(-50%) translateY(-50%) rotate(-90deg);
-webkit-transform: translateX(-50%) translateY(-50%) rotate(-90deg);
transform: translateX(-50%) translateY(-50%) rotate(-90deg);
position: absolute;
top: 50%;
text-align: center;
width: 200px;
left: 50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div id="menu-container">
<div id="menu-label">
This is my Menu Label
</div>
</div>
<div id="content">
This is the content
<div id="menu">
Menu
</div>
</div>
For the sliding menu
The basic concept is a parent div with position:relative and overflow:hidden , and a child div with position:absolute, beginning with a negative left equal to the width of the div
I used the css transition property for the smooth slide effect
Edit:
For the left aligned & rotated menu label
This effect is created with a combination of several properties.
My code block has been updated with the appropriate css.
See here http://jsfiddle.net/CCMyf/79/ (not my fiddle) for alterations
to the css if you need to have a dynamic height
If you want to float a menu to left of the main content, you need to firstly create the menu element that you want to be the menu (obviously), then float it to the left with float: left. e.g.
HTML
<div class="floated-menu">
Menu
</div>
CSS
.floated-menu {
float: left;
width: 50px;
height: 600px;
background-color: #ccc;
}
Then you have to float the main content container as well. .e.g
.container {
float: left;
position: relative;
width: 800px;
height: 100%;
}
I could be wrong, but I believe if you don't float both the items, the normal (non-floated context) behaviour of the container divs display: block; property kicks in and it will move down the page to the next "line". Which is weird because all items next to something thats floated should lose their display block behaviour and sit next to the floated item - i.e. float was originally intended to make block type headings and paragraphs sit next to pictures like in a magazine or newspaper, but yep, welcome to the world of CSS - you fill find many nonsensical things like this.
Also, the combined width of both floated elements border box (the widest and largest of the boxes that an element is contained in) cannot be wider than their parent element - other wise the second element will drop down to the next line - which actually does make sense. I have reduced the sizes for you in my demo, but you will have to manage that as you build your page.
You also need to remember that, by default the browser uses the
"content-box" box-sizing property. from the docs
content-box
This is the default style as specified by the CSS standard. The width
and height properties are measured including only the content, but not
the padding, border or margin. Note: Padding, border & margin will be
outside of the box e.g. IF .box {width: 350px}; THEN you apply
{border: 10px solid black;} RESULT {rendered in the browser} .box
{width: 370px;}
Here is a demo - http://codepen.io/anon/pen/QyKyVV?editors=110

translateY(-50%) blurring child elements

For some reason my vertical alignment code is blurring some but not all child elements in Chrome and Safari.
Whats causing it is the translateY(-50%), if I remove this then blurriness is gone however the vertical centring effect is lost.
/* #group Center all the things */
.center-wrapper {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.center-wrapper .center {
position: relative;
overflow: hidden;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
/* This fixes the blurred buttons but breaks centering
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
transform: translateZ(0);*/
}
/* #end */
Tried and tested methods such as below work but they break the vertical centring:
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
transform: translateZ(0);
Faced the same issue while trying to position buttons in the middle, but the button appeared on hover of the parent element and each time text inside was randomly cut.
The solution is:
.positioned-button {
transform: translateY(-50%) scale(1);
filter: blur(0);
line-height: 1;
}
Breaks nothing, fixes Chrome :)
The only way around this blurry issue, from what I could see was to change the vertical alignment method and use display: table instead. Here's how I did it:
1) Keep HTML markup the same
<div class="center-wrapper">
<div class="center">
<p>Centered content here</p>
</div>
</div>
2) Change CSS to the following:
/* #group Center all the things */
.center-wrapper {
min-height: 100%;
padding: 0;
display: table;
width: 100%;
}
.center-wrapper .center {
display: table-cell;
vertical-align: middle;
}
/* #end */
You can see the display table in action here.
.center-wrapper {
min-height: 200px;
padding: 0;
display: table;
width: 100%;
background: black;
}
.center-wrapper .center {
display: table-cell;
vertical-align: middle;
color: white;
}
.center-wrapper .center div {
height: 40px;
background: red;
width: 50%;
margin: 0 auto;
}
<div class="center-wrapper">
<div class="center">
<div>Centered content here</div>
</div>
</div>

How to vertically center image in this responsive, flippable circle?

In a Rails 3.2 app I am displaying user avatars using a responsive, flippable CSS circle. But due to padding needed on a parent element, the avatar is not centered in the circle.
How can I center this circle? Where possible, I would prefer to keep this semantically marked up with an img tag, rather than as a background image on a div.
Also, can this be optimized? I've a lot of nested divs at present!
The code is below, and a jsfiddle here.
<div class='responsive-container'>
<div class='responsive-inner'>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flip-inner">
<div class="front">
<div class="circle">
<div class="circle-inner">
<%= image_tag #user.avatar %>
</div>
</div>
</div>
<div class="back">
<div class="circle">
<div class="circle-inner">
<%= #user.name %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
.responsive-container{
position: relative;
width: 50%;
}
.responsive-container:before{
content: "";
display: block;
padding-top: 100%;
}
.responsive-inner{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.flip-container {
perspective: 1000;
-webkit-perspective: 1000; /* Safari and Chrome */
}
/* flip the pane when hovered */
.flip-container:hover .flip-inner, .flip-container.hover .flip-inner {
transform: rotateY(180deg);
-ms-transform:rotateY(180deg); /* IE 9 */
-webkit-transform:rotateY(180deg); /* Safari and Chrome */
}
.flip-inner {
transition: 0.6s;
-webkit-transition: 0.6s; /* Safari */
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d; /* Safari and Chrome */
position: relative;
}
.front, .back {
backface-visibility: hidden;
-webkit-backface-visibility:hidden; /* Chrome and Safari */
-moz-backface-visibility:hidden; /* Firefox */
-ms-backface-visibility:hidden; /* Internet Explorer */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.front {
z-index: 2;
}
.back {
transform: rotateY(180deg);
-ms-transform:rotateY(180deg); /* IE 9 */
-webkit-transform:rotateY(180deg); /* Safari and Chrome */
}
.circle {
width: 100%;
height: 0;
padding: 50% 0; //padding top & bottom must equal width
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
overflow: hidden;
border: 1px #000 solid;
}
.circle-inner {
display: table;
width:100%;
}
.circle-inner img {
height: auto;
width: 100%;
}
.circle-inner p {
display: table-cell;
vertical-align: middle;
text-align: center;
}
</style>
why dont you use border-radius instead of circle? will be much easier i think.
http://bavotasan.com/2011/circular-images-with-css3/