I have created a polygon triangle and I want to stack them next to each other
I have used shape-outside however it does not seem to be working.
I want this to be dynamic so more can be added without the need to change the code
div:nth-child(odd) {
width: 280px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
float: left;
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
shape-outside: polygon(50% 0%, 0% 100%, 100% 100%);
}
div:nth-child(even) {
width: 280px;
height: 280px;
background: #1e90ff;
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
float: left;
-webkit-clip-path: polygon(50% 100%, 0 0, 100% 0);
clip-path: polygon(50% 100%, 0 0, 100% 0);
shape-outside: polygon(50% 100%, 0 0, 100% 0);
left: -137px;
}
div {
position: relative;
}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
Simply adding margin-right: -274px; to div:nth-child(even) does the trick.
div:nth-child(odd) {
width: 280px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
float: left;
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
shape-outside: polygon(50% 0%, 0% 100%, 100% 100%);
}
div:nth-child(even) {
width: 280px;
height: 280px;
margin-right: -274px;
background: #1e90ff;
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
float: left;
-webkit-clip-path: polygon(50% 100%, 0 0, 100% 0);
clip-path: polygon(50% 100%, 0 0, 100% 0);
shape-outside: polygon(50% 100%, 0 0, 100% 0);
left: -137px;
}
div {
position: relative;
}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
You could use the pseudo selector of
:nth-child(even)
in order to select all 'even' elements.
I haven't used the clip-path (due to browser compatibility issues), so this wouldn't be the cleanest, but this (should) work on more browsers:
.parent {
height: 100px;
width: 100px;
margin: 2px;
display: inline-block;
position: relative;
overflow: hidden;
margin-left: -50px;
}
.parent:nth-child(odd) {
top: -50px;
}
.parent:first-child {
margin-left: 0;
}
.parent:nth-child(odd) .child {
position: absolute;
bottom: 0;
left: 0;
background: tomato;
height: 70%;
width: 70%;
transform: rotate(45deg);
transform-origin: bottom left;
}
.parent:nth-child(even) .child {
position: absolute;
top: 0;
left: 0;
background: tomato;
height: 70%;
width: 70%;
transform: rotate(-45deg);
transform-origin: top left;
}
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
I have fixed your css quickly (so pardon mistakes) , now they are aligning next to each other and you can add how many you want and they will alignt as long as there is space.
div:nth-child(odd) {
width: 280px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
/* float: left; */
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
shape-outside: polygon(50% 0%, 0% 100%, 100% 100%);
margin-left: -141px;
}
and
div:nth-child(even) {
width: 280px;
height: 280px;
background: #1e90ff;
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
/* float: left; */
-webkit-clip-path: polygon(50% 100%, 0 0, 100% 0);
clip-path: polygon(50% 100%, 0 0, 100% 0);
shape-outside: polygon(50% 100%, 0 0, 100% 0);
/* left: -137px; */
margin-left: -141px;
}
and
body:nth-child(1){
margin-left:0; /* To clear the first marign */
}
Related
I have created a polygon triangle and I want to stack them next to each other
I have used shape-outside however it does not seem to be working.
I want this to be dynamic so more can be added without the need to change the code
div:nth-child(odd) {
width: 280px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
float: left;
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
shape-outside: polygon(50% 0%, 0% 100%, 100% 100%);
}
div:nth-child(even) {
width: 280px;
height: 280px;
background: #1e90ff;
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
float: left;
-webkit-clip-path: polygon(50% 100%, 0 0, 100% 0);
clip-path: polygon(50% 100%, 0 0, 100% 0);
shape-outside: polygon(50% 100%, 0 0, 100% 0);
left: -137px;
}
div {
position: relative;
}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
Simply adding margin-right: -274px; to div:nth-child(even) does the trick.
div:nth-child(odd) {
width: 280px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
float: left;
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
shape-outside: polygon(50% 0%, 0% 100%, 100% 100%);
}
div:nth-child(even) {
width: 280px;
height: 280px;
margin-right: -274px;
background: #1e90ff;
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
float: left;
-webkit-clip-path: polygon(50% 100%, 0 0, 100% 0);
clip-path: polygon(50% 100%, 0 0, 100% 0);
shape-outside: polygon(50% 100%, 0 0, 100% 0);
left: -137px;
}
div {
position: relative;
}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
You could use the pseudo selector of
:nth-child(even)
in order to select all 'even' elements.
I haven't used the clip-path (due to browser compatibility issues), so this wouldn't be the cleanest, but this (should) work on more browsers:
.parent {
height: 100px;
width: 100px;
margin: 2px;
display: inline-block;
position: relative;
overflow: hidden;
margin-left: -50px;
}
.parent:nth-child(odd) {
top: -50px;
}
.parent:first-child {
margin-left: 0;
}
.parent:nth-child(odd) .child {
position: absolute;
bottom: 0;
left: 0;
background: tomato;
height: 70%;
width: 70%;
transform: rotate(45deg);
transform-origin: bottom left;
}
.parent:nth-child(even) .child {
position: absolute;
top: 0;
left: 0;
background: tomato;
height: 70%;
width: 70%;
transform: rotate(-45deg);
transform-origin: top left;
}
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
I have fixed your css quickly (so pardon mistakes) , now they are aligning next to each other and you can add how many you want and they will alignt as long as there is space.
div:nth-child(odd) {
width: 280px;
height: 280px;
background: #1e90ff;
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
/* float: left; */
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
shape-outside: polygon(50% 0%, 0% 100%, 100% 100%);
margin-left: -141px;
}
and
div:nth-child(even) {
width: 280px;
height: 280px;
background: #1e90ff;
display: inline-block;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/Harry-Potter-1-.jpg) center center;
background-size: cover;
/* float: left; */
-webkit-clip-path: polygon(50% 100%, 0 0, 100% 0);
clip-path: polygon(50% 100%, 0 0, 100% 0);
shape-outside: polygon(50% 100%, 0 0, 100% 0);
/* left: -137px; */
margin-left: -141px;
}
and
body:nth-child(1){
margin-left:0; /* To clear the first marign */
}
I have little problem with my header. I want to create something like this:
I made this, but I couldn't get the third div to appear on the same line as the others. How can I do that?
I've tried Float: left and tried, display
.logo {
float:left;
height: 80px;
width:100%;
background-color: green;
-webkit-clip-path: polygon(0 0, 18% 0, 20% 100%, 0 100%);
clip-path: polygon(0 0, 18% 0, 23% 100%, 0 100%);
}
.photo1 {
background-color: red;
background-size: cover;
background-position: center center;
width: 100%;
height: 80px;
-webkit-clip-path: polygon(18% 0, 61% 0, 66% 100%, 23% 100%);
clip-path: polygon(18% 0, 61% 0, 66% 100%, 23% 100%);
}
.photo2 {
background-color:brown;
background-size: cover;
background-position: left center;
height: 80px;
-webkit-clip-path: polygon(62% 0, 100% 0, 100% 100%, 67% 100%);
clip-path: polygon(62% 0, 100% 0, 100% 100%, 67% 100%);
}
<div class="header">
<div class="logo"></div>
<div class="photo1"></div>
<div class="photo2"></div>
</div>
Set 3 DIVs:
position: absolute;
width: 100%;
Also adjust the polygon size of .photo2
.logo {
position: absolute;
height: 80px;
width:100%;
background-color: green;
-webkit-clip-path: polygon(0 0, 18% 0, 20% 100%, 0 100%);
clip-path: polygon(0 0, 18% 0, 23% 100%, 0 100%);
}
.photo1 {
position: absolute;
background-color: red;
background-size: cover;
background-position: center center;
width: 100%;
height: 80px;
-webkit-clip-path: polygon(18% 0, 61% 0, 66% 100%, 23% 100%);
clip-path: polygon(18% 0, 61% 0, 66% 100%, 23% 100%);
}
.photo2 {
position: absolute;
background-color:brown;
background-size: cover;
background-position: left center;
height: 80px;
width: 100%;
-webkit-clip-path: polygon(61% 0, 100% 0, 100% 100%, 66% 100%);
clip-path: polygon(61% 0, 100% 0, 100% 100%, 66% 100%);
}
<div class="header">
<div class="logo"></div>
<div class="photo1"></div>
<div class="photo2"></div>
</div>
How about something like this?
This also keeps the lines in a 45 degrees slope, no matter how wide the window is.
.header {
display: flex;
overflow: hidden;
}
.logo {
position: relative;
flex: 0 0 24%;
max-width: 24%;
height: 80px;
}
.logo:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: -100%;
right: 0;
bottom: 0;
background-color: green;
transform: skewX(45deg);
}
.photo1 {
position: relative;
flex: 0 0 38%;
max-width: 38%;
width: 100%;
height: 80px;
}
.photo1:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: -2px;
right: -2px;
bottom: 0;
background-color: red;
transform: skewX(45deg);
}
.photo2 {
position: relative;
flex: 0 0 38%;
max-width: 38%;
height: 80px;
}
.photo2:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: -100%;
bottom: 0;
background-color: brown;
transform: skewX(45deg);
}
<div class="header">
<div class="logo"></div>
<div class="photo1"></div>
<div class="photo2"></div>
</div>
I have an image as shown below:
Here is my HTML:
<div class="diamond-border" style="left:10px;top:10px"></div>
<div class="diamond" style="left:13px;top:13px" >
<img src="http://res.cloudinary.com/demo/image/upload/sample.jpg" />
</div>
Here is my css:
.diamond
{
background-color: white;
height: 260px;
width: 260px;
position: absolute;
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
.diamond-border
{
background-color: #AAA;
height: 266px;
width: 266px;
position: absolute;
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
.diamond img
{
height: 300px;
width: 300px;
}
What I want:
I want to show the border around image as follows:
What I tried for that:
img
{
border: 5px solid red;
}
But the border is not showing. How do I show that border?
JSFiddle
https://jsfiddle.net/Vishal1419/gfok1bv8/
you can create a div with same height and width as your image to wrap that code and give it a border.
here is updated code from your fiddle
<div class="diamond-container">
<div class="diamond-border" style="left:10px;top:10px"></div>
<div class="diamond" style="left:13px;top:13px" >
<img src="https://res.cloudinary.com/demo/image/upload/sample.jpg" />
</div>
</div>
and css:
.diamond
{
background-color: white;
height: 260px;
width: 260px;
position: absolute;
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
.diamond-border
{
background-color: #AAA;
height: 266px;
width: 266px;
position: absolute;
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
.diamond img
{
height: 300px;
width: 300px;
}
.diamond-container{
border: 5px solid red;
height: 300px;
width: 300px;
}
here is an updated fiddle
https://jsfiddle.net/icernn03/gfok1bv8/3/
You can use css transform property to achieve that. check this fiddle:
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
https://jsfiddle.net/ggukk60j/
You can use a wrapper :
#wrapper {
border:5px solid red;
height: 300px;
width: 300px;
}
.diamond
{
background-color: white;
height: 260px;
width: 260px;
position: absolute;
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
.diamond-border
{
background-color: #AAA;
height: 266px;
width: 266px;
position: absolute;
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
.diamond img
{
height: 300px;
width: 300px;
}
<div id="wrapper">
<div class="diamond-border" style="left:10px;top:10px"></div>
<div class="diamond" style="left:13px;top:13px" >
<img src="http://res.cloudinary.com/demo/image/upload/sample.jpg" />
</div>
</div>
I'm trying to create a border to my clip path using pseudo-elements. I have already tried to change positioning in them and my pseudoelement still stay on top of it. How can I change this?
You can see my code in here.
#shield {
z-index: 1;
background-color: red;
box-shadow: 1px 1px 1px black;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/9/91/Bras%C3%A3o_Porto_Feliz.png");
background-size: 50%;
background-repeat: no-repeat;
background-position: center;
background-blend-mode: multiply;
display: inline-block;
height: 120px;
width: 200px;
-webkit-clip-path: polygon(100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
clip-path: polygon(100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
}
#logo {
width: 100px;
height: 100px;
}
#shield::before {
top: 0;
left: 0;
transform: scale(1.2);
content:"";
display: block;
width: 100%;
height: 100%;
background-color: black;
position: absolute;
z-index: -1;
}
<div class="navbar-brand navbar-brand-centered" id="shield">
</div>
To see what I wanted to be in top of things, just delete the ::before element
Full example is in here
Thanks in advance :)
Just flip it around. Use your background image in your ::after and your black color for the actual div.
#shield {
z-index: 1;
background-color: black;
box-shadow: 1px 1px 1px black;
position: relative;
display: inline-block;
height: 120px;
width: 200px;
-webkit-clip-path: polygon(100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
clip-path: polygon(100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
}
#logo {
width: 100px;
height: 100px;
}
#shield::before {
top: 0;
left: 0;
transform: scale(1.2);
content:"";
display: block;
width: 100%;
height: 100%;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/9/91/Bras%C3%A3o_Porto_Feliz.png");
background-repeat: no-repeat;
background-position: center;
background-blend-mode: multiply;
position: absolute;
z-index: 1;
background-size: 50%;
}
<div id="shield"></div>
i want create Transversely div using css.
i want create look like show in following image.
following image
You can use:
transform: skew();
in your CSS.
Working Example:
body {
margin: 0;
}
.intro {
position: relative;
width: 65vw;
height: 100vh;
left: -15vw;
background-color: rgb(47, 47, 47);
transform: skew(-10deg);
}
<div class="intro">
</div>
something like this?
this is a quick copy/paste that i found on a site i made..
https://codepen.io/biroplane/pen/NpLrvE
#sx {
-webkit-clip-path: polygon(0 0, 95% 0, 74% 100%, 0% 100%);
clip-path: polygon(0 0, 100% 0, 84% 100%, 0% 100%);
background-image: url('https://unsplash.it/1920/1080/?random');
//background-image: url('http://loremflickr.com/1920/1080/dog,cat');
background-position: center center;
background-clip: border-box;
background-repeat: no-repeat;
background-size: cover !important;
background-attachment: scroll;
overflow: scroll;
width: 50vw !important;
height: 100vh;
display: flex;
align-items: center;
align-content: center;
flex-direction: column;
transition: all 0.5s cubic-bezier(.34, -0.32, .42, 1.34);
&:hover {
border: 10px solid white;
width: 100vw !important;
-webkit-clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%);
clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%);
~ #dx {
//width:100vw !important;
}
h1 {
//margin-left: 25vw;
color: white;
#include textlongshadow(#222);
}
img {
//margin-left: 25vw;
#include longshadow();
//-webkit-filter:drop-shadow(10px 10px 10px white) drop-shadow(20px 20px 10px red);
//longdrop(20,#222);
}
}