full width diagonal div - html

I am currently building a site and the photoshop image shows that sections must be created diagonally, alternating colors as shown in the picture below.
I am wondering if somebody might help me with the CSS for such a request (just for the diagonal boxes) - I can only think of rotating or skewing, but then the div will have to start off the page in order to not leave gaps, and this obviously isn't ideal especially as the requirements are that the site is responsive.
Thanks in advance.

You can do this by creating triangle effects using the borders of the :before and :after pseudo elements.
Demo Fiddle
HTML
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
CSS
div {
height:200px;
width:200px;
}
div:nth-child(odd) {
position:relative;
background:lightgrey;
margin-top:20px;
}
div:nth-child(odd):before {
width: 0;
height: 0;
border-style: solid;
border-width: 20px 200px 0px 0;
border-color: transparent lightgrey transparent transparent;
content:'';
position:absolute;
right:0;
top:-20px;
}
div:nth-child(odd):after {
width: 0;
height: 0;
border-style: solid;
border-width: 20px 200px 0px 0;
border-color: transparent white transparent transparent;
content:'';
position:absolute;
right:0;
bottom:0px;
}

Related

How to connect a horizontal/vertical line between two divs?

I'm wondering how to connect two div elements with a line which is even distanced kind of like the one in this website:
JSFiddle link: https://jsfiddle.net/mcbvb8m2/
How would you do this for horizontal and vertical divs?
Any help would be appreciated!
Thanks.
You can create a div with a class of something like connector and style this to look like the connector with the following CSS:
.connector {
border: 6px solid #333;
border-right: 0;
border-top-left-radius: 8px;
border-bottom-left-radius: 8px;
height:50px;
width: 10px;
}
You can change the appearance of this by playing around with the border thickness, colour and border-radius. This takes care of the styling.
To position it correctly, you can use absolute or relative positioning. In this case to use absolute positioning, apply position:absoluteto the connector class. To position it use properties such as top, bottom, left and right. The absolute position will absolutely position the element relative to the entire page so I'd recommend adding position:relative to its parent container so it is positioned relative to this.
.container{
height:800px;
width:100%;
padding:50px;
background:#eeeeee;
position:relative;
}
.box-1{
height:300px;
width:300px;
background:blue;
color:#fff;
margin-bottom:30px;
}
.box-2{
height:300px;
width:300px;
background:red;
color:#fff;
}
.connector {
position:absolute;
top: 335px;
left: 35px;
border: 6px solid #333;
border-right: 0;
border-top-left-radius: 8px;
border-bottom-left-radius: 8px;
height:50px;
width: 10px;
}
<div class="container">
<div class="box-1">
Box 1
</div>
<div class="box-2">
Box 2
</div>
<div class="connector"></div>
</div>

Best way in css to cut the corners of a border out

