Diagonal background in CSS (Responsive) - html

Here's an image of what I'm trying to achieve first: https://i.imgur.com/bTsL2wS.png
Note that this is only supposed to be one section of the full page. The background should not span the entire website. However each section has full-screen dimensions.
I had two ideas regarding doing this:
Have a container object with viewport dimensions and add an relative-positioned image with z-index: -1 and inside of that an absolute-positioned img with right: 0 and ~60% width, then rotate it.
Same as above but put the img inside of a 60% width right-aligned sub-container and skew the container.
Both approaches work on a desktop-screen but this happens when scaling the window down too much.
Basically I need it to work until the viewport reaches tablet/mobile size.

Wrap the part you want to have with that background in a div, then add the background-image property to the div.

*{ box-sizing: border-box}
#blue{ background: #269;}
#red{ background: #a22;}
#green{ background: #6a6; }
section{ display: block; height: 100vh; margin: 2% auto; color: #fff; font: normal 16px verdana, sans-serif; text-align: center; }
div{ height: 100%; width: 70%; overflow: hidden; float: right;}
img{ transform: rotate(70deg); height: 920px; margin: -120px 0 auto; }
h1, p{ margin: 5% auto 0 0; width: 40%;}
#media only screen and (min-height: 500px){ h1, p{ margin: 30% auto 0 0 }}
span{ position: absolute; left: 2%; z-index: 2; background: rgba(0,0,0,0); height: 100vh; width: 96%; padding: 20px }
css for tests only
span::before{ content: 'this is span'}
p::after{ content: 'this is pafagraph'; display: block; padding: 20px 0 0}
h1::after{ content: 'this is h1'}
section:hover h1, section:hover p{ background: grey}
span:hover{ background: rgba(0,0,0,0.5); }
<section id="blue"><div><img src="img.jpg" alt="blue"></div><span><h1></h1><p></p></span></section>
<section id="red"><div><img src="red.jpg" alt="red"></div><span><p></p></span></section>
<section id="green"><div><img src="green.jpg" alt="green"></div></section>
Responsiveness is an old story, mobile-first is up to date. Of course with responsive solutions, but #media only for larger devices.
You better not use flex, it leaks badly.

Related

Margin, Padding, Height & width of html and body tags

I wrote this code in order to understand what does it margin, padding and position for the below code. the question are between these /* */. Thanks again.
html {
width: auto;
/* Does auto apply the background-color automatically to the display screen */
height: 100%;
/* 100% means 100% of the display browser??*/
margin-left: 1%;
margin-right: 1%;
/*does changing the value of the margin will change anything in the page*/
margin-top: 1%;
margin-bottom: 1%;
padding-left: 1%;
padding-right: 1%;
padding-top: 1%;
Padding-bottom: 0%;
border: 1px solid black;
background-color: red;
}
body {
background-color: #00FF00;
width: 50%;
/* does it means 50% of the width stated above in the html (auto)*/
height: 50%;
/*does it means 50% of the height of the display browser or we have to add the padding-top(1%) in html*/
position: fixed;
top: 25%;
/* does it mean that the body is shifted to below 25% of it's heigh or 25% of the display browser? */
left: 25%;
/* what is the different if i give 0% to left and i changed the margin-left value to 25%*/
border: 2px solid black;
margin-top: 0px;
margin-left: 0px;
}
header {
width: 50%;
height: auto;
top: 25%;
left: 25%;
/* what does it mean here the value given to top and left??*/
border: 2px solid black;
margin-top: 10%;
margin-left: 25%;
}
h1 {
margin: 5px;
color: blue;
}
<body>
<header>
<h1> MY First webpage </h1>
</header>
</body>
Centering an item within the body is a simple combination of width and margins.
The margin applied below. margin: 0 auto; is shorthand for:
margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
Centered div.wrapper width a width of 960px
body {
margin: 0; /* REMOVE THE MARGIN FROM THE BODY */
}
.wrapper {
width: 960px; /* GIVE THE WRAPPING ELEMENT A WIDTH */
margin: 0 auto; /* USE MARGIN (0 AUTO) TO CENTER THE WRAPPER ON THE SCREEN */
}
/* demo styles */
#header {height: 100px; background: orange}
#content {height: 800px; background: grey}
#footer {height: 150px; background: pink}
<div class="wrapper">
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
</div>
The difference between HTML and Body has been answered in this StackOverflow post.
Yes the body contains everything.
If I understand your question all you should need to do is mess with the body in your .css
body {
margin: XXXpx
}
Replace the X's with a number that best suits what you are after

Why DIVs and Images are not resizing, but being cutted?

Ok, so here we go:
http://judao.com.br/direto-do-epicentro-de-terremoto-a-falha-de-san-andreas/
The content images are huge, 100% width, with a caption. BUT on a 1080p resolution. Anything below that cuts the images, the caption AND the video.
The divs are inside another one, that says max-width: 960px. Here's what I did to make it huge.
#tamanhao {
display: inline-block;
left: -50%;
outline: 0;
overflow: hidden;
position: relative;
text-align: center;
height: auto !important;
width: 200%;
}
#tamanhao img {
max-width: 100% !important;
padding-top: 32px !important;
height: auto !important;
}
.caption {
float: left;
display: inline;
margin-top: -16px;
font-size: 14px;
color: #888;
padding-left: 32px !important;
max-width: 470px;
font-style: italic;
font-family: exo;
text-align: left !important;
line-height: 14px !important;
}
#videozao {
display: block;
left: -50%;
outline: 0;
overflow: hidden;
position: relative;
text-align: center;
width: 200%;
max-height: 744px !important;
}
#videozao iframe {
margin: 0 auto;
display: block;
width: 1280px !important;
height: 720px !important;
position: relative;
}
What am I doing wrong? How can I make it right?
This is because you are using static widths for your content, meaning you're using px instead of percentage. Percentage will make your content to be responsive in smaller screens fiting the screen while resizing the window, while for example 500px will always maintain that same value, unless you use media queries. Here's a example, Resize the window where the images are on this link to see it work.
Code Explanation
<div class="responsiveWidth">
...Conteúdo Responsivo...
<img src="http://i1.wp.com/www.24x7photography.com/wp-content/uploads/2010/08/random2.jpg?w=720" width="500">
</div>
<div class="staticWidth">
...Conteúdo Estático...
<img src="http://i1.wp.com/www.24x7photography.com/wp-content/uploads/2010/08/random2.jpg?w=720" width="500">
</div>
This 2 div's look exaclty the same, but here's where the magic happens
CSS
.staticWidth {
width:500px;
margin:10px;
border:1px solid #000;
}
.responsiveWidth {
width:100%; /* This says the div to stay always 100% of it's parent, in this case it's `body` because we don't have any div container */
margin:10px;
border:1px solid #000;
}
.responsiveWidth img{
width:100%; /* This will make the width of the image 100% as well, the height it's automattic because we didn't set one nor on HTML or CSS */
}
Ok, guys, I solved it. I never heard about the VW thing... And when I did, it worked. Here's the final solution. :)
#tamanhao {
position: relative;
left: 50%;
height: auto !important;
margin: 0px 0 0 -50vw;
width: 100vw;
}
#tamanhao img {
max-width: 100vw !important;
padding-top: 32px !important;
height: auto !important;
}
#videozao {
position: relative;
left: 50%;
max-height: 720px !important;
margin: 0px 0 0 -50vw;
width: 100vw;
}
#videozao .fve-video-wrapper {
margin-left: auto;
margin-right: auto;
max-width: 1280px !important;
max-height: 720px !important;
}
#videozao iframe {
max-width: 1280px !important;
max-height: 720px !important;
}
Thank you / Obrigado! :))))

