View Full Version : @media advice please
theremotedr
01-02-2018, 10:32 PM
I have an issue with the centering of my photo on most mobile devices.
The photo is not centered to the screen but its more to the right.
Here is a screen which is mostly the same for many devices.
Please could you advise how i correct this within the @media code then i can continue with the others.
Thanks.
http://www.theatticbanwell.co.uk/index.html
The problem is shown once an image is loaded
6242
theremotedr
01-03-2018, 08:36 PM
Is there any advice please.
Thanks
molendijk
01-04-2018, 08:10 PM
Hello Remote Doctor,
Not only is the position of the image not right, its size too is incorrect. On smaller windows, the text is not fully shown.
Unfortunately, I can't immediately see from the code on your page how you have sized the image, so let me just make some general remarks about creating responsive images. I will be using your image.
1. Always start with creating a container div for the image. Give the div a class name (see below), a position (fixed, absolute or relative), a percentage width, and a height (percentages for the width must be preferred, pixels for the height are okay). If you want to center the div, give it also margin: auto. If, in the case of a div that must be centered, you have chosen position: fixed or position: absolute, make the width for the div 100% or choose another percentage (for. ex 70%) and then add: left: 15% (100%-minus-70% divided by 2).
2. Put another div inside the container div and give it width: 100%, height: 100% and margin: auto (for centering). Also give this div a certain max-width because, depending on what image you use, it might extend too much to the left and the right, which would automatically make the image too 'short'.
Adding a background image for the div inside the container div is done by something like:
background-image: url(http://www.theatticbanwell.co.uk/images/fulls/welcome-to-the-attic.jpg); background-repeat: no-repeat; background-size: cover; background-position: center center
(Other values for background-size and background-position are possible, but that's perhaps not relevant here).
3. Here's a possible application of the above lines:
<div class="responsive_img" style="position: relative; width: 70%; height: 400px; margin: auto">
<div style="width: 100%; height: 100%; max-width: 600px; margin: auto; background-image: url(http://www.theatticbanwell.co.uk/images/fulls/welcome-to-the-attic.jpg); background-repeat: no-repeat; background-size: cover; background-position: center center">
</div>
</div>
The need for a maximum width for our image (max-width: 600px) becomes immediately obvious when we omit the maximum width. Try it: the image will be too big on wide screens, as a result of which parts of it will not be visible any more.
4. Finally @media screen code is required to solve possible problems that still may occur at certain window sizes. When we resize the window until it is less than 500px wide, the text on your image is not entirely visible anymore. We can solve this problem by stipulating that the image must be 100% wide at less than 500px:
@media screen and (max-width: 500px) {.responsive_img {width: 100%!important; }}
In fact, it turns out that this does not do the job for windows that are still smaller, so we also make the image shorter (the shorter the image, the more 'it shows':
@media screen and (max-width: 500px) {.responsive_img {width: 100%!important; height:350px!important}}
Note that the keyword !important is not needed if we replace all inline styles with a style sheet while making sure that the @media screen code is below the other css, like this:
<head>
<style>
.responsive_img {position: relative; width: 70%; height: 400px; margin: auto}
.responsive_img_inner {width: 100%; height: 100%; max-width: 600px; margin: auto; background-image: url(http://www.theatticbanwell.co.uk/images/fulls/welcome-to-the-attic.jpg); background-repeat: no-repeat; background-size: cover; background-position: center center}
@media screen and (max-width: 500px) {.responsive_img {width: 100%; height:350px}} </style>
</head>
<body>
<div class="responsive_img" >
<div class="responsive_img_inner" >
</div>
</div>
</body>
I hope this helps.
theremotedr
01-04-2018, 08:17 PM
Hi,
Ive added the following to the main css which seems to have solved the issue for the image.
background-size: contain;
I have noticed the following in respect of the text but cant see why its word warping etc.
If you click the thumbnail top right you will see when loaded the following,on a pc.
CHEST OF DRAWERS £150
H 112cm W 115cm D50cm
This is fine BUT when i check on a mobile i see the following,
CHEST OF DRAWERS
£150
H 112cm W 115cm D
50cm
Many thanks for your reply
molendijk
01-04-2018, 08:29 PM
background-size: contain; hasn't solved the problem because at 980px or less the text on the image gets cut off. Please read carefully what I wrote in post #3.
theremotedr
01-04-2018, 08:42 PM
Thanks,
I have learning difficulties & trying to take on board / where to put it / delete existing code is too much for me.
I am reading it through again but so far dont understand.
Do you get that feeling you wish you never started it.
Thanks
molendijk
01-04-2018, 09:03 PM
I'm sorry to hear about your learning condition.
theremotedr
01-04-2018, 09:22 PM
I appreciate your time spent so far.
I have attached the files if you assist a little further please.
I am trying what i think is correct but when it looks like a patchwork quilt i then know it wasnt in the correct place.
Once i get this sorted i can continue with other tasks which i find easier but these things take me so long to acheive.
Many Thanks.
I understand if you cant/wont help further.6243
theremotedr
01-04-2018, 09:47 PM
Please could you take a look at the site now and advise where i went wrong.
molendijk
01-04-2018, 10:44 PM
I'm so sorry, but I can't help you any further. This would require me to go over all your code instead of trying to solve a local problem. Good luck.
theremotedr
01-04-2018, 10:57 PM
OK i understand.
I asked as i added where i thought the code needed to go but when i uploaded it i knew i was wrong.
I have now put it back to how it was like before.
I you could add the code you specified into the files i sent you then that would be a huge hurdle for me not to go over.
Thanks
molendijk
01-05-2018, 01:03 PM
One last effort. Put this (http://mesdomaines.nu/theremotedr/main.css) in main.css. It seems to work with me.
theremotedr
01-18-2018, 09:17 AM
Morning,
Here is the page in question http://www.theatticbanwell.co.uk/index.html
I would like the background image on the caption section,bottom of the screen to only be shown on tablets & pc etc but not phones in portrait.
Currently in portrait mode on phones its being shown & i don't wish it to be.
In place of the background image being shown on the phones in portrait mode i would like it to be a color #A9A8A6;
Not sure of the correct position within my main css file or code itself.
Something like Background image hidden or media query like if screen if less than XXX then #A9A8A6 otherwise if screen is more than xxx image background-image:url(../../misc/CAPTION-BACKGROUND.jpg);
Thanks very much,
Have a nice day.
theremotedr
01-19-2018, 04:29 PM
Hi,
Please can you check my main css file,at the bottom i have added the supplied code.
I am looking to target mobile phone NOT to show the background image in portrait mode.
I am not sure what number to enter.
If you could advise please,
@media only screen and (max-width: 812px) and (orientation : portrait) {
#viewer .slide .caption {
background-image: none;
}
}
molendijk
01-19-2018, 08:13 PM
#viewer .slide .caption {
background-image: none;
}
is wrong. It should be:
#viewer .slide, #viewer .caption {
background-image: none;
}
theremotedr
01-19-2018, 09:29 PM
Hi,
When i change the code to your supplied code the background image is shown,when using my code the image is not shown and a background color of grey is shown.
This is how i require it so using your code did i make a mistake with the value of 812px or advise otherwise.
The image is called CAPTION BACKGROUND & in my css its shown on line 1143 as shown below.
6250
Thanks very much
molendijk
01-20-2018, 12:26 PM
1.
You want CAPTION-BACKGROUND.jpg to be hidden when the screen gets too small for it to display properly. You don't need CSS-orientation for that, see 3 below.
2.
I don't know where you got your code from, but in your main.css, there are still lots of errors of the type I mentioned in my previous post. Correct them. So #a .b .c should be replaced with #a .b, #a .c.
3.
Once you've done that, use the Responsive Design-modus in Firefox to see at which width your image is still acceptable. For instance, if it doesn't look good at width: 690px and less, then replace 480px with 690px wherever you have it.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.