Remove space between two trapezoids - html

For some reason there's space between my trapezoids.
#trapezoid {
margin-top: 100px;
border-bottom: 100px solid red;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
height: 0;
width: 200px;
transform:rotate(90deg);
float: left;
}
#trapezoid2 {
margin-top: 100px;
border-bottom: 100px solid red;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
height: 0;
width: 200px;
transform:rotate(-90deg);
float: left;
}
<div id="trapezoid2"></div>
<div id="trapezoid"></div>
Is there a way to remove the space without using negative margin?

Instead of making the trapezoid horizontally and then rotating, just make it the way you want it.
#trapezoid {
margin-top:20px;
border-left:100px solid red;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
height: 200px;
float: left;
}
#trapezoid2 {
margin-top:20px;
border-right:100px solid red;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
height: 200px;
float: left;
}
<div id="trapezoid2"></div>
<div id="trapezoid"></div>

It's because elements still keep it's DOM flow when you do transform:rotate(-90deg);. If you remove it, you will see that two divs actually touches. You can move second element to reduce gap.
#trapezoid {
margin-top: 100px;
border-bottom: 100px solid red;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
height: 0;
width: 200px;
transform: rotate(90deg);
float: left;
/* Added code */
position: relative;
right: 140px;
}
#trapezoid2 {
margin-top: 100px;
border-bottom: 100px solid red;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
height: 0;
width: 200px;
transform: rotate(-90deg);
float: left;
}
<div id="trapezoid2"></div>
<div id="trapezoid"></div>

Do it without the rotating:
#trapezoid {
border-left: 100px solid red;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
height: 200px;
width: 0px;
float: left;
}
#trapezoid2 {
border-right: 100px solid red;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
height: 200px;
width: 0px;
float: left;
}
http://codepen.io/anon/pen/Wxzdrv

That gap is there because of width and transform: rotate, but you can use translateY to fix it.
#trapezoid {
margin-top: 100px;
border-bottom: 100px solid red;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
height: 0;
width: 200px;
transform: rotate(90deg) translateY(70px);
float: left;
}
#trapezoid2 {
margin-top: 100px;
border-bottom: 100px solid red;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
height: 0;
width: 200px;
transform: rotate(-90deg) translateY(70px);
float: left;
}
<div id="trapezoid2"></div>
<div id="trapezoid"></div>

Related

How can I create a navbar without an overlapping border?

I would like to create a navbar that looks like this: https://www.audacityteam.org/
I tried this but I think this doesn't look right. The border from the notch is on top of the left and right placeholders when it shouldn't be. Also I think I made this too complicated; can this be done with fewer div elements?
:root {
--background: black;
--accent: silver;
}
body {
margin: 0;
}
.placeholder {
float: left;
height: 20px;
width: 30%;
background: var(--background);
border-bottom: 3px solid var(--accent);
}
.right {
float: right;
}
.container {
position: absolute;
left: 25%;
border-top: 50px solid var(--background);
border-left: 50px solid transparent;
border-right: 50px solid transparent;
height: 0;
width: 40%;
}
.container-accent {
position: absolute;
left: 24.8%;
border-top: 53px solid var(--accent);
border-left: 53px solid transparent;
border-right: 53px solid transparent;
height: 0;
width: 40%;
transform: scale(1.008, 1.008);
}
<div class="placeholder"></div>
<div class="placeholder right"></div>
<div class="container-accent"></div>
<div class="container"></div>

CSS for the following image design

