How to make responsive lines in path shape - html

I have these path lines, the form is okey with 2k res. and full hd but on other devices (smaller, bigger) the shape will not move responsive. Is there a way to make my code responsive or is there a more efficient way to do this.
Wished shape:
.line {
display: flex;
align-items: center;
}
.line span:first-child {
white-space: nowrap;
}
.line b {
flex: 1 0 0;
height: 5px;
background: black;
margin: 0 5px;
min-width: 25px;
}
.line1 {
position: absolute;
width: 5.2%;
left: 36.2vw;
top: 31.9%;
}
.line2 {
position: absolute;
width: 15%;
left: 40vw;
top: 20%;
}
.line3 {
position: absolute;
width: 15%;
left: 40vw;
top: 45%;
}
.line4 {
position: absolute;
width: 26.1vh;
left: 33.5%;
top: 32.5%;
transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
}
<p class="line line1"><span></span><b></b>
<p class="line line2"><span></span><b></b>
<p class="line line3"><span></span><b></b>
<p class="line line4"><span></span><b></b>

The general idea is to wrap all your lines into a relative container with height and width, so your lines are positioned according to their container. If your container is, in this case, the whole page, you will experiance those issues. I have put together some quick example.
.container {
position: relative;
height: 500px;
}
.container p {
margin: 0;
}
.line {
position: absolute;
background: black;
}
.line1 {
width: 75%;
height: 5px;
bottom: 0;
right: 0;
}
.line2 {
width: 25%;
height: 5px;
top: 50%;
left: 0;
}
.line3 {
width: 75%;
height: 5px;
right: 0;
}
.line4 {
position: absolute;
height: 500px;
width: 5px;
left: 25%;
}
<div class="container">
<p class="line line1"><span></span><b></b>
<p class="line line2"><span></span><b></b>
<p class="line line3"><span></span><b></b>
<p class="line line4"><span></span><b></b>
</div>
Please note that you will need to play a bit with the values in order to achieve the exact result as you want.

Related

Horizontal and Vertical lines on top of img via CSS

I'm trying to put two lines (horizontal and vertical one) on top of an image via CSS.
here my code:
div {
width: 640px;
position: relative;
}
.verticalLine {
display: block;
position: absolute;
background-color: blue;
width: 3px;
top: 0px;
bottom: 0px;
left: 50%;
height: 480px;
}
.horizontalLine {
position: absolute;
width: 3px;
top: 0px;
bottom: 0;
left: 50%;
background-color: blue;
transform: rotate(90deg);
}
<div>
<span class="verticalLine"></span>
<span class="horizontalLine"></span>
<img src="http://placehold.it/640x480">
</div>
Unfortunately my result is:
How can I solve this?
thanks
You should add a height to the horizontal line equal to the image width, and then position it in the center with top:50% translateY(-50%).
And also you should add translateX(-50%) to both of them to make them stay in the exact center of the image.
See below
div {
width: 640px;
position: relative;
}
.verticalLine {
display: block;
position: absolute;
background-color: blue;
width: 3px;
top: 0px;
bottom: 0px;
left: 50%;
height: 480px;
transform: translateX(-50%)
}
.horizontalLine {
position: absolute;
width: 3px;
top: 50%;
bottom: 0;
left: 50%;
background-color: blue;
transform: translate(-50%, -50%) rotate(90deg);
height:640px;
}
<div>
<span class="verticalLine"></span>
<span class="horizontalLine"></span>
<img src="http://placehold.it/640x480">
</div>

How to create a square which is tilted 45 degrees and has a seperated border

How can I accomplish such a square with css? I don't know how to create such a border and how to center the text that perfectly.
I expect you to do something like this!
CSS:
.parent {
width: 150px;
height: 150px;
position: relative;
top: 40px;
left: 50px;
transform: rotate(45deg);
}
.parent:before {
content: "";
width: 106px;
height: 106px;
background: rgb(20, 20, 134);
position: absolute;
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
}
.orange {
width: 100%;
height: 20px;
background: orange;
position: absolute;
}
.orange::before,
.orange::after {
content: "";
position: absolute;
width: 20px;
height: 50px;
background: orange;
}
.orange::after {
right: 0;
height: 95px;
}
.orange:last-of-type {
bottom: 0;
transform: scale(-1);
}
.date {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
color: #FFF;
line-height: 0;
}
<div class="parent">
<div class="orange"></div>
<div class="date">
<h4>May</h4>
<p>2018</p>
</div>
<div class="orange"></div>
</div>

