Fitting CSS background image to IOS - html

I could really use some help.
I have a 2000x1000 image png file I am using as my background for a website. It works great on a desktop. When viewing on my iphone, only the left 1/3 of the image is shown and it stacks two ontop of eachother. I have tried using background-size: auto and 100%, as well as background-attachment:scroll to no avail. I've created a proper aspect ratio image from the larger image and used media queries, but it still ends up super weird. You can find my current media in here which is supposed to detect if the resolution is < 415px to change the size to max, however this doesn't work. Ideally I would like the background to just center in the middle, maintain its aspect ratio and take up the full window height. Here is my CSS. Thanks.
*
{
margin: 0;
padding: 0;
}
.email
{
color:black;
font-size: 25px;
position: fixed;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
}
body
{
background: black;
background-image: url("images/Mountains.png");
}
.html
{
width: 100%;
height: 100%;
}
.github
{
position: fixed;
top: 37%;
left: 41%;
transform: translate(-50%, -50%);
}
#items
{
transition: margin-left .5s;
padding: 20px;
}
.link_in
{
position: fixed;
top: 37%;
left: 59%;
transform: translate(-50%, -50%);
}
.loc
{
color:black;
position: fixed;
top: 45%;
left: 50%;
transform: translate(-50%, -50%);
}
#media screen and (max-height: 450px)
{
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
#media screen and (max-width: 415px)
{
body
{
background-color: black;
background-size: 100% 100%;
position: fixed;
top: 0;
left: 0;
bottom: 0;
/* Preserve aspect ratio */
min-width: 100%;
min-height: 100%;
}
}
#media screen and (max-width: 1100px)
{
.github {
position: fixed;
top: 37%;
left: 31%;
transform: translate(-50%, -50%);
}
.link_in
{
position: fixed;
top: 37%;
left: 69%;
transform: translate(-50%, -50%);
}
}
.sidenav
{
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 60px;
transition: 0.5s;
}
.sidenav a
{
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
.sidenav a:hover
{
color: #f1f1f1;
}
.sidenav .close
{
font-size: 36px;
position: absolute;
top: 0;
right: 25px;
margin-left: 50px;
}
.thanks
{
color:black;
position: fixed;
top: 35%;
left: 50%;
transform: translate(-50%, -50%);
}
.under_construction
{
position: fixed;
top: 37%;
left: 50%;
transform: translate(-50%, -50%);
}

I think you're trying to keep the background image fixed and responsive. You can keep the size to cover, so it will resize the background image to cover the entire container, even if it has to stretch the image or cut a little bit off one of the edges. Then you can set the position to center, so if it stretches it will display the center part of the image. And keep the attachment to fixed, so when you scroll the background image is fixed.
background-size: cover;
background-position:center ;
background-attachment: fixed;

Related

How can I add a caption beneath an image in a basic CSS lightbox?

I'm using the following code to display a simple lightbox using only CSS. (I'd prefer not to use Javascript).
.lightbox {
display: none;
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
text-align: center;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
}
.lightbox img {
position: fixed !important;
top: 50% !important;
transform: translateY(-50%) translateX(-50%);
width: 70%;
}
.lightbox figcaption {
display: inline;
position: fixed!important;
top: 70% !important;
right: 5%;
transform: translateX(0%);
color: white;
}
#media (max-width: 500px) {
.lightbox img {
width: 90%;
}
}
#media (min-width: 800px) {
.lightbox img {
width: 50%;
}
}
<img class="img-thumbnail" src="img/sensei/kieflesson.jpg">
<a href="#_" class="lightbox" id="img1">
<figure><img src="img/sensei/kieflesson.jpg">
<figcaption>Test22</figcaption>
</figure>
</a>
As you can see I've been trying to put in a caption immediately beneath the image using figcaption. I managed to get it to display, but it isn't responsive. I want it to move with the changing image size.
Any help would be much appreciated.
Use position: absolute for image and caption. position: fixed is fine with the wrapper. Right now you have put position: fixed to all wrapper and image also.
Thanks for your help. It seems my code was a little over-complicated. I achieved the desired effect using the following:
.lightbox {
display: none;
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);}
.lightbox figure {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width:90%;
max-width: 500px;}
.lightbox img {
width:100%;}
.lightbox figcaption {
bottom:0;
position:absolute;
color:white;
width: 100%;
max-width: 500px;
text-align: right;
padding-right: 10px;
background: rgba(0, 0, 0, 0.5);}

How do I position a circlular div halfway over an angled div?

