How do i create like the image using two div?
I have search many used skew and I tried but didn't get exactly like the image.
only skew the div. not the content inside.
Here is what I have tried:
.container{
width: 100%;
}
.left{
float: left;
background: red;
height: 50px;
width: 50%;
-ms-transform: skew(-30deg, 0deg);
-webkit-transform: skew(-30deg, 0deg);
transform: skew(-30deg, 0deg);
}
.right{
float: left;
background-color: #666;
height: 50px;
width: 50%;
}
<div class="container">
<div class="left">
LEFT
</div>
<div class="right">
RIGHT
</div>
</div>
How is this. I used a gradient background and CSS grid to create two divs inside that are not skewed. A couple of caveats:
You will need to use padding on both sides to keep your text from running over the top of your color change.
You may need to use webkit for browser support of the linear gradient, depending on which older browser you intend to support.
.container {
background: linear-gradient(45deg,#FF0000 50%,#666666 50%);
display: grid;
grid-template-columns: auto auto;
width: 100%;
}
.side {
background-color: transparent;
color: #FFFFFF;
height: 50px;
}
<div class="container">
<div class="side">
test
</div>
<div class="side">
test
</div>
</div>
Related
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.
In the middle of the page is where I need the textboxes
horizontal plus vertical center is troublesome.
first center horizontally by making your parent display: flex
and include two bracketting children that stretch flex: 1 as well as your centered element (this allows it to be a perfect third, if you want it to instead be bigger, remove flex: 1 for the center child and put a width in percentage instead (pixel works but will not scale))
then center vertically by adding a margin top where you calculate leftover size :
.centeredchild {
background-color: red;
height: 20px;
flex: 1;
text-align: center;
margin-top: calc(50vh - 10px);
}
.centeringaid {
flex: 1;
}
.parent {
width: 100%;
height: 100vh;
display: flex;
background-color: lightblue;
}
<div class="parent">
<div class="centeringaid"></div>
<div class="centeredchild">hi</div>
<div class="centeringaid"></div>
</div>
there's also the more common method : https://www.w3schools.com/howto/howto_css_center-vertical.asp
this website, by the way is full of usefull tidbits.
Refer below code snippet to align your multiple text boxes in the middle of the page. (Consider page height to be 400px)
.main-div {
height: 400px;
position: relative;
}
.sub-div {
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;
}
input[type="text"] {
margin:10px auto;
border: 1px solid gray;
}
<div class="main-div">
<div class="sub-div">
<input type="text" />
<input type="text" />
<input type="text" />
</div>
</div>
You use this code:
CSS:
.outercontainer {
height: 200px;
position: relative;
border: 3px solid green;
}
.innercontainer {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
HTML:
<div class="outercontainer">
<div class="innercontainer">
<p>This sentance is it the middle!</p>
</div>
</div>
I'm trying to make a vertical button inside a div element, but I can't get the div's height to fill the remaining space.
I flipped the button using transform and I'm using Bulma for the layout. Here's the outline of my code:
.column {
border: 1px solid #ddd;
margin-top: 50px;
background: gray;
}
.button {
width: auto;
transform: rotate(90deg);
-webkit-transform: rotate(90deg);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" rel="stylesheet" />
<div class="columns">
<div class="column">
SHOW OPTIONS
</div>
</div>
Not sure what I can do here to fix this and make it responsive? I know I can always use a fixed height, but is there any way I could do it differently, so it expands with the content? Can someone please take a look and let me know if you have any suggestions? I don't even have to use transform, that just seemed like a logical option.
Thank you!
If for any reason, you can't use the writing-mode property, here is an alternative solution:
.column {
border: 1px solid #ddd;
margin-top: 50px;
background: gray;
}
.button {
width: auto;
}
.so55562898-outer {
display: inline-block;
}
.so55562898-inner {
transform: rotate(90deg);
padding-top: calc(100% - 36px);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" rel="stylesheet" />
<div class="columns">
<div class="column">
<div class="so55562898-outer">
<div class="so55562898-inner">
SHOW OPTIONS
</div>
</div>
</div>
</div>
Note that this solution requires to know the height of the button (in this case: 36px).
I hope it works for you
.column1 {
border: 1px solid #ddd;
margin-top: 50px;
background: gray;
display: block;
padding: 3.40rem;
}
.button {
width: auto;
transform: rotate(90deg);
-webkit-transform: rotate(90deg);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" rel="stylesheet" />
<div class="columns">
<div class="column1">
SHOW OPTIONS
</div>
</div>
I have to apply skew and rotate on an element. It works fine but the skewed text isn't left aligned in it's container (see the result image):
The text on the left is overflowing the container: the H (from "Hello") and the T (from "The") alignment is not right.
This is what I am trying to achieve:
.skew-parent-wrapper {
width: 300px;
margin-left: 100px;
margin-top: 50px;
border: 1px solid red;
padding-bottom: 30px;
}
.skew-text {
-moz-transform: rotate(-10deg) skew(-30deg, 0deg);
-webkit-transform: rotate(-10deg) skew(-30deg, 0deg);
-o-transform: rotate(-10deg) skew(-30deg, 0deg);
-ms-transform: rotate(-10deg) skew(-30deg, 0deg);
transform: rotate(-10deg) skew(-30deg, 0deg);
}
<div class="skew-parent-wrapper">
<h1 class="skew-text">Hello Welcome to the skew text</h1>
</div>
One way of aligning the skewed text on a vertical line is to manualy set a negative text-indent. This technique also requires to set a transform-origin on bottom left :
.skew-parent-wrapper {
width: 300px;
margin-left: 100px;
margin-top: 50px;
border: 1px solid red;
padding-top: 30px;
}
.skew-text {
transform: rotate(-10deg) skew(-30deg, 0deg);
transform-origin: 0 100%;
text-indent: -15px;
}
<div class="skew-parent-wrapper">
<h1 class="skew-text">Hello Welcome to the skew text</h1>
</div>
This technique works on text that wraps only on two lines. For text with more than 2 lines, you will need to wrap each line in a tag (like a <span>) :
.skew-parent-wrapper {
width: 300px;
margin-left: 100px;
margin-top: 50px;
border: 1px solid red;
padding-top: 30px;
}
.skew-text span{
display:block;
transform: rotate(-10deg) skew(-30deg, 0deg);
transform-origin: 0 100%;
}
<div class="skew-parent-wrapper">
<h1 class="skew-text">
<span>Hello Welcome to the</span>
<span>skewed text with</span>
<span>several lines many</span>
<span>many many lines</span>
</h1>
</div>
Note that you need to set the <span> to display:block because transforms don't apply on inline elements.
With rotation and skew you will get a behaviour like perspective so the oversizing is a result of that.
You need to manually scale down your skew-text and then disable the overflow of its container so you won't see any overlapping text.
That's the only idea for me to fix this.
It's hard to achieve the alignment if you use a rotation as transform.
Use a skew to get the inclined lines. You can (to some extent) get the angle on the letters using italics
Also, there is no need for all the vendor specific tranforms
.skew-parent-wrapper {
width: 300px;
margin-left: 100px;
margin-top: 50px;
border: 1px solid red;
padding-bottom: 30px;
}
.skew-text {
transform: skewY(-20deg);
font-style: italic;
background-color: goldenrod;
}
<div class="skew-parent-wrapper">
<h1 class="skew-text">Hello Welcome to the skewed text that can span several lines</h1>
</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