CSS Media queries not responding - html

I know this question appeared here a few times, but I didn't find the answer I am looking for in them.
Basically I created web for 800x600 resolution, as I want to adjust web for different resolutions on desktop from this point. Before I go on, I want to ask, which is the best option, to use % or px for defining elements ?
So let's say I got web which I want to adjust to different resolutions. There is about 12 available of them for desktop. If I want that web to look properly on each, I should code it for each,right ? What is the best way to target screen resolution ? 800x600 works well, 1024x600 works too. However 1024x768, for some reason is not being targeted. Here I ll post the code:
.scene {
padding: 0;
margin: 0;
}
.fill {
position: absolute;
bottom: 0%;
right: -1%;
left: -2%;
top: -10%;
}
.expand-width {
width: 101%;
}
#media only screen and (min-width: 1024px) and (max-height: 600px){}
#media only screen and (min-width: 1024px) and (min-height: 601px){
body{background-color: red;}
.fill {
position: absolute;
bottom: 0%;
right: -1%;
left: -2%;
top: -10%;
}
.expand-width {
width: 101%;
}
}

Firstly you are using media queries so % or px is not an issue as media queries is ther for resolving that issue only. but for true responsive ness you can go for %.
Next you are designing for 1024*600, so 1024*768 is included in it that's why ir is not effecting the code.
Try !important for 1024*768 resolution styles.

Related

CSS issue with Responsive HOVER DIV

I'm having a problem with the mobile version of a responsive website I'm building.
See that green "info" DIV that appears at the top left corner of the full-screen version of the site?
I need it to move down and live at the bottom of the screen - right above the footer DIV that has all the links - on the mobile version of the site.
Here's the full-screen version:
Here's the Mobile version:
Here's my CSS for the regular full-screen layout:
#productHoverDIV {
z-index: 20;
position: absolute;
top: 10px;
left: 10px;
width: 300px;
padding: 8px;
}
And here's the mobile rule:
#media screen and (max-width: 414px) {
#productHoverDIV {
z-index: 20;
position: absolute;
bottom: 40px; // that's the height of the FOOTER DIV below it
width: 100%;
padding-top: 0px;
padding-bottom: 0px;
}
}
The issue is that even though I'm telling the productHoverDIV to be 40px from the bottom on the mobile layout, it still keeps it's top:10px value from the regular CSS rule, and ends up covering almost the entire screen.
So I need to somehow cancel-out the top rule - or override it with a different value, except
I have no idea know what value to put from the top cause every mobile device has a different height.
How do I resolve this?
You should change it back to its default value, which is auto.
Removed the duplicated z-index and position values.
#media screen and (max-width: 414px) {
#productHoverDIV {
top: auto;
bottom: 40px;
width: 100%;
padding-top: 0px;
padding-bottom: 0px;
}
}

Media queries in my web page not working in firefox and IE and Edge browsers

I am trying to place an image over (on top of) previous div,previous div's position is relative and this img tag has position absolute, for that I wrote media queries for all devices to position the image correctly on different sizes.
Now my problem is media queries are not working for IE,Edge browser and Mozilla Firefox.
my image is totally getting disappeared in these browsers.
my code:
<div class="temp">
</div>
<img src="" class="img img-responsive tit">
and my css is
.temp{
padding-top: 4rem;
background-image: url('../img/BG.jpg');
background-size: cover;
width:100%;
height: 45rem;
position: relative;
opacity: 0.7;
background-repeat: no-repeat;
z-index: -1;
}
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
.temp{
height: 30rem;
}
.tit{
content: url("../img/Title_Landscape.png");
position: absolute;
top: 10rem;
width: 100%;
}
}
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
.tit{
content: url("../img/Title_Landscape.png");
position: absolute;
top: 8rem;
width: 100%;
}
.temp{
height: 40rem;
}
}
#media only screen
and (min-width : 1224px){
.tit{
content: url("../img/Title_Landscape.png");
position: absolute;
top: -1rem;
width: 100%;
}
}
A few potential issues:
img src missing. Move the img url from CSS content: to the actual HTML img per the standard syntax. content: property is reserved to ::after and ::before pseudo-elements. See this MDN entry for reference.
device-width vs width: You might want to use width for media queries, especially when you're testing on your desktop devices. See this SitePoint article for reference.
Missing width ranges: Your media queries handle 320px-480px, 768px-1024px, and >1224px ranges, and skipping all other possible pixel dimensions. When viewport size falls within those ranges, browsers won't have styling to choose from. You might want to either
Apply global styling outside media queries,
Provide all potential ranges, or
Use only min- or max- widths, so there's no missing ranges.
Not knowing what your intention is, and how the entire page is configured, I cannot provide further pointers. See https://codepen.io/baadaa/pen/RwNdpvo for quick look.

