Responsive design - new background image will not show in smaller viewport - css

I'm pretty new to css and I am working locally so I cannot provide the exact address, but here goes:
I am using the wpexplorer adapt theme which has a responsive layout. I set up the wrapper background in the style.css like so:
#wrap{
background: url(images/scribble-top.jpg) center top no-repeat #fff;
margin: 0 auto;
width: 1040px;
padding: 0 30px;
}
When I moved into responsive.css to start designing the other viewpoints I wanted to use a new background image for the wrap div in the tablet portrait view but for some reason the new image will now show up at all (just remains blank) and the style.css background appears again when I shrink it to the mobile viewports. Here is my coding:`
/* #Tablet (Portrait)
================================================== */
/* Note: Design for a width of 740px */
#media only screen and (min-width: 768px) and (max-width: 959px) {
body {background: #000;}
#wrap {background: url(images/scribble-top-680.jpg) no-repeat center top #fff; width: 680px; overflow:inherit;}
.hp-highlight, .portfolio-item, .home-entry, #footer-one,#footer-two,#footer-three,#footer-four{ width: 155px; }
#home-tagline{ font-size: 21px; }
#search { text-indent: -9999px; }
.loop-entry-thumbnail{width: 35%;}
}
It should be noted that the new image is the exact width of the new wrap div size and that the height is not relative as it is just a banner-type image at the top of the wrapper thus should not interfere with wrap div height.
What am I doing wrong?
Thanks in advance for your help!!!
`

add !important after your background declaration like so:
#wrap {
background: url(images/scribble-top-680.jpg) no-repeat center top #fff !important;
width: 680px;
overflow:inherit;
}

Related

CSS Background Image Appears in Wrong Position on Mobile

I'm having trouble getting the background to display correctly on my landing page. On my desktop, it shows up fine, but on mobile, it appears to be centered in the middle vertically at the top of the page. I'm new to front-end and have been trying all sorts of hacks over the past 4 hours. Could somebody point me in the right direction?
I've set the image to scale to cover the entire screen. There shouldn't be any blank areas. I've tried using responsive modes on my desktop, and the Wright Glider mostly stayed in view as I resized, so the image should also center in the middle of the ... viewport?/window.
For the background, I have a normal sized image, and a cropped image I use for smaller devices
My site is at http://we-fly.ddns.net
Tested only with Chrome 49 on all devices, Android is v5.1
Responsive mode on the desktop doesn't seem to produce the same results.
Source: https://gist.github.com/yanalex981/992a60dd54be82162a45
Screenshots:
Desktop
Nexus 4
Galaxy Tab A 8
Also, if anybody has any suggestions, please share them with me
To fix the issue of your image getting cut off part way, you need to set your background position in your media query's to initial... So in each of your css Media query's paste the following code:
background-position: initial;
This will reset your background position to default when on mobile... from here you should be able to apply different styles to stretch/expand the image to your liking. :)
This is my second answer, I created this instead of adding it to my initial answer because the method is different.
In your HTML (index) file, add the image like this:
<img id="imgBackground" src="http://we-fly.ddns.net/images/back.jpg" />
(I suggest adding it directly after the body tag)
In your CSS, I am just going to post the entire thing, Its a little funny because your last #Media (Min-Width: 601px) is overriding your default for your desktop page... you may want to consider deleting this Media Query... See comments in code below to see changes:
/* Set initial values for your image background */
#imgBackground{
position:absolute; /* Absolute Positioning so we can use "top" and "Left" */
top:0px; /* Set top edge to 0px (Top of the screen) */
left:0px; /* Set left edge of image to 0px, so it starts at the left edge of the screen. */
width:100%; /* We want our widt to be 100% of our browser window */
height:auto; /* we don't care about the image height, so let it set itself based on the image's proportions */
position:fixed; /* Make our image scroll with the user so if they can scroll they don't leave our background behind, exposing the white "body" tag background. */
}
body {
text-align: center;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
margin: 0;
padding: 0;
}
#quote-conatiner {
position: fixed;
margin: auto auto 24px auto;
bottom: 20%;
left: 0;
right: 0;
text-align: center;
background-color:rgba(180, 180, 180, .4);
}
h3 {
font-family: Garamond sans-serif;
color: white;
width: 80%;
margin: .5em auto .5em auto;
}
.button {
font-family: sans-serif;
text-decoration: none;
padding: .3em 0.6em;
border-radius: 8px;
border: 2px solid #59169c;
background-color: #417;
color: white;
box-shadow: 0 0 64px black;
}
.button-container {
position: fixed;
margin-left: auto;
margin-right: auto;
top: 80%;
left: 0;
right: 0;
}
.button:active {
background-color: #330855;
}
#media only screen and (max-width: 600px) {
/* set image background to achieve max Height and we don't care about width (auto) on mobile displays. */
#imgBackground{
position:absolute;
top:0px;
left:0px;
width:auto;
height:100%;
position:fixed;
}
body {
margin: 0;
padding: 0;
}
h3 {
font-size: 1.2em;
}
.button {
font-size: 1.4em;
}
}
#media only screen and (max-width: 400px) {
/* set image background to achieve max Height and we don't care about width (auto) on mobile displays. */
#imgBackground{
position:absolute;
top:0px;
left:0px;
width:auto;
height:100%;
position:fixed;
}
body {
margin: 0;
padding: 0;
}
h3 {
font-size: 0.8em;
}
.button {
font-size: 1.0em;
}
}
/* May want to consider getting rid of this Query, if you don't it is overriding your styles set above your media querys. */
#media only screen and (min-width: 601px) {
/* Set image background qualities for any display larger than 601px.*/
#imgBackground{
position:absolute;
top:0px;
left:0px;
width:100%;
height:auto;
position:fixed;
}
body {
margin: 0;
padding: 0;
}
h3 {
max-width: 600px;
font-size: 1.3em;
}
.button {
font-size: 1.3em;
}
}
"background-size: cover" does not cover mobile screen
and
height: 100% or min-height: 100% for html and body elements?
held the answer. I had to set the height of the root elements for background-size: cover to work:
html {
height: 100%;
}
body {
min-height: 100%;
}
It works on the Nexus 4 and on the Galaxy Tab
Reason for having to do this (stolen from last answer):
Incidentally, the reason why you have to specify height and min-height to html and body respectively is because neither element has any intrinsic height. Both are height: auto by default. It is the viewport that has 100% height, so height: 100% is taken from the viewport, then applied to body as a minimum to allow for scrolling of content.
#Alex how exactly you want image to be display...for different screen size you can use the #media css property to resize image as per screen size.
#media screen and (min-width: 480px) {
body {
property: attribute;
}
}
See more about the #media css attributes here:
http://www.w3schools.com/cssref/css3_pr_mediaquery.asp

