Parallel diagonal lines on background - html

I want to draw 2 parallel diagonal lines on the background of my div.
Please see my table here:
body {
background-image: url("http://i.imgur.com/TnPgXl4.jpg");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
padding: 40px;
}
#table {
width: 800px;
height: 300px;
background-color: transparent;
border: solid 1px white;
}
<div id="table"></div>
I want to achieve something like this:

You can achieve the 2 diagonal lines with a rotated pseudo element. The 2 lines are the top and bottom borders of the absolutely positioned pseudo element:
body {
background-image: url("http://i.imgur.com/TnPgXl4.jpg");
background-size: cover;
background-repeat: no-repeat;
padding: 40px;
}
#table {
position: relative;
width: 800px; height: 300px;
background-color: transparent;
border: solid 1px white;
overflow: hidden;
}
#table:before {
content: '';
position: absolute;
right: 30%; bottom: 100%;
height: 20px; width: 100%;
border-top: 1px solid #fff;
border-bottom: 1px solid #fff;
transform-origin: 100% 100%;
transform: rotate(-70deg);
}
<div id="table"></div>
This is how this works :
the width between the 2 lines is controled by the height of the pseudo element
the thickness of the lines is controled by the border-width
the slant of the lines is controled by the rotation angle
the overflowing parts of the lines are hidden with the overflow:hidden; property on the div
Note that you need to add vendor prefixes to the transform and transform origin properties for browser support and you probably don't need the vendor prefixes on the background-size property:
canIuse for background-size
canIuse for 2D transforms

You can do this with :after and :before pseudo elemnts and trasform: rotate()
body {
background-image: url("http://www.planwallpaper.com/static/images/cool-background.jpg");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
padding:40px;
}
#table {
width: 70%;
height: 300px;
background-color: transparent;
border: solid 1px white;
margin: 0 auto;
position: relative;
box-sizing: border-box;
}
#table:before, #table:after {
content: "";
position: absolute;
left: 60%;
height: 102%;
border-left: 1px solid white;
transform: rotate(10deg);
transform-origin: top;
}
#table:after {
left: 65%;
}
<div id="table"></div>

An alternative to wek-tiki and Nenad Vracar's answers would be to use the skewX() CSS transform.
This solution won't require you to hide anything that overflows the edge and therefore adds a little more flexibility.
body {
background-image: url("http://i.imgur.com/TnPgXl4.jpg");
background-size: cover;
background-repeat: no-repeat;
padding: 40px;
}
#table {
position: relative;
width: 800px;
height: 300px;
background-color: transparent;
border: solid 1px white;
}
#table:before {
content: '';
position: absolute;
left: 50%;
top: 0;
height: 100%;
width: 20px;
border-right: 1px solid #fff;
border-left: 1px solid #fff;
transform-origin: 100% 100%;
transform: skewX(-20deg);
}
<div id="table"></div>

Svg
You could use an svg element and span the svg to your div.
body {
background-color: #222;
margin: 20px;
}
.container {
width: 100%;
height: 150px;
border: 2px solid white;
}
.container svg {
width: 100%;
height: 100%;
}
<div class="container">
<svg viewBox="0 0 100 100">
<line stroke="white" x1="47" x2="57" y1="100" y2="0" />
<line stroke="white" x1="57" x2="67" y1="100" y2="0" />
</svg>
</div>

Related

How do I make my background-image take full height of div?

