I am currently trying to make a basic Food pyramid with six levels, The bottom 5 layers/levels will use trapezoids and the top level will be a triangle to make up a pyramid shape.
I currently can display 2 trapezoids and one triangle but after that any sizing that I use looks extremely strange and skewed, Please see the image below for what I am trying to achieve:
Css Food pyramid
Here is my current CSS code
body {
background-color: #EFEFEF;
}
.shape {
margin: auto;
}
.one {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 60px solid #EA1B07;
}
.one:hover {
border-bottom: 60px solid #EA1B07;
}
.two {
border-bottom: 75px solid #F4B600;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 100px;
}
.two:hover {
border-bottom: 75px solid #F4B600;
}
.three {
border-bottom: 100px solid #F9E029;
border-left: 80px solid transparent;
border-right: 80px solid transparent;
height: 0;
width: 1px;
}
.three:hover {
border-bottom: 100px solid #F9E029;
}
.four {
border-bottom: 100px solid #049DFC;
border-left: 80px solid transparent;
border-right: 80px solid transparent;
height: 0;
width: 60px;
margin: auto;
}
.four:hover {
border-bottom: 100px solid #049DFC;
}
.five {
border-bottom: 100px solid #A77643;
border-left: 80px solid transparent;
border-right: 80px solid transparent;
height: 0;
width: 220px;
margin: auto;
}
.five:hover {
border-bottom: 100px solid #A77643;
}
.six {
border-bottom: 100px solid #5CD533;
border-left: 80px solid transparent;
border-right: 80px solid transparent;
height: 0;
width: 380px;
margin: auto;
}
.six:hover {
border-bottom: 100px solid #5CD533;
}
As you can see the top three layers aren't connected properly.
Also, the fifth orange/gold (#F4B600) layer need to have some padding above and below it like the above image.
Any help with this would be appreciated.
Instead of trying to style each shape individually you could put all 6 elements in a container which is then shaped using CSS clip-path as that shape is simply a triangle.
Here's a basic snippet which results in:
.pyramid {
clip-path: polygon(50% 0, 100% 100%, 0 100%);
width: 100vmin;
aspect-ratio: 2 / 1;
background-color: gray;
display: grid;
grid-template-columns: 1fr;
gap: 1vmin;
}
.pyramid > * {
background: pink;
}
.one {
background-color: #EA1B07;
}
.two {
background-color: #F4B600;
}
.three {
background-color: #F9E029
}
.four {
background-color: #049DFC
}
.five {
background-color: #A77643;
}
.six {
background-color: #5CD533;
}
<div class="pyramid">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div class="four"></div>
<div class="five"></div>
<div class="six"></div>
</div>
Obviously you'll want to decide on exactly the aspect ratios and gaps to suit your needs.
Related
I'm looking for a way to draw a special shape like in the picture using Css3. Any idea or drawing way to draw that shape using Css3?
I have referenced several ways but it just draws into a normal triangle.
#shape {
width: 0;
height: 0;
border-left: 72px solid transparent;
border-right: 0px solid transparent;
border-bottom: 72px solid red;
}
<div id="shape"></div>
you can add border-bottom-right-radius in your #shape css. you just need to set the border-left to white or depending on your background color of your div to match the color
#shape {
width: 0;
border-left: 72px solid white;
border-right: 0px solid transparent;
border-bottom: 72px solid red;
border-bottom-right-radius: 20px;
}
<div id="shape"></div>
it can be done using an after element on shape
#shape{
width: 100px;
height: 100px;
border-left: 0px solid transparent;
border-top: 0px solid transparent;
border-right: 1px solid blue;
border-bottom:1px solid blue;
border-bottom-right-radius: 25px;
position: relative;
overflow: hidden;
}
#shape::after{
content:"";
position: absolute;
background-color: blue;
width: 1px;
height: 150%;
bottom: 0;
transform-origin: bottom;
transform: rotateZ(45deg);
}
<div id="shape"></div>
I have been trying to create an image like this using css.
which I partly achieved like this
<div class="nav-tab">
<div class="arrow-left"></div>
<div class="arrow"></div>
<div class="arrow-right"></div>
</div>
CSS
div {
float: left;
margin: 0;
padding: 0;
}
.arrow {
background-color: green;
height: 60px;
width: 240px;
}
.arrow-right {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid green;
}
.arrow-left {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid white;
position: relative;
left: 30px;
}
Fiddle: https://jsfiddle.net/codeandcloud/g3cmgw8y/6/
But the design has these problems
1) The arrow-left not having background-color transparent. ( Is it possible as per this design? )
2) What I want is to use it as the image below. When I put each .nav-tab in a ul > li with float:left the output is garbled.
Fiddle: https://jsfiddle.net/g3cmgw8y/7/
What am I doing wrong and how should I fix this.
How about using skew instead?
https://jsfiddle.net/foreyez/1gf3zam3/
<div class='arrow'>
<div class='arrowtop'>
</div>
<div class='arrowbottom'>
</div>
</div>
.arrowtop {
transform: translateX(50px) skewX(45deg);
width:400px;
height:50px;
background:red;
}
.arrowbottom {
transform: translateX(50px) skewX(-45deg);
width:400px;
height:50px;
background:red;
}
Hmm ... maybe this's an answer ?
.arrow-left {
border-top: 30px solid green;
border-bottom: 30px solid green;
border-left: 30px solid transparent;
position:relative;
left: 0px;
}
This question already has answers here:
html/css hexagon with image inside
(7 answers)
Closed 8 years ago.
http://codepen.io/anon/pen/dqEbA
I'd like to be able to replace some of the green backgrounds with image backgrounds... is this possible with the CSS I'm using now, or do I have to an alternative CSS layout to make it possible?
Here's the CSS for reference:
.hex {
float: left;
margin-left: 3px;
margin-bottom: -26px;
}
.hex .top {
width: 0;
border-bottom: 30px solid #6C6;
border-left: 52px solid transparent;
border-right: 52px solid transparent;
}
.hex .middle {
width: 104px;
height: 60px;
background: #6C6;
}
.hex .bottom {
width: 0;
border-top: 30px solid #6C6;
border-left: 52px solid transparent;
border-right: 52px solid transparent;
}
.hex-row {
clear: left;
}
.hex-row.even {
margin-left: 53px;
}
And a snippet of the HTML:
<div class="hex"><div class="top"></div><div class="middle"></div><div class="bottom"</div></div>
<div class="hex"><div class="top"></div><div class="middle"></div><div class="bottom"></div></div>
I guess it is, I would use :nth-child(). If, for instance, every third hexagon needs a background image, but they need the same picture:
.hex:nth-child(3n) {background-image: url('third.png');}
Although you can select manually the ones you need to change the background of:
.hex:nth-child(19) {background-image: url('bg19.png');}
.hex:nth-child(26) {background-image: url('bg26.png');}
And so on.
HTML
<div class="hex "><div class="bbc "></div><div class="middle abc"></div><div class="bbb "></div></div>
CSS
.hex .abc
{
background:red;
}
.bbc
{
border-bottom: 30px solid red;
width: 0;
border-left: 52px solid transparent;
border-right: 52px solid transparent;
}
.bbb
{
width: 0;
border-top: 30px solid red;
border-left: 52px solid transparent;
border-right: 52px solid transparent;
}
Make these Changes and try
HTML:
<div class="arrow-right"></div>
CSS:
.arrow-right {
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid green;
}
Result:
Is there any way I can produce a 1 pixel border on the two sides of the result? (the non 180 degree ones)?
Thanks
100% pure CSS, no... but add an extra div in there and:
HTML
<div class="arrow-right">
<div></div>
</div>
CSS
.arrow-right {
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid black;
}
.arrow-right > div {
width: 0;
position: relative;
left: -60px;
top: -59px;
border-top: 59px solid transparent;
border-bottom: 59px solid transparent;
border-left: 59px solid green;
}
http://jsfiddle.net/qJJxm/
(replace every instance of 59 with a smaller number to make a wider border - all four should always be the same number)
You can add a border through before or after pseudo-elements, shifted one pixel to the left.
.arrow-right,
.arrow-right:after {
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid black;
}
.arrow-right:after {
border-left-color: green;
content: '';
display: block;
position: relative;
left: -61px;
top: -60px;
}
http://jsfiddle.net/Nh63r/
Ok so, I'm trying to replicate the effect you see here at the bottom of the page, with the back to top button: http://www.ppp-templates.de/tilability/ - After the content area for We stay connected.
basically he's using a background image for that and I'd like to replicate it with CSS and keep the same effect.
I know how to create triangles with CSS with borders, but in my case I'd like to use the transparent bg image and not a color so I can't use borders
I removed the background image and used #FFF on the whole div, so it's all white now... I created a new div in which I added the back to top button and added background: transparent to it so it's transparent, but how do I create the triangle via CSS?
Any help is greatly appreciated.
The Fiddle:
http://jsfiddle.net/JaMH9/2/
The HTML:
<div class="bar">
<span class="home">^<br>Home, sweet home!</span>
</div>
The CSS:
.bar {
position: relative;
width: 90%;
height: 30px;
margin: 0 auto;
}
.home {
position: absolute;
top: 0px;
left: 60%;
width: 20%;
text-align: center;
}
.bar:before, .bar:after {
content:'';
position: absolute;
top: 0;
height: 0;
border-top: 30px solid white;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.bar:before {
left: 0;
width: 70%;
border-right: 30px solid transparent;
}
.bar:after {
right:0;
width: 30%;
border-left: 30px solid transparent;
}
Here's one way to make a triangle with fairly minimal markup and css:
HTML:
<div class="triangle"></div>
CSS:
.triangle {
width: 0;
height: 0;
border-left: 35px solid transparent;
border-right: 35px solid transparent;
border-bottom: 35px solid gray;
}
http://jsbin.com/iribib/21
Here you go, http://jsfiddle.net/pkUx7/1/
HTML
<body>
<div id = "footer"></div>
<div id = "bottom-line-left"></div>
<div id = "triangle"></div>
<div id = "bottom-line-right"></div>
</body>
CSS
body {
background-color: purple;
}
div {
margin:0;
padding:0;
background-color: violet;
}
#footer {
height: 100px;
}
#bottom-line-left, #bottom-line-right {
display: inline-block;
height: 20px;
}
#bottom-line-left {
width: 61%;
}
#bottom-line-right {
float: right;
width: 37%;
}
#triangle {
margin-left:-6px;
margin-right: -4px;
padding:0;
display: inline-block;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 20px solid purple;
}
I just threw this together, there's probably a better way to achieve this effect.
HTML
<div class="div1">Lorem Ipsum</div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
CSS
body {
background-color: gray;
border: 20px solid gray;
}
.div1 {
background-color: white;
border: 20px solid white;
}
.div2 {
float: right;
border-top: 20px solid white;
border-right: 20px solid white;
border-left: 20px solid transparent;
}
.div3 {
float: right;
margin: 10px -20px;
border-bottom: 20px solid white;
border-right: 20px solid transparent;
border-left: 20px solid transparent;
}
.div4 {
border-top: 20px solid white;
border-right: 20px solid transparent;
margin-right: 40px;
}
See it here.
You can use vector path.
For instance, transparent triangle with green border:
<svg height="151" width="150">
<path d="m0 150 h150 l -75 -150 z" fill="transparent" stroke="green" />
</svg>
See it here.