Can't remove right margin and it grows as div width shrinks

This seems to be a pretty standard situation but the HTML/CSS is behaving oddly. I'm in the process of building a profile page for a game and am also looking at mobile responsiveness. I can't seem to get the right-margin to go away. It's not a problem in portrait mode (using a Chrome mobile emulator extension) but in landscape, the div + margin is too wide and a scrollbar appears.
HTML:
<div class="userProfile" style="display:none">
<div class="profileTop">
<div class="profilePicture">
<img src="somepicture.png"></img>
</div>
<div class="profileName"></div>
</div>
</div>
CSS:
.profileTop {
position: relative;
top: 10%;
left: 15%;
width: 70%;
height: 12%;
margin: 0;
}
.profilePicture {
display: inline-block;
width: 12vw;
}
.profilePicture img {
width: 100%;
height: auto;
vertical-align: top;
}
.profileName {
display: inline-block;
position: relative;
font-family:Stencil;
font-size: 1.3em ;
font-weight: lighter;
color: white;
left: 20%;
top: 35%;
}
What's odd is that if I decrease the width of the "profileTop" class, the right margin grows so that the whole thing is the same width. Any help?
EDIT: I can get a workable solution by reducing the width of "userProfile" but it's still bothering me that this won't work as originally intended.
EDITx2: The margin also exists on the "userProfile" div. I suppose the "profileTop" div is following its parent somehow but even if I add margin-right: 0 attributes to both divs, the margin is still there. The parent of "userProfile" is the body.
Error in HTML code, you don't need a closing tag for image.
Secondly, you can use media queries to achieve that. Media queries even have an option for landscape and it's really easy to use. Good luck
#media (min-width: 700px) and (orientation: landscape) { ... }
P.S. Use codepen or jsFiddle second time, it will be WAY MORE simpler to help you.
EDIT: Added media queries example
You need to use a more specific selector to override the initially-assigned CSS attribute.
#media (max-width: 768px) {
div.userProfile div.profileTop {
margin-right:0;
}
}

I am having trouble seeing my website on mobile

I am making an website and it works perfectly on pc but when I try to preview on phone I got some problems.
Can anyone help me?
I got everything inside an div with this properties.
width: 960px;
height: 500px;
margin-top: 50px;
margin-left: 312px;
clear: both;
position: relative;
top: -250px;
position: static
Since you're giving the elements static heights it won't change when you switch to mobile platforms. Like Adarsh Mohan said, use #media rules. You can define what lay-out you want per size of the screen. For example:
#media all and (max-width: 320px){
.content{height:250px; width:500px;}
}
This CSS will only be applied to the div 'content' when the width of the screen is 320px (or lower).

Bootstrap & image responsivness

I have a website that is totally responsive however there is one part that is not ans is situated below the slogan URBAN FREE SPIRIT (I am talking about the images)
I tried to had the class container, the class img-responsive but nothing seems to work ..
Here is my website, it will be easier to have a look through the inspector I think than with copy paste
http://v1954132.caqoajqezbu9.demo42.volusion.com/
.home-stage-v2 isn't responsive.
.home-stage-v2 {
width: 1000px;
height: 1200px;
position: relative;
margin-top: 25px;
}
Apply media queries for it for the various widths.
#media (min-width: 1200px) {
.home-stage-v2 {
width: 1000px;
}
}
#media (max-width: 1199px) {
.home-stage-v2 {
width: 100%;
}
}
Example above. You will also have to rework the images as they're with fixed width and also don't respond to width changes. I'd suggest reworking them into either percentages or putting them into a grid.
http://getbootstrap.com/examples/grid/ for examples on grids.