Show contents of div when overflow hidden

I have a website where a simple DIV will be hidden when it's width if overflow'ed.
The problem is on large layouts (1000px+) when there's enough width to show off the left & right side of the div - the content is hidden, yet I want it to show.
http://sadakov.com/
div #timeline #life - the width is enough to show content, yet hidden in the large browser;
Thanks.
Check the section #timeline-section, you have a div .container. The bootstrap container class behaves like follow on medium screen :
#media (min-width: 768px)
.container {
width: 750px;
}
.container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
Override the bootstrap with :
#media (min-width: 768px){
#timeline-section .container
{
width:100%;
}
}

height of the Navbar increase after re sizing to mobile size and resetting back again to desktop size

Hi guys i have a very weird problem. If you can see my navbar when resized to mobile size and click in drop down and again make it normal desktop size there is an increase in the navbar height. I wanted a horizontal justified menu for this i used
.menu_container>ul:after{
content: "";
padding-left: 100%;
visibility: hidden;
/* do not use float:left but the display:inline-block below!!! */
display: inline-block;
}
If I removed the content:"", it works fine but the justification of the menu goes off
This is my fiddle
Also attached screenshot for your reference
DEMO
Its because of height: auto; present in
#hidden_menu_collapser:checked + ul {
height: auto;
min-height: 40px;
max-height: 2999px;
background-color:
#FFF;
}
You need update the height:auto; to height: 44px !important; and update it in desktop media query, so that that extra space is removed.
#media only screen and (min-width: 768px) {
#hidden_menu_collapser:checked + ul {
min-height: 40px;
max-height: 2999px;
background-color: #FFF;
height: 44px !important;
}
}
You can just copy paste the above css to your file and it will work

How to make div tags expand to content when one drops below the other

I'm currently making a CSS layout and I have divs side by side in the main content. When the page is resized one drops below the other. When this happens I want the top div to take up the width of the parent div
#MainWrapper #Content {
float: left;
background-color:#E4E4E4;
width:100%;
max-width:1180px;
clear:left;
font-family: Bebas;
}
#Welcometext {
max-width: 500px;
min-width: 100%;
background-color:#399;
display:inline-block;
}
#Slideshow {
width: 100px;
background-color:#C96;
min-width: 200px;
display:inline-block;
}
From your last comment, I think you want to look into # media queries.
You can tell it to change specific properties when the width of the window drops below your specified width.
#media (max-width: 600px) {
#Welcometext{
Properties specific to to a screen size under 600px;
}
}
CSS Media Queries

Absolute Positioning and Media Queries

I'm working on a very basic one page layout that needs to be responsive. It consists
of one large background image and 2-3 divs absolutely positioned around it. http://www.reversl.net/demo/ The reason I'm using absolute positioning is because the background image will need to vary in height but the text box needs to always be positioned the same distance from the bottom of the image.
I also need to place a logo bottom right of the page. Everything works well when viewed on desktop devices. But on smartphones, due to their smaller screens I need to position the logo beneath the text using media queries. Now here's the problem....because the text div is positioned absolutely....the logo get's hidden behind it on smaller screens. My initial thought was to give the logo an absolute position from the top so that it always appears beneath the text box on screen sizes 320px wide and below. However, the text box will need to vary in height so I can't work it this way.
My Question is...how can I place the logo so that it always appears beneath the text box (regardless of the text box height) on screen sizes 320px wide and below?
#bg {
max-width: 100%;
margin: 0;
padding: 0;
position: relative;
}
#title {
margin: 0;
padding: 0;
color: #f0f0f0;
background: #333;
margin: 0;
padding: .5em 1em;
width: 250px;
position: absolute;
top: -2%;
text-align: center;
}
#content {
background: #333;
width: 250px;
position: absolute;
top: 85%;
padding: .5em 1em;
color: #888;
text-align: center;
border: 1px solid #444;
}
footer {
margin: 0;
padding: 0;
}
.logo {
float: right;
width: 50px;
height: 25px;
border: 1px solid #444;
text-align: center;
padding: .5em;
color: #666;
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
#title {top: -17%;line-height: 1;}
}
Desired Layout on mobile
I'm sure you figured this out by now - but one approach that can sometimes be useful is to put the same logo twice in the HTML and show or hide the one you want depending upon the width. I find this to be more maintainable, and obviously if the image has the same URL then there's minimal overhead. Absolute positioning is no fun.
// mobile
#media only screen and (max-width : 319px)
{
.logo.right-justified
{
display: none; // hide right logo
}
}
// desktop
#media only screen and (min-width : 320px)
{
.logo.underneath
{
display: none; // hide bottom logo
}
}

Resources