.step2 {
background-color: #f1f1f1;
color: #000;
margin: 0 -87px 0 33px;
padding: 30px 40px 0 40px;
height: 212px;
text-align: center;
}
.step2:before {
border-top: 40px solid transparent !important;
border-bottom: 40px solid transparent;
border-left: 40px solid #4060A5;
position: absolute;
right: -40px;
top: 0;
}
<div class="col-lg-3">
<div class="step2">
Step 1
</div>
</div>
I am developing a website but now I got stucked to achieve css for the Steps portion (Step 1, Step 2, Step 3) given in the image below :
This is the link for the image
Can anyone help me to achieve CSS ?
Play around with it and adjust the sizes and fonts according to your needs !
span{
position: absolute;
width : 100px;
margin-left: 30%;
margin-top: 40%;
}
.orange {
vertical-align: middle;
color: white;
position:relative;
background-color:#333;
height:100px !important;
width:100px !important;
z-index:3;
border-bottom-left-radius: 50%;
float: left;
margin-right:2px;
}
.orange:after {
content:'';
position: absolute;
left: 100%;
width: 0;
height: 0;
border-top: solid 50px transparent;
border-bottom: solid 50px transparent;
border-left: solid 15px #333;
}
.green {
color: white;
position:relative;
background-color: #333;
height:100px !important;
width:100px !important;
z-index:2;
margin-right:2px;
float: left;
}
.green:after {
content:'';
position: absolute;
left: 100%;
width: 0;
height: 0;
border-top: solid 50px transparent;
border-bottom: solid 50px transparent;
border-left: solid 15px #333;
}
.green:before {
content:'';
position: absolute;
width: 0;
height: 0;
border-top: solid 50px transparent;
border-bottom: solid 50px transparent;
border-left: solid 15px white;
}
.blue {
color: white;
position:relative;
background-color: #333;
height:100px !important;
width:100px !important;
border-top-right-radius: 50%;
float: left;
}
.blue:after {
content:'';
position: absolute;
top: 100%;
left: 100%;
margin-left: 250px;
width: 0;
height: 0;
}
.blue:before {
content:'';
position: absolute;
width: 0;
height: 0;
border-top: solid 50px transparent;
border-bottom: solid 50px transparent;
border-left: solid 15px white;
}
<div class="orange"><span>Step 1</span></div>
<div class="green"><span>Step 2</span></div>
<div class="blue"><span>Step 3</span></div>

Draw right arrow using CSS [duplicate]

This question already has answers here:
Border within border CSS
(3 answers)
Closed 6 years ago.
In my project i need to draw rectangle with right arrow and it should be filled with white color background with black color border. I have tried in many ways but i didn't get right arrow with white background and black color border.
I tried follwoing code:
HTML:
<html>
<head></head>
<body>
<div class="paddingstyleleft right-arrow1">
<div><span><img src="images/referral_out.png"/> Referred To<span>
<div><strong>Dr.Sarah Willam</strong><span class="bandagealign"><span class="bandage">3</span></span></div>
<div class="datestyle"><img src="images/Date.png"/> Jul 24th,2016 | <div class="datestyle1 scheduledstatus"><span class="spanwaiting">Scheduled</span></div></div></div>
</div>
</body>
</html>
CSS:
.right-arrow1 {
display: inline-block;
position: relative;
background: white;
padding: 15px;
height: 100px;
padding:25px;
border-bottom: 1px solid grey;
width: 285px;
border: 1px solid black;
}
.right-arrow1:after {
content: '';
display: block;
position: absolute;
left: 100%;
top: 50%;
margin-top: -10px;
width: 0;
height: 0;
border-top: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid black;
}
you can check this fiddle for all arrows:
https://jsfiddle.net/wLxag8pn/
.arrow-up {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid black;
}
.arrow-down {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #f00;
}
.arrow-right {
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid green;
}
.arrow-left {
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right: 10px solid blue;
}
Try this css for arrow with border fiddle link https://jsfiddle.net/m4dv4f7s/
div{
position: relative;
background-color: #008000;
padding: 0px 16px;
height: 40px;
line-height: 40px;
display: inline-block;
color: white;
border: 2px solid black;
border-right: none;
z-index:1;
}
div:before{
content: '';
position: absolute;
left: 100%;
z-index:-1;
width: 28px;
height: 28px;
background-color: #008000;
border-right: 2px solid black;
border-bottom: 2px solid black;
transform: rotate(-45deg) translate(-14px,-7px);
}

How come half the triangle is missing