I am currently trying to build a portfolio website. Here is my landing page idea:
The part that I am struggling with regarding this design is positioning the down arrow so that it straddles the angled div regardless of screen width.
The closest that I have been able to come is by assigning the following values to the button...
position: absolute;
top: 290px;
left: 30%;
Here is my code:
*,
*:before,
*:after {
box-sizing: border-box;
padding: 0;
margin: 0;
}
section {
width: 100%;
min-height: 400px;
}
.bg-hero {
background: #00C1F7;
position: relative;
}
.bg-dark {
background: #003342;
position: relative;
}
.angled-div::before {
content: '';
width: 100%;
height: 100%;
position: absolute;
background: inherit;
z-index: -1;
bottom: 0;
transform-origin: left bottom;
transform: skewY(-3deg);
z-index: 1;
}
.button {
height: 150px;
width: 150px;
position: absolute;
top: 290px;
left: 30%;
background: #003342;
border-radius: 150px;
z-index: 2;
}
.button span {
width: 100%;
text-align: center;
color: white;
position: absolute;
top: 20px;
font-size: 62px;
}
.button:hover {
cursor: pointer;
background: #004472
}
<section class="bg-hero"></section>
<div class="button"><span>↓</span></div>
<section class="bg-dark angled-div"></section>
Question
How do I position my div so that it is halfway over the angled div and remains exactly half way over the angled div no matter the screen width?
You can have a near perfect centering if you can change your markup:
Change the skewed pseudo element to a span and position the button inside the span so that the button is also skewed.
Center the button using the below and also make a reverse skew:
position: absolute;
top: 0;
left: 50%;
transform: translate(-50%, -100%) skew(3deg);
transform-origin: left bottom;
Now make the contents of the button vertical using transform: rotate(3deg) on the button span element.
Now you can change the value of top (say 50px) to push the button inside the skewed section as much as needed.
See demo below:
*,
*:before,
*:after {
box-sizing: border-box;
padding: 0;
margin: 0;
}
section {
width: 100%;
min-height: 400px;
}
.bg-hero {
background: #00C1F7;
position: relative;
}
.bg-dark {
background: #003342;
position: relative;
}
.angled-div > span{
width: 100%;
height: 100%;
position: absolute;
background: inherit;
z-index: -1;
bottom: 0;
transform-origin: left bottom;
transform: skewY(-3deg);
z-index: 1;
}
.button {
height: 150px;
width: 150px;
position: absolute;
top: 50px;
left: 50%;
transform: translate(-50%, -100%) skew(3deg);
background: #003342;
border-radius: 150px;
z-index: 2;
transform-origin: left bottom;
}
.button span {
width: 100%;
text-align: center;
color: white;
position: absolute;
top: 20px;
font-size: 62px;
transform: rotate(3deg);
}
.button:hover {
cursor: pointer;
background: #004472;
}
<section class="bg-hero"></section>
<section class="bg-dark angled-div">
<span>
<div class="button"><span>↓</span></div>
</span>
</section>

How to create menu fixed to the left corner?

I looking how to create menu like this http://www.panic.lv/en/ . Menu have to bi fixed in left corner, so menu can stay on scroll. When I use CSS from this website
#nav-corner {
width: 100%;
height: 5em;
position: fixed;
top: 0;
left: 0;
z-index: 800;
overflow: hidden;
-o-transform: skewY(-10deg);
transform: skewY(-10deg);
}
I got this on mine website
http://www.awesomescreenshot.com/image/443096/8c36574b9c0461dbd40f92ecb4257485
Menu isn't in top left corner, and when I downsize width he is moving i corner, but without width:100% I'm losing my corner peace. I only could solve this using top:-170, and add height for example 220px; but that is bad solution because of responsive, on smaller resolutions I'm losing my icon.
Can somebody help me please?
Thank you!
you can use this
body{
background-color: #000000;
}
#wrapper {
width: 100%;
text-align: left;
height: auto;
min-height: 100%;
position: relative;
}
* {
box-sizing: border-box;
}
.menu-space {
position: fixed;
height: 203px;
top: 0px;
left: 0px;
z-index: 800;
overflow: hidden;
transform: rotate(-10deg) translate(-50px, -177px);
padding: 43px;
width: calc(100% + 100px);
background: #FFF none repeat scroll 0% 0%;
}
.menu-icon {
position: fixed;
height: 5em;
top: 1.25em;
left: 1.25em;
z-index: 800;
overflow: hidden;
-o-transform: skewY(-10deg);
transform: skewY(-10deg);
}
<div id="wrapper">
<div class="menu-space"></div>
<span class="menu-icon"><img src="http://motiongiraffx.com/wp-content/themes/motiongiraffx/images/menu-icon.png" id="nav-icon" onclick="changeImage()" alt="Menu icon"></span>
</div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
With this code you can remove top: -170px i use transform: rotate(-10deg) translate(-50px, -177px); Instead transform: skewY(-10deg); And other small changes in html and css
can see here http://liveweave.com/WQZWpX
ok for solve problem in mobile you just need add position: fixed; and width: calc(100% + 100px); to .responsive-menu class
.responsive-menu {
display: none;
position: fixed;
z-index: 900;
width: calc(100% + 100px);
}
and for solve small problem follow me
. change #media only screen and (max-width: 640px) { to #media only screen and (max-width: 630px) { in media-query.css
. add this css to media-query.css file
#media (min-width: 550px) and (max-width: 639px) {
.resp-menu-space {
height: 66px;
}
}
test it