Trying to extend inner div height past container div height

I'm trying to create an effect where the blue section extends past the gray section.
The blue section is currently contained within the gray section, which may be the problem.
http://nufios.com/node
I've got this as the HTML:
<div id="header-wrapper">
<div id="header">
...
</div></div>
And this as the CSS:
#header-wrapper {
width: 100%;
background-color: #686868;
}
#header {
width: 60%;
background-color: #45719E;
margin: 0 auto;
padding: 0 2em 2em 2em;
position: relative;
}
How do I get it so that the blue section is centered within the gray section, and can still go down below the gray section (i.e., the height is greater on the blue section).
Try using z-index and fixed heights:
CSS:
#header-wrapper {
width: 100%;
background-color: #686868;
height:30px;
}
#header {
width: 60%;
background-color: #45719E;
margin: 0 auto;
padding: 0 2em 2em 2em;
position: relative;
z-index:10;
height:50px;
}
jFiddle demo here: http://jsfiddle.net/LynchJustRules/RQV4h/
Just give your #header-wrapper height. If you want to always fit the blue box's height when its height is less than the gray box's, set the max-height
#header-wrapper {
width: 100%;
background-color: #686868;
max-height: 92px;
}

100% Not Working

I'm having an issue with the age-old problem of 100% height. I know this problem is asked a lot, and I have reviewed this, this, this and countless more. I want to create a basic fixed header, side navigation and main article area, that looks like this:
But, for some reason it's looking like the following (I put 200px padding in the blue bar just to have it appear).
My HTML looks like the following:
<!DOCTYPE html>
<html>
<head></head>
<body>
<header></header>
<section>
<nav></nav>
<article></article>
</section>
</body>
</html>
And my CSS looks like this:
* { -moz-box-sizing: border-box; background-color: transparent; border: 0 none; color: #000000; list-style: none outside none; margin: 0; outline: medium none; padding: 0; text-decoration: none; }
body, html { height: 100%; }
header {
background: #6c6363;
top: 0;
z-index: 100;
height: 100px;
left: 0;
position: fixed;
right: 0;
}
section {
min-height: 100%;
overflow: auto;
position: relative;
padding-top: 100px;
}
nav {
background-color: #747feb;
float: left;
min-height: 100%;
padding-bottom: 200px;
width: 150px;
}
article {
background: #74eb8a;
margin: 20px 20px 20px 170px;
min-height: 100%;
padding: 20px;
position: relative;
}
As you can see, nothing too special. I know that section needs 100% height, and so does body and html. I can position the nav and acticle absolutely, and make something like this:
But, in my actual site (I simplified it for this), the side navigation has drop-downs, which will change the navigation height dynamically. This causes the following to happen:
Absolutely positioned elements won't change the height of the relative wrapper, so I need to float them. However, floating them doesn't make the height become 100%.
I have even made a JSFiddle to show the problem: http://jsfiddle.net/g8VjP/
If anybody can help me out, I'll really appreciate it.
Thank you!
PS: I'm all for using calc() if it works!
SOLUTION
I modified Mayank's answer and managed to come up with a solution. I had to add a couple wrappers, but it worked. My HTML now looks like the following:
<!DOCTYPE html>
<html>
<head></head>
<body>
<header></header>
<section>
<nav></nav>
<div class="cell-wrap">
<div class="table-wrap">
<article></article>
</div>
</div>
</section>
</body>
</html>
With the key being the cell-wrap and table-wrap. I have the nav is one table-cell and the .cell-wrap is another. With the nav having a fixed with, the .cell-wrap fills in the rest. However, I want spacing around the article, so I added .table-cell and made that into a table. That then expands and fills the height and width of the .cell-wrap. I then add 30px padding to give a space around the article (because margins don't work on table-cells) and made the article a table cell.
A bit confusing, but it works!
My CSS is as follows:
* { -moz-box-sizing: border-box; background-color: transparent; border: 0 none; color: #000000; list-style: none outside none; margin: 0; outline: medium none; padding: 0; text-decoration: none; }
body, html { height: 100%; }
header {
background: #6c6363;
top: 0;
z-index: 100;
height: 100px;
left: 0;
position: fixed;
right: 0;
}
section {
display: table;
height: 100%;
min-height: 100%;
padding-top: 100px;
position: relative;
width: 100%;
}
nav {
background-color: #657182;
display: table-cell;
min-height: 100%;
width: 150px;
}
.cell-wrap {
display: table-cell;
height: 100%;
min-height: 100%;
}
.table-wrap {
display: table;
height: 100%;
padding: 30px;
width: 100%;
}
article {
background: none repeat scroll 0 0 #FFFFFF;
display: table-cell;
min-height: 100%;
padding: 20px 20px 120px;
z-index: 1;
}
Here's the fiddle. Not sure why there's a scroll bar at the bottom though, but it seems fine if you show it just normally in your browser.
height: 100% means 100% of the containing block's height. Your containing block, section, does not have a defined height (but a min-height instead). You can either:
Change min-height: 100% on section to height: 100%. or...
Keep min-height: 100% and add a height: 1px (or anything less than 100%) which will be overridden by min-height.
The key here is to have a height property set on the parent.
display:table and display:tabel-cell are you friends here mate!!
Updated your fiddle to slight workarounds and here you go : DEMO
CSS to modify :
section {
min-height: 100%;
overflow: auto;
position: relative;
padding-top: 100px;
display:table;/* addition */
}
article {
background: #74eb8a;
margin: 0px 20px 0px 170px;
min-height: 100%;
width:100%;
height: 100%;
position: relative;
display:table-cell; /* addition */
}
Additionally i took the liberty to remove the extra padding that you have placed inside article , insert a div or section inside article and assign padding to it if it works!!
try this :
nav {
background-color: #747feb;
width: 150px;
position : absolute;
top : 100px;
left : 0;
bottom : 0;
}
article {
background: #74eb8a;
position: absolute;
top : 100px;
left : 150px ; /* nav width*/
bottom : 0;
right : 0;
}

How to squash a div vertically and keep element below 100% on screen

So I have this code here: http://jsfiddle.net/nUwgX/ which has a little arrow at the bottom. What I'd like to happen is when the window get's resized is to keep the arrow about 15% from the bottom of the screen but I'm not sure how I'd do that. Any help would be appreciated.
HTML:
<div class = "container">
<div class = "top-wrapper">
<a id = "name" href = "#">Bigfoot Games</a>
</div>
<div class = "bottom-wrapper">
<p>Content</p>
</div>
</div>
CSS:
.container {
width: 100%;
height: 100%;
margin: 0 auto;
position: relative;
padding: 0;
text-align: center;
}
.top-wrapper {
position: relative;
background: #0f0f0f;
height: auto;
height: 100%;
max-height: 900px;
width: 100%;
margin: 0 auto;
padding: 0;
display: table;
}
.top-wrapper:after {
top: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(15, 15, 15, 0);
border-top-color: #0f0f0f;
border-width: 30px;
margin-left: -30px;
}
#name {
display: table-cell;
text-align: center;
vertical-align: middle;
padding: 20px;
color: white;
font-size: 80px;
text-decoration: none;
margin: auto 0;
}
.bottom-wrapper {
background: white;
margin: 0 auto;
padding: 20px;
}
Edit: Okay, so saying that I wanted the arrow about 15% above is not what I meant! Ha! What I mean is, I want the .top-wrapper to be 100% so that it covers the whole window, and you scroll down to see the .bottom-wrapper - however when the screen is resized (other than my 1920 x 1080 resolution) the arrow get's hidden just out of sight, what I'd like is the arrow to be visible regardless of resolution and have the look (in terms of padding/distance) as a 1920 x 1080 resolution.
Change the css of .top-wrapper to only take up 85%, that leaves 15% for the "arrow" on the bottom to take up.
.top-wrapper {
...
height: 85%;
...
}
see the jsfiddle:
http://jsfiddle.net/nUwgX/1/
Change your .top-wrapper height to 85%
I changed just that in the jsfiddle and it maintains when the screen is resized. If that isn't what you are looking for, please elaborate on the question.
Good Luck!
If you want to keep your bottom-wrapper at the bottom fixed position ...
Replace your .bottom-wrapper class with below
.bottom-wrapper {
position:fixed;
bottom: 0px;
height: 15%;
width: 100%;
background-color: white;
margin: 0 auto;
}
.bottom-wrapper p{
padding-top: 20px;
}
Then change .top-wrapper:after to .bottom-wrapper:before