I was looking at css-tricks to see how to make a triangle with css. In the comments there was a question about how to give the triangle a border.
I thought I had a solution, but the results were unexpected. How come the right half of the inner triangle is missing.
#outer {
display: block;
height: 0;
width: 0;
border-top: 50px solid red;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
}
#inner {
display: inline;
margin: 0;
position: relative;
left: -40px;
top: -6px;
height: 0;
width: 0;
border-top: 40px solid green;
border-bottom: 0 solid transparent;
border-left: 40px solid transparent;
border-right: 40px solid transparent;
}
<div id="outer">
<div id="inner"></div>
</div>
If I change the inner triangle to have display: block or display: inline-block, the right half exists, but it's gone when then inner triangle has display: inline and I don't know why.
Strange, it works on Firefox and IE.
You can make it work on Chrome with
#inner::after {
content: '\200B';
}
#outer {
display: block;
height: 0;
width: 0;
border-top: 50px solid red;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
}
#inner {
display: inline;
margin: 0;
position: relative;
left: -40px;
top: -6px;
height: 0;
width: 0;
border-top: 40px solid green;
border-bottom: 0 solid transparent;
border-left: 40px solid transparent;
border-right: 40px solid transparent;
}
#inner::after {
content: '\200B';
}
<div id="outer">
<div id="inner"> </div>
</div>

I want to target multiple divs inside a parent div

I have created a hexagon from 3 divs combined. I want to hover over the hexagon and all 3 divs to change colour.
<div class="hex" >
<div class="left" ></div>
<div class="middle" ></div>
<div class="right" ></div>
</div>
.hex {
float: left;
margin-right: -26px;
margin-bottom: -50px;
}
.hex .left {
float: left;
width: 0;
border-right: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex .left:hover {
border-right: 60px solid yellow;
}
.hex .middle {
float: left;
width: 124px;
height: 208px;
background: #6C6;
}
.hex .middle:hover {
background-color: yellow;
}
.hex .right {
float: left;
width: 0;
border-left: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex .right:hover {
border-left:60px solid yellow;
}
As you can see, at the moment I am only able to target each element of the hexagon but not the hexagon as a whole.
CSS can not associate and combine the :hover state of separated individual elements.
In this case, you can associate a :hover state to the whole .hex element in each selector. After a :hover, you can add more subselectors:
.hex:hover .left
(instead of .hex .left:hover)
The full code:
.hex {
float: left;
margin-right: -26px;
margin-bottom: -50px;
}
.hex .left {
float: left;
width: 0;
border-right: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex:hover .left {
border-right: 60px solid yellow; /* or simply: border-right-color: yellow; */
}
.hex .middle {
float: left;
width: 124px;
height: 208px;
background: #6C6;
}
.hex:hover .middle {
background-color: yellow;
}
.hex .right {
float: left;
width: 0;
border-left: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex:hover .right {
border-left: 60px solid yellow; /* or simply: border-left-color: yellow; */
}
<div class="hex">
<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>
</div>
.hex:hover div { } maybe? I don't think that will work in some older version of IE though.
How about this:
.hex{transition:875ms ease all;}
.hex:hover div{
background:red;
}
You can use currentcolor
.hex {
float: left;
margin-right: -26px;
margin-bottom: -50px;
color:#6C6;
}
.hex .left {
float: left;
width: 0;
border-right: 60px solid currentcolor;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex .middle {
float: left;
width: 124px;
height: 208px;
background: currentcolor;
}
.hex .right {
float: left;
width: 0;
border-left: 60px solid currentcolor;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex:hover .right{
border-left-color:yellow;
}
.hex:hover .left{
border-right-color:yellow;
}
.hex:hover .middle{
color:yellow;
}
<div class="hex" >
<div class="left" ></div>
<div class="middle" ></div>
<div class="right" ></div>
</div>
or use pseudo elements
.hex {
width:125px;
height:208px;
position:relative;
background-color:#6C6;
margin:20px auto
}
.hex:before,.hex:after{
content:'';
position:absolute;
width: 0;
height:0
}
.hex:before {
left:-60px;
border-right: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex:after {
right:-60px;
border-left: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex:hover{
background-color:yellow;
}
.hex:hover:before{
color:yellow;
border-right-color:yellow;
}
.hex:hover:after{
border-left-color:yellow;
}
<div class="hex" ></div>