How to center a child div with a smaller parent div

I have a div (fixed) which acts like a pop up:
<body>
<div class="popup-container">
<div class="popup-item">
Yolowing
</div>
</div>
</body>
This css allows the container to be horizontally centered (having a 100% width makes everything behind it unclickable; thus, I set it to 1px):
.popup-container {
position: fixed;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
width: 1px;
z-index: 9999;
}
.popup-item {
display: block;
min-width: 20px;
padding: 25px 50px;
background-color: yellow;
}
However, I am unable to center .popup-item due to the parent element .popup-container being smaller than its child. How do I center .popup-item while still being able to click it (pointer-events: none entirely disabled it)?
Vote to Close almost has it, but with the 1px width, the element doesn't get centered.
Do this instead:
.popup-container {
position: fixed;
left: 0;
right: 0;
z-index: 9999;
text-align:center;
height:0px;
}
.popup-item {
display: inline-block;
min-width: 20px;
padding: 25px 50px;
background-color: yellow;
}
This will make it centered, because the container is 100% wide. However, pointer-events:none; will allow you to click through to anything below it.
A couple of solutions.
First, you can make the child of the container centered using translateX() transform: http://jsfiddle.net/Yjz5R/. The same effect can be accomplished using negative margins, but the width for the container's child has to be set: http://jsfiddle.net/9Qmza/.
CSS:
.popup-item {
position: absolute;
min-width: 20px;
padding: 25px 50px;
background-color: yellow;
top: 0;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
Or second, you can make the container "immune" to click events:
Markup:
<input type = "checkbox" id = "clickToggle" />
<label for = "clickToggle">Click me</label>
<div class="popup-container">
<div class="popup-item">
Yolowing
</div>
</div>
Styles: http://jsfiddle.net/CVfHt/.
.popup-container {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(200, 200, 200, 0.5);
pointer-events: none;
}
.popup-item {
position: absolute;
min-width: 20px;
padding: 25px 50px;
background-color: yellow;
top: 50%;
left: 50%;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
pointer-events: all;
}
input[type = "checkbox"] {
display: none;
}
input[type = "checkbox"] + label {
cursor: pointer;
}
input[type = "checkbox"]:checked ~ div {
display: none;
}
Lastly, a question/comment. If you do not want the container to be visible, then why use it at all? Just keep the markup of the child and get rid of the container: http://jsfiddle.net/yvc4E/.
.popup-container {
position: fixed;
left: 0;
right: 0;
margin-left: auto; /* remove this line - unnecessary*/
margin-right: auto; /* and this line, remove */
width: 1px;
z-index: 9999;
text-align: center; /* add this */
}
.popup-item {
display: inline-block; /* change to inline-block */
min-width: 20px;
padding: 25px 50px;
background-color: yellow;
}

Vertically aligning div with fixed div as a parent?

I have a relatively div positioned on top of a fixed position div and I would like to vertically align this first div. Is there a way to do this? This is my current markup:
<div class="overlay">
<div id="dialogInvoice">
content
</div>
</div>
The CSS:
.overlay {
height: 100%;
width: 100%;
top: 0;
left: 0;
background-color: rgba(0,0,0,0.5);
position: fixed;
z-index: 10;
}
#dialogInvoice {
width: 390px;
height: 722px;
margin: 0 auto;
padding-top: 28px;
border-radius: 4px;
background: #ffffff;
position: relative;
}
Any suggestions on this? I did try the line-height method but this is apparently only working when using mere text.
If your element does not have a fixed width or height then you can't use the other solutions without using javascript to calculate the values.
Here is an alternative.
#dialogInvoice {
width: 390px;
height: 722px;
padding-top: 28px;
border-radius: 4px;
background: #ffffff;
position: absolute;
left:50%;
top:50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
what you need to add to your css of #dialogInvoice is
top: 50%;
and change the margin to
margin: 361px auto;
(361 is 722 / 2)
it will first push your container half way down the page and then push it back up the required value, which is exactly half of its height (361px)
here is a jsfiddle for better understanding.
This CSS may do what you require:
.overlay {
height: 100%;
width: 100%;
top: 0;
left: 0;
background-color: rgba(0,0,0,0.5);
position: fixed;
z-index: 10;
}
#dialogInvoice {
margin: 0 auto;
padding-top: 28px;
border-radius: 4px;
background: #ffffff;
position: absolute;
top: 100px;
bottom:100px;
left:100px;
right:100px;
}