i have a video that i have overlaid text on top of. This overlay has a border around it, but the design calls for the corners to be cut out. Here is an image of what i want to achieve:
Is there any way to achieve this white border with cut out corners using just simple css, rather than have a load of transparent html elements that are just in there to add borders to.
You could use :before and :after to draw some borders and play with the margins / width / height a bit to get it right:
div:before {
content:'';
border-top: 4px solid white;
border-bottom: 4px solid white;
width: 596px;
height: 272px;
margin: 10px 20px;
position: absolute;
}
div:after {
content:'';
border-left: 4px solid white;
border-right: 4px solid white;
width: 612px;
height: 256px;
position: absolute;
margin: 20px 10px;
}
Fiddle
jsBin demo
.video{
position:relative;
width:500px;
height:300px;
background:url(//placehold.it/500x300/f0f);
}
.overlay{
/*Uncomment Bachground to reveal the logic */
/*background:rgba(0,0,0,0.2);*/
color:#fff;
position:absolute;
width:400px;
margin:50px;
height:164px;
padding:15px 0; /* remember 15 ...*/
border-top:3px solid #fff;
border-bottom:3px solid #fff;
}
.overlay:before,
.overlay:after{
content: " ";
position:absolute;
background:#fff;
width: 3px; /* same as .overlay border width */
top:5%; /* This is also interesting */
height:90%; /* Do the math */
}
.overlay:before{left: -15px;} /* :) */
.overlay:after{right: -15px;}
From my comment: multiple background and gradient (it could be 1pixel image ) DEMO
<div class="cornersOff"><img src="http://lorempixel.com/640/480/cats/1"/></div>
and CSS
.cornersOff {
position:relative;
display:inline-block; /* or table or float or width or whatever*/
}
.cornersOff img,
/* not an image ? */ .cornersOff > * {
display:block;/* or vertical-align:top for inline-block element*/
}
.cornersOff:before {
content:'';
height:100%;
width:100%;
position:absolute;
border:solid 10px transparent;/* size here tells how far from borders you want to see these new borders drawn */
box-sizing:border-box;/* include that border width */
background:
linear-gradient(to top, rgba(255,255,255,0.8), rgba(255,255,255,0.8)) top center no-repeat ,
linear-gradient(to top, rgba(255,255,255,0.8), rgba(255,255,255,0.8)) bottom no-repeat,
linear-gradient(to top, rgba(255,255,255,0.8), rgba(255,255,255,0.8)) left no-repeat,
linear-gradient(to top, rgba(255,255,255,0.8), rgba(255,255,255,0.8)) right no-repeat;
background-size: 580px 3px,580px 3px , 3px 420px, 3px 420px;
/* it cactches the click event ? : uncomment this : *//* pointer-events:none*/
}
img tag inside can be an iframe, a video tag or just content.
If you experiment troubles with clicking, you can add to .cornersOff:before the rule : pointer-events:none; so it ill never catch the click event .... if that's an issue when you would set some opacity background-color.

Make a circular border around text

Right now I would like to have a plus sign with a circle around it.
http://jsfiddle.net/dtracers/cvtztcy1/1/
<h1>TEXY TXT <span>+</span></h1>
<style>
span {
border-radius: 50%;
border-style:solid;
border-width: 1px 3px 1px 1px;
padding:0px;
padding-bottom:0.125em;
cursor:pointer;
margin:0px;
}
/* Just to see if that would modify anything */
h1 {
padding:0px;
margin:0px;
}
</style>
After looking at it you can tell that this is not a circle but instead an elipse.
I have realize that it is the text height that is causing this issue but is there a way to make it appear closer.
The background is dynamic so I can not use an image.
And I would rather not have a floating element that depended on absolute positioning.
I would also like the circle in height to be equal to its current width.
I know I can just make it wider but I don't want a giant circle I want a tight small circle
EDIT
For those that are saying this is the same question it is kinda.
The difference between what I am asking and what that person is asking is that in their case the circle is larger than the bounds of the text.
What I am asking is for a circle that is smaller than the bounds of the text.
As such none of the solutions given there will apply to my question.
You can achieve this using :after pseudo element. check the DEMO.
span {
position:relative;
padding:0; margin:0;
cursor: pointer;
}
span:after
{
content:"";
position:absolute;
display:inline-block;
left:-1px;
top:7px;
background:gold;
border-radius: 50%;
width:0.5em;
height:0.5em;
font-size:1.3em;
z-index:-1;
}
Adjust your padding value in css and all is good :
demo
span {
border-radius: 50%;
border-style:solid;
border-width: 1px 3px 1px 1px;
padding:0 2%; /* updated */
/* padding-bottom:0.125em; removed */
cursor:pointer;
margin:0px;
}
This will lead to a perfect circle:
span {
border-radius: 150px;
border-style:solid;
border-width: 1px;
padding:1% 2%;
cursor:pointer;
margin:0px;
width:200px;
line-height:300px;
}
One solution is to make the span have equal width and height using em so it naturally adjusts to the font size.
h1 span {
display: inline-block;
width: 0.9em;
height: 0.9em;
line-height: 0.8em;
text-align: center;
color: teal;
background-color: palegoldenrod;
border: 0.18em solid;
border-radius: 1000px;
padding-left: 1px;
cursor: pointer;
}
Then center the plus sign with line-height and text-align.
Fiddle with the CSS:
http://jsfiddle.net/zx2c4drL

Boxes with angled bottom and top

I would like to know how can I make in CSS3 angled boxes. Like this site:
http://themeluxe.com/themes/glissando/ (the whites ones)
And how can I make the borders look better, smooth.
Looking on their code, I found this css:
.container:before, .container:after {
border-bottom: 80px solid transparent;
border-left: 110vw solid transparent;
content: "";
display: none;
height: 0;
margin-top: -80px;
position: relative;
width: 0;
}
But is not working for me.
In the website you link to they use the "border technique" to create the oblique boxes on pseudo elements you may understand this technique in this SO question.
Here is a simple fiddle using this technique to create the oblique bottom and top. It should help you understand how it works :
DEMO
HTML :
<div></div>
<div class="second"></div>
CSS :
body{
margin:0;
padding:0;
}
div{
height:200px;
background:teal;
position:relative;
}
.second{
background:gold;
}
.second:before{
content:'';
position:absolute;
bottom:100%;
border-left:100vw solid transparent;
border-bottom: 80px solid gold;
}
You should also be aware that in the website you link to, they are using vw units. They are not supported by IE8-

Full width header with different extremities

Hi all,
I've been trying to make a header for a website I'm working on like the image above, the issue is I would like that the header fill 100% of the page width.
Is it possible to show me a way to do this in HTML5/CSS3 without using this image as a background img.
You need to create everything on 100%, fully flexible. Try the code given below DEMO
This is just to make you understand how you can do this.
CSS
body { background: #ccc; margin:0; padding: 0;}
header {background: #fff; width:100%; float:left; height:60px; position:relative;}
nav {background: red; height:30px; width:100%; float:left; margin-top: 30px;}
.logo {
position:absolute;
width:150px; height:80px; background: #fff;
border-radius: 0 0 3px 0; left:0; top:0;
}
.triangleDown { width: 0; height: 0; border-left: 50px solid transparent; border-right: 35px solid transparent; border-top: 81px solid #fff; left: 98px; position: absolute;}
HTML
<header>
<div class="logo"></div>
<div class="triangleDown"></div>
<nav></nav>
</header>
Salam my friend, the best idea is to use Css3 proprieties i mean the gradient role, i made a demo for you, you can costumize it as u need.
http://codepen.io/anon/pen/FBpEv
set the containing div to 100% and have a bg image of 1px wide and repeat the image. above this will sit the original main image with margin: 0 auto;
This will give you the desired result as above.
Try this, it has examples of what you want:
http://css-tricks.com/full-browser-width-bars/
You can use below code:
*{margin:0; padding:0;}
html, body{height:100%; width:100%;}
header{width:100%; background:#ccc;}