How can I make a responsive menu with diagonal grid in CSS?

i am creating a template for a website. there i want to create a menu like this
I found the below code as a solution
but I can't get the div to divided into 4 parts and add the text in a responsive way. Can do it using position:absolute, but the it is not responsive. How can I achieve this using css in a responsive way?
.background {
background-color: #BCBCBC;
width: 100px;
height: 50px;
padding: 0;
margin: 0
}
.line1 {
width: 112px;
height: 47px;
border-bottom: 1px solid red;
-webkit-transform: translateY(-20px) translateX(5px) rotate(27deg);
position: absolute;
/* top: -20px; */
}
.line2 {
width: 112px;
height: 47px;
border-bottom: 1px solid green;
-webkit-transform: translateY(20px) translateX(5px) rotate(-26deg);
position: absolute;
top: -33px;
left: -13px;
}
<div class="background">
<div class="line1"></div>
<div class="line2"></div>
</div>
You can use CSS Flexbox & CSS Transform properties to achieve this. Have a look at the snippet below:
body {
padding: 20px;
}
.menu-cover {
width: 360px;
height: 360px;
overflow: hidden;
background: #eee;
}
.menu {
list-style: none;
margin: -70px 0 0 -70px;
padding: 80px;
display: flex;
flex-wrap: wrap;
width: calc(600px - 100px);
height: calc(600px - 100px);
position: relative;
transform: rotate(45deg);
transform-origin: center;
}
.menu:before {
content: '';
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 1px;
height: 100%;
background-color: #aaa;
}
.menu:after {
content: '';
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
width: 100%;
height: 1px;
background-color: #aaa;
}
.item {
width: 50%;
}
.item a {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
transform: rotate(-45deg);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class="menu-cover">
<ul class="menu">
<li class="item">
Bussiness
</li>
<li class="item">
Team
</li>
<li class="item">
Talent
</li>
<li class="item">
Group
</li>
</ul>
</div>
Hope this helps!
You can use pseudo elements like before and after. Kindly review the updated answer. Hope it is helpful to you.
.background {
background-color: #BCBCBC;
width: 100px;
height: 100px;
padding: 0;
margin: 0;
position: relative;
overflow: hidden;
}
.background:before {
width: 1px;
height: 500px;
background :red;
-webkit-transform: rotate(45deg);
position: absolute;
content:'';
left: 0;
right: 0;
margin:-200px auto 0;
}
.background:after {
width: 1px;
height: 500px;
background :green;
-webkit-transform: rotate(-45deg);
position: absolute;
content:'';
left: 0;
right: 0;
margin:-200px auto 0;
}
<div class="background">
</div>
Please check the below code. You can implement your requirement in the same way. I have added <span> tags to show the text.
.background {
background-color: #BCBCBC;
width: 100px;
height: 50px;
padding: 0;
margin: 0
}
.line1 {
width: 112px;
height: 47px;
border-bottom: 1px solid red;
-webkit-transform: translateY(-20px) translateX(5px) rotate(27deg);
position: absolute;
/* top: -20px; */
}
.line2 {
width: 112px;
height: 47px;
border-bottom: 1px solid green;
-webkit-transform: translateY(20px) translateX(5px) rotate(-26deg);
position: absolute;
top: -33px;
left: -13px;
}
<div class="background">
<span style="float:left;padding-left:20%">Business
</span>
<span style="float:left;padding-left:5%">Team
</span>
<span style="float:right;padding-left:5%">Talent
</span>
<span style="float:left;padding-left:20%">Group
</span>
<div class="line1"></div>
<div class="line2"></div>
</div>
https://jsfiddle.net/t3z8q2k4/

How to place pseudo-elements behind the parent node?

http://codepen.io/pen/YZdpgb
The pseudo-element after is on front of the div .rotate.
It seems that the z-index: -1 is not working
HTML
<div class="box--container">
<div class="box--rotate">
<div class="box">
<p>my background should be the light grey :(</p>
</div>
</div>
</div>
CSS
body {
height: 80vh;
margin: 10vh 10vw;
}
.box--container {
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
text-align: center;
}
.box--rotate {
position: relative;
width: 250px;
height: 250px;
transform: rotate(45deg);
transform-origin: 100% 150%;
background: #ccc;
z-index: 1;
&::after {
position: absolute;
content: '';
width: 100%;
height: 100%;
background: #F2C398;
top: 15px;
left: 15px;
z-index: -1;
}
}
.box {
position: relative;
top: 50%;
transform: rotate(-45deg) translateY(-50%);
z-index: 10;
}
try this one it's helpful https://jsfiddle.net/x061nock/ ::after use default color

CSS Put arrows on each side of a Box(div)

Need help on how to put an arrow on each side of a box pointing outward.
I have the box and the basic CSS for an arrow I saw on another stack question.
Need help creating four arrows in that box
Im a java developer so this is not my cup of tea
Box:
#myBox {
width: 150px;
height: 150px;
background-color: grey;
border: 1px solid black;
}
/*Chevron*/
.Chevron {
position: relative;
display: block;
height: 50px;
/*height should be double border*/
}
.Chevron:before,
.Chevron:after {
position: absolute;
display: block;
content: "";
border: 25px solid transparent;
/*adjust size*/
}
/*Change four 'top' values below to rotate (top/right/bottom/left)*/
.Chevron:before {
top: 0;
border-top-color: #b00;
/*Chevron Color*/
}
.Chevron:after {
top: -50px;
/*adjust thickness*/
border-top-color: #fff;
/*Match background colour*/
}
<div id="myBox"></div>
<i class="Chevron"></i>
Since you are looking to interact with these shapes, you'd be better to go with a different approach to making your triangles, rather than a border hack.
.box {
height: 150px;
width: 150px;
background: lightgray;
position: relative;
}
.wrap {
position: absolute;
top: 0;
left: 25%;
height: 25%;
width: 50%;
overflow: hidden;
}
.touch {
position: absolute;
top: 0;
left: 50%;
height: 200%;
width: 200%;
transform: rotate(45deg);
transform-origin: top left;
background: gray;
cursor: pointer;
}
.wrap:nth-child(2) {
transform: rotate(90deg);
transform-origin: top left;
top: 25%;
left: 100%;
}
.wrap:nth-child(3) {
transform: rotate(180deg);
transform-origin: top left;
top: 100%;
left: 75%;
}
.wrap:nth-child(4) {
transform: rotate(-90deg);
transform-origin: top left;
top: 75%;
left: 0;
}
.touch:hover {
background: tomato;
}
<div class="box">
<span class="wrap"><span class="touch"></span></span>
<span class="wrap"><span class="touch"></span></span>
<span class="wrap"><span class="touch"></span></span>
<span class="wrap"><span class="touch"></span></span>
</div>
i have used the nth-child in order to position the arrows correctly. I have also needed to used a wrapper div like in this answer as the border-hack won't work on a hit-test.
Use Css triangle. Do you need something like this?
For each side, use the code below to make a triangle:
width: 0;
height: 0;
border-style: solid;
border-width: 100px 100px 100px 0;
border-color: transparent #007bff transparent transparent;
Here is a working demo.
I have managed to do this with 3 elements using CSS transforms and positioning. Is that what you were trying to achieve?
.container {
width: 100px;
height: 100px;
background: grey;
position: relative;
}
.container .triangles {
width: 70px;
height: 70px;
background: yellow;
transform: rotate(45deg);
position: absolute;
top: 15px;
left: 15px;
}
.container .triangles .box {
width: 50px;
height: 50px;
background: blue;
transform: rotate(-45deg);
position: absolute;
top: 10px;
left: 10px;
color: white;
}
<div class="container">
<div class="triangles">
<div class="box">
text
</div>
</div>
</div>