I've been trying to add a parallax scrolling effect to a background image on my website.
I'm having problems when the browser height changes. (It will push the image up over the text.) Adding queries using min-height or max-height doesn't seem like a very elegant solution.
Do you suggest I include different sizes of the image for different media queries, or just simply alter the background size and background position?
#headerwrap {
background-color: #3F8BE0;
min-height: 1020px;
padding-top: 85px;
padding-bottom: 0;
text-align: center;
/* Parallax scrolling effect */
background-image: url("../img/globe345.png");
background-size: 800px 800px;
background-position: 50% 155%;
background-attachment: fixed;
background-repeat: no-repeat;
}
And here are the media queries I'm using:
#media (min-width: 590px) and (max-width: 767px) {
#headerwrap {
background-size: 450px 450px;
background-position: 50% 55%;
min-height: 720px;
}
}
#media (min-width: 320px) and (max-width: 589px) {
#headerwrap {
background-size: 450px 450px;
background-position: 50% 40%;
min-height: 625px;
}
}
#media (max-height: 950px) {
#headerwrap {
background-size: 450px 450px;
background-position: 50% 75%;
min-height: 710px;
}
}
Related
I would like to change the background based on a boolean.
If I have two backgrounds in CSS:
.background {
background-image: url('../assets/images/Background.png');
background-repeat: no-repeat;
background-size: contain;
#media screen and (max-width: 1280px) {
}
background-size: 100% 670px;
#media screen and (min-width: 1920px) {
background-size: 100% 800px;
}
#media screen and (min-width: 2560px) {
background-size: 100% 1200px;
}
}
.performance-background {
background-image: url('../assets/images/Background-performance.png');
background-repeat: no-repeat;
background-size: contain;
#media screen and (max-width: 1280px) {
}
background-size: 100% 335px;
#media screen and (min-width: 1920px) {
background-size: 100% 325px;
}
#media screen and (min-width: 2560px) {
background-size: 100% 325px;
}
}
I would like to use something similar to:
[ngClass]="{ 'background': displayBackground, 'performance-background': displayPerformanceBackground}"
Thank you so much.
You can add different classes depending of a boolean state using angular ngClass and a ternary operator in a HTML tag
example:
HTML:
<div [ngClass]="boolean ? 'trueClass' : 'falseClass'"> Example Text</div>
"boolean" is a variable and if it is set to true the html tag will use "trueClass" class, else "falseClass"
CSS:
.trueClass{
background: red
}
.falseClass{
background:blue
}
I have a background image setup in my css and everything seems to display fine on the desktop but when I try viewing on my ipad or iphone 6 plus I don't get the image at all (not even an off-center image).
How can I be sure my images resize, center and appear on mobile?
.landpage-img {
background: url('../img/bg-neon-01-2000x1333.jpg') center center no-repeat fixed !important;
height: 1333px;
background-size: cover;
}
#media only screen and (max-width: 1024px) {
.landpage-img {
background: url('../img/bg-neon-01-1024x671.jpg') 50% 0 no-repeat center center fixed !important;
height: 671px;
background-size: cover;
}
}
#media only screen and (max-width: 991px) {
.landpage-img {
background: url('../img/bg-neon-01--991x649.jpg') 50% 80% center center no-repeat fixed;
height: 649px;
background-size: cover;
}
}
#media only screen and (min-width: 0px) and (max-width: 767px) {
.landpage-img {
background: url('../img/bg-neon-01--767x502.jpg') 50% 80% no-repeat fixed !important;
height: 767px;
background-size: cover;
}
}
I am not sure what image you are working with but this should fix the problem (no media queries needed).
body {
background-image: url(/example/example.jpg);
background-repeat: no-repeat;
background-size: cover;
}
Also, see https://www.w3schools.com/css/css_background.asp
I am trying to make header responsive. Currently header is fixed and when you view it from different screen resoultions it is not lookin good.
#tie-wrapper #theme-header {
background-image: url(http://example.com/header-image.jpg);
background-repeat: no-repeat;
}
I wish to have same image on different resolutions. It should decrease with website. Also logo is centered so the image should be.
I really don't know how to add this image for different resolutions.
Thanks
You can use different images at different screen widths using css:
#media only screen and (max-width: 1023px) {
#tie-wrapper #theme-header {
background: url('http://example.com/header-image_FULLWIDTH.jpg') center center/cover no-repeat;
min-height: 500px;
width: 100%;
}
}
#media only screen and (max-width: 767px) {
#tie-wrapper #theme-header {
background: url('http://example.com/header-image_LARGE.jpg') center center/cover no-repeat;
min-height: 400px;
}
}
#media only screen and (max-width: 480px) {
#tie-wrapper #theme-header {
background: url('http://example.com/header-image_MEDIUM.jpg') center center/cover no-repeat;
min-height: 300px;
}
}
I will normally add this code into my template file and using wp_get_attachement(), load up different sizes of images. Or you can hard code it in your styles.css. Either way.
I am trying to add media queries to my homepage banner image. I want it to be responsive and update to 3 different image sizes depending on the screen used. Currently only the medium sized image shows up. Please advise what is wrong with my code. Thanks.
Here is my code:
/*---------------------------------------------
Section#Slider [Banner Image]
-----------------------------------------------*/
/* NEXUS 5 Size 412px, XS
(less than 786px no media query since this is
default in Bootstrap)
*/
/* IPAD SIZE 768px and up, S*/
#media screen and (min-width: 550px) {
#slider {
background: url("../img/smartphoneweb_640x285.jpeg") no-
repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;
padding: 200px 0 280px 0;
position: relative;
}
}
/* MD, desktops, 992px and up */
#media (min-width: 950px) {
#slider {
background: url("../img/smartphoneweb_1280x570.jpeg") no-
repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;
padding: 200px 0 280px 0;
position: relative;
}
}
/* LG, large desktops, 1200px and up */
#media (min-width: 1200px) {
#slider {
background: url("../img/smartphoneweb_1920x855.jpeg") no-
repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;
padding: 200px 0 280px 0;
position: relative;
}
}
The main issue was you forgot to add screen in your 992px media query. I made the changes might be this is helpful.
/*---------------------------------------------
Section#Slider [Banner Image]
-----------------------------------------------*/
/* NEXUS 5 Size 412px, XS
(less than 786px no media query since this is
default in Bootstrap)
*/
/* IPAD SIZE 768px and up, S*/
#media screen and (min-width:0px) and (max-width:550px) {
#slider {
background: url("../img/smartphoneweb_640x285.jpeg") no-
repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;
padding: 200px 0 280px 0;
position: relative;
}
}
/* MD, desktops, 992px and up */
#media screen and (min-width:551px) and (max-width:992px){
#slider {
background: url("../img/smartphoneweb_1280x570.jpeg") no-
repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;
padding: 200px 0 280px 0;
position: relative;
}
}
/* LG, large desktops, 1200px and up */
You can handle style of a spicifique screen size using min and max media query
#media screen and (min-width: 550px) and (max-width: 950px){
#slider {
background: url("../img/smartphoneweb_640x285.jpeg") no-
repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;
padding: 200px 0 280px 0;
position: relative;
}
}
/* MD, desktops, 992px and up */
#media (min-width: 950px) and (max-width: 1200px){
#slider {
background: url("../img/smartphoneweb_1280x570.jpeg") no-
repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;
padding: 200px 0 280px 0;
position: relative;
}
}
#media (min-width: 1200px){
#slider {
background: url("../img/smartphoneweb_1920x855.jpeg") no-
repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;
padding: 200px 0 280px 0;
position: relative;
}
}
I've been trying to enlarge the logo of our site when viewed on mobile phone but no code seems to work. I've tried different versions of this but to no avail:
#media (max-width: 360px) {
.header-logo img {
max-width: 50%;
max-height: 50%;
}
}
I'm not sure what to adjust further since Firebug seems to be displaying code for the desktop version. And I don't really want to change anything on desktop view. Just mobile.
Will appreciate any feedback.
You can make the below changes in the css.
.header-logo img {
max-width: 100%;
max-height: auto;
}
Try this out
.header-logo img {
width: 100%;
height: 400px;
background-image: url('img_flowers.jpg');
background-repeat: no-repeat;
background-size: contain;
border: 1px solid red;
}
At max-width of 360px change style property for class .custom-logo-link as below,
#media screen and (max-width : 360px){
.custom-logo-link {
width: 50%;
}
}
You have to specify only width, it will adjust height automatically.
.header-logo img {
width: 100%;
}
This may be a silly question, but are you sure max-width and max-height is what you want to change here? Those parameters just set the upper limit of how tall and wide the element can be.
https://www.w3schools.com/CSSref/pr_dim_max-width.asp
Perhaps try one of these?
#media (max-width: 360px) {
.header-logo img {
width: 50%;
height: 50%;
}
}
or:
#media (max-width: 360px) {
.header-logo img {
transform: scale(0.5);
}
}