I have a div with a background image that I am trying to give a transparent type border to.
Currently, this works for the side borders but the top and bottom borders do not fill with the image. How would I achieve this?
.picture-div {
background: url(https://www.princeton.edu/sites/default/files/styles/half_2x/public/images/2022/02/KOA_Nassau_2697x1517.jpg);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
border: 25px solid rgba(100, 100, 100, .50);
width: 200px;
height: 200px;
border-radius: 60px;
}
<div class="picture-div" />
Add background-origin to border-box, so the image will fill the border.
You can read the detail in : https://www.w3schools.com/cssref/css3_pr_background-origin.asp
.picture-div {
background: url(https://www.princeton.edu/sites/default/files/styles/half_2x/public/images/2022/02/KOA_Nassau_2697x1517.jpg);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-origin: border-box;
border: 25px solid rgba(100, 100, 100, .50);
width: 200px;
height: 200px;
border-radius: 60px;
}
<div class="picture-div" />
You can use border on the pseudo :before of the picture-div class as follows:
.picture-div {
background: url(https://www.princeton.edu/sites/default/files/styles/half_2x/public/images/2022/02/KOA_Nassau_2697x1517.jpg);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
position: relative;
width: 200px;
height: 200px;
border-radius: 60px;
}
.picture-div:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border: 25px solid rgba(100, 100, 100, .50);
border-radius: 60px;
}
<div class="picture-div" />

Expanding absolute div from center to reveal child

I want to have a(n absolutely-positioned) rectangular mask that expands on hover to reveal its (variable height) children. Right now the way that I'm achieving this is with an absolutely positioned div that changes its left, width and max-height values. However, I'd like to make it look like it's expanding from the middle instead of revealing from the top left--and all at the same time.
<div id="container">
<div id="mask">
<div id="background"></div>
</div>
</div>
#container {
width: 300px;
height: 300px;
background-color: black;
}
#mask {
width: 50px;
max-height: 50px;
position: absolute;
top: 125px;
left: 125px;
overflow: hidden;
transition: width 1s, max-height 1s, left 1s, top 1s;
}
#background {
background-image: url(https://www.pngfind.com/pngs/m/299-2991041_memes-para-stickers-png-png-download-surprised-pikachu.png);
background-size: contain;
width: 150px;
height: 125px;
}
#mask:hover {
width: 150px;
max-height: 1000px;
left: 75px;
top: 75px;
}
Here's a codepen: https://codepen.io/jraynolds/pen/OJJxpOm
#1 – Using clip-path
Compatibility: All modern browsers apart from Edge. IE10/11 and Edge provide limited support using url() only.
Example with clip-path
To crop the image, use clip-path: inset(). In this example, we have a 120 pixel box that is reduced to 0 on hover.
.reveal {
background: url(https://i.stack.imgur.com/3v1Kz.jpg) no-repeat;
background-size: 150px;
background-position: center;
height: 300px;
width: 300px;
clip-path: inset(120px 120px 120px 120px);
transition: clip-path 0.5s;
}
.reveal:hover {
clip-path: inset(0 0 0 0);
}
/*for example*/
body {
background: linear-gradient(to bottom right, black 0%, white 100%);
height: 100vh;
}
<div class="reveal"></div>
Example with url() (not working in Edge or IE)
There was an attempt!
Create an SVG like so:
<svg>
<clipPath id="square">
<rect />
</clipPath>
</svg>
and place that in the container. The div is given clip-path: url(#square) and the width, height, x and y coordinates are provided in the CSS and changed on hover.
.reveal-url {
background: url(https://www.pngfind.com/pngs/m/299-2991041_memes-para-stickers-png-png-download-surprised-pikachu.png)
no-repeat;
background-size: 150px;
background-position: center;
height: 300px;
width: 300px;
clip-path: url(#square);
position: relative;
}
svg {
width: 100%;
height: 100%;
}
.reveal-url rect {
transition: all 0.5s;
x: 120px;
y: 120px;
width: 60px;
height: 60px;
}
.reveal-url:hover rect {
width: 100%;
height: 100%;
x: 0;
y: 0;
}
/*for example*/
body {
background: linear-gradient(to bottom right, black 0%, white 100%);
height: 100vh;
}
h1 {
font-size: 30px;
color: white;
}
<h1>This only works in Chrome and Firefox.</h1>
<div class="reveal-url">
<svg>
<clipPath id="square">
<rect />
</clipPath>
</svg>
</div>
#2 – Using Box-shadow
If you are working with solid background colours, a simple method is to use inset box-shadow to mask the contents of the container and then reduce the box shadow on hover.
.reveal {
background: #000 url(https://www.pngfind.com/pngs/m/299-2991041_memes-para-stickers-png-png-download-surprised-pikachu.png) no-repeat;
background-size: 150px;
background-position: center;
height: 300px;
width: 300px;
box-shadow: inset 0 0 0 120px #000;
transition: box-shadow 1s;
}
.reveal:hover {
box-shadow: inset 0 0 0 70px #000;
}
/*for example*/
body {
background: #000;
}
<div class="reveal"></div>
This solution works, however, it uses the mask element as a child of the background element, not the other way round.
<div id="container">
<div id="background">
<div id="mask"></div>
</div>
</div>
You simply give the mask 100% border and zero dimensions and transition to zero border and 100% dimension (transparent). Mask must have elevated z-indez. Like so:
#container
{
width: 300px;
height: 300px;
background-color: black;
position: relative;
}
#mask
{
position: absolute;
left: 0;
top: 0;
z-indez: 10;
height: 0;
width: 0;
transition: 0.4s ease;
border: 150px solid black;
}
#background
{
background-image: url(https://www.pngfind.com/pngs/m/299-2991041_memes-para-stickers-png-png-download-surprised-pikachu.png);
background-size: contain;
width: 300px;
height: 300px;
display: block;
margin: 1rem auto;
}
#background:hover #mask
{
border: 0 solid black;
width: 100%;
height: 100%;
}
Here's a pen:
https://codepen.io/jaycodist/full/MWWEpMx

parallax scrolling pages arranged oddly

I want the about div to show up BELOW the
full screen home card
I'm having troubles getting it to show like it should.
my html code has both divs in the "right" order and when i look it up online, i couldn't find any solutions.
<body>
<div class="homeCard">
<div class="homeCardTitle">
<h1>Robin Riezebos</h1>
</div>
</div>
<div class="aboutCard">
<div class="aboutCardText">
<h2>About</h2>
</div>
</div>
</body>
my css is either missing something or I did something completely wrong but I can't seem to find out what it is so please help...
index.css
.homeCard {
background-image: url("images/helicopter-in-sky-2.jpg");
height: 100%;
width: 100%;
position: fixed;
float: left;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 0;
}
.homeCardTitle {
position: fixed;
width: 100%;
height: 320px;
top: 50%;
margin-top: -160px;
color: white;
text-shadow: 0 0 10px black;
}
.aboutCard {
background-color: #1F1F1F;
color: white;
height: 500px;
}
Please change your css like below, i think the problem was with position fixed, if you want to get your background image rendered fully please respective pixels of height.
.homeCard {
background-image: url("images/helicopter-in-sky-2.jpg");
width: 100%;
position: relative;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 0;
}
.homeCardTitle {
color: white;
text-shadow: 0 0 10px black;
}
.aboutCard {
background-color: #1F1F1F;
color: white;
height: 500px;
}
I have found a solution by bugging around in my css.
Turns out in stead of position: fixed; I should have used background-attachment: fixed; and remove position all-together.
this is my own fixed code:
.homeCard {
background-image: url("images/helicopter-in-sky-2.jpg");
height: 100%;
width: 100%;
background-attachment: fixed;
float: left;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 0;
}
.homeCardTitle {
position: relative;
width: 100%;
height: 0px;
top: 50%;
margin-top: -90px;
color: white;
text-shadow: 0 0 10px black;
}
.aboutCard {
width: 100%;
background-color: #1F1F1F;
color: white;
height: 320px;
float: left;
text-align: center;
}

Complementing image to the right

I want to create a background image that has two images, but I can’t complement the second image to the right.
I can’t manage to make it look like one whole picture, but in one place.
* {
margin: 0;
padding: 0;
overflow: hidden;
}
.home-wrapper {
height: 100%;
width: 100%;
overflow: hidden;
}
.left-content {
background: url(../img/leftwing.png);
background-repeat: no-repeat;
background-size: cover;
height: 100%;
width: 100%;
float: left;
position: absolute;
border-right: 1px solid black;
left: 0;
}
.right-content {
background: url(../img/rightwing.png);
background-repeat: no-repeat;
background-size: cover;
height: 100%;
width: 50%;
float: right;
position: absolute;
border-right: 1px solid black;
right: 0;
}
<div class="home-wrapper">
<div class="left-content">
a
</div>
<div class="right-content">
a
</div>
</div>
The reason I didn’t make it a whole background is these two have a different function when you hover over them.
This is what I want it to look like:
This is what I have instead:
You can achieve the desired result by adding background position in your css. Try this code.
.left-content{
background: url(../img/leftwing.png);
background-position: left center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
width: 50%;
float: left;
position: absolute;
border-right: 1px solid black;
left: 0;
}
.right-content{
background: url(../img/rightwing.png);
background-position: right center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
width: 50%;
float: right;
position: absolute;
border-right: 1px solid black;
right: 0;
}
Add background-position to both .right-content and .left-content
.right-content {
background-position: left center;
width: 50%; /* << this was 100%, typo? */
}
.left-content {
background-position: right center;
}

Make a curve in a div with background image

I'm stuck with one task and I can't find any solution over the internet.
I have this situation:
Images 1 and 2 has background images.
I need one 1st or 2nd image have that bump.
If it would be 1st image, that bump should extend div bottom and overlay the 2nd background.
If it would be 2nd div then I need like a crater/hole at the top and be under 1st div.
I can't cut my images to .png/.gif and cut with that bump in photoshop. These images are changed by client, so he can't prepare exact images all the time, so I need to extend them by code.
I tried to radial-gradient() background and cut with svg, but those aren't supported by Firefox.
Is it possible to make this with code who adapts to all background images?
Here is a solution that uses background-size: cover, so it is easier to adapt. (It would be easier with known dimension images).
The drawback is a little complex markup, 3 auxiliar divs are needed.
The curves are standard border-radius, so that can be adjusted as needed
.container {
width: 600px;
height: 400px;
border: solid 1px blue;
position: relative;
}
.up {
width: 100%;
height: 50%;
position: relative;
border-bottom: 40px solid transparent;
background-image: url(http://lorempixel.com/600/400);
background-size: cover;
background-position: center bottom;
background-origin: border-box;
background-clip: padding-box;
margin-bottom: -40px;
}
.addon {
width: 25%;
height: calc(100% + 40px);
position: absolute;
left: 37.5%;
border-radius: 0px 0px 50px 50px;
overflow: hidden;
background-image: inherit;
z-index: 2;
}
.addon:before {
content: "";
position: absolute;
width: 400%;
height: 100%;
left: -150%;
background-image: inherit;
background-size: cover;
background-position: center bottom;
background-origin: padding-box;
background-clip: padding-box;
}
.down {
width: 100%;
height: 50%;
position: relative;
bottom: 40px;
border-top: 40px solid transparent;
background-image: url(http://lorempixel.com/400/200);
background-size: cover;
background-position: center top;
background-origin: border-box;
background-clip: padding-box;
margin-top: -40px;
}
.addleft {
width: 37.5%;
height: calc(100% + 40px);
position: absolute;
left: 0px;
bottom: 0px;
border-radius: 0px 50px 0px 0px;
overflow: hidden;
background-color: tomato;
background-image: inherit;
background-size: 0px 0px;
}
.addleft:before {
content: "";
position: absolute;
width: 266.667%;
height: 100%;
left: 0px;
background-image: inherit;
background-size: cover;
background-position: center top;
background-origin: padding-box;
background-clip: padding-box;
}
.addright {
width: 37.5%;
height: calc(100% + 40px);
position: absolute;
right: 0px;
bottom: 0px;
border-radius: 50px 0px 0px 0px;
overflow: hidden;
background-image: inherit;
background-size: 0px 0px;
}
.addright:before {
content: "";
position: absolute;
width: 266.667%;
height: 100%;
right: 0px;
background-image: inherit;
background-size: cover;
background-position: center top;
background-origin: padding-box;
background-clip: padding-box;
}
<div class="container">
<div class="up">
<div class="addon"></div>
</div>
<div class="down">
<div class="addleft"></div>
<div class="addright"></div>
</div>
</div>
You need to use border-color
border-color: transparent transparent #555 transparent;
Basically you need to mark some percentage of left and right of the image border-color as transparent.
And then set border-radius to give the curve
Thanks.