My webpage uses multiple sections. I have the .header section set to 1050px which is perfect for desktop viewing, but when viewed on a mobile device the elements inside overflow into the next section.
How can I seamlessly change the section height for mobile viewing so the elements don' overflow?
Other ideas are welcome as well.
Here is my CSS for the section:
.header-14-sub {
color: #bdc3c7;
background-color: #1c201d;
position: relative;
padding-top: 95px;
padding-bottom: 95px;
height: 1200px;
}
Here's one option for you: http://codepen.io/panchroma/pen/BulnL
I'm using media queries to set different CSS values as the viewport of window width changes. The css is easy to follow and for this to work reliably, you need to include a meta tag similar to the following in the head of your document.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
I've used min-height instead of heght to control the div sizes, because it's more flexible, for example it will probably give better results if a user has a large font setting.
The break points I've chosen for the media queries viewport widths are for illustration only, customise these to fit the specifics of your design.
Good luck!
CSS
.header-14-sub {
color: #bdc3c7;
background-color: #1c201d;
position: relative;
padding-top: 95px;
padding-bottom: 95px;
min-height: 900px; /* set default height */
transition: all 0.5s ease; /* optional css transition effect */
}
/* For media queries to work on smartphones, be sure to add a meta tag similar to the following
<meta name="viewport" content="width=device-width, initial-scale=1.0">
*/
#media (max-width: 480px) {
.header-14-sub {min-height: 300px;}
}
#media (min-width: 481px) and (max-width: 767px) {
.header-14-sub {min-height: 500px;}
}
#media (min-width: 768px) and (max-width: 979px) {
.header-14-sub { min-height: 700px;}
}
#media (min-width: 1200px) {
.header-14-sub {min-height: 1200px;}
}
Related
Here is a simple HTML page that uses multiple #media rules:
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<style type="text/css">
.div1{
height: 100vh;
width: 100vw;
display: block;
position: absolute;
top: 0;
left: 0;
background-color: blue;
}
#media only screen and (max-width: 700px) and (min-width: 500px) {
.div1{
background-color: green;
}
}
#media only screen and (max-width: 499px) and (min-width: 300px) {
.div1{
background-color: red;
}
}
#media only screen and (max-width: 299px) {
.div1{
background-color: yellow;
}
}
</style>
</head>
<body>
<div class="div1"></div>
</body>
</html>
This page should change its colour as the window becomes smaller. It works as intended if I manually resize the web browser window. It also works under Firefox. However, it fails to work properly under Chrome's responsive design mode [Version 69.0.3497.100 (Official Build) (64-bit)]
Strangely enough, the CSS behaves as expected under Chrome's responsive design mode when I recreated it in JSFiddle here: http://jsfiddle.net/7g5jca8x/13/
What is the difference between the JSFiddle version and the HTML version? I can't figure this out.
You were missing the viewport meta tag here is an example
<meta name="viewport" content="width=device-width, initial-scale=1">
I am trying to get my slider on my website to adjust to a different height in a mobile screen but didn't get it to work properly.
The website that i am trying to work on is www.msstoreway.com. After having added the css-code below, i could get the desktop/laptop screen to adjust but on a mobile screen the slider height wont change at all. Can you please advise what i am doing wrong and how to get the height to increase in a mobile screen only.Thanks. See my CSS-Codes that i have added.
regards
Mark
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
#slider .rslides, #slider .rslides li { height: 250px; max-height:
250px; }
#slider .rslides img { height: 100%; max-height: 250px; }
}
The plugin you are using for the slider is scaling the height/width as inline styles which is overriding your css styles.
You are able to add the !important tag which will then override the inline styles, but do note you will lose the aspect ratio scaling that the js plugin is implementing.
#media only screen and (max-width : 500px) {
.rslides { height: 250px !important; }
.rslides img { height: 250px !important; }
}
I am using a WordPress theme called Spacious. I have set a site logo but I can't seem to make the logo responsive. The logo only responds to certain media queries, but none for mobile screen sizes.
I changed the site logo's location from the center below the header to over the header to the left. I think that this may be the issue but I'm not sure. Am I doing something wrong? How can I go about making my logo responsive? The link to my site is: davenport.ryannemurphy.com. The CSS code I am using for the logo is below:
#media only screen and (max-width: 600px) {
.custom-logo {margin-top: 25px;
position: absolute;}
#media only screen and (max-width: 768px) {.header-image {height: 100px;}
.custom-logo {width: 50%;
margin-top: -20px;
}
}
#media only screen and (max-width: 900px) {
.custom-logo {width: 50%;
position: relative;}
}
#media only screen and (max-width: 1100px){
.custom-logo {width: 50%;
margin-top: -20px;
position: relative;
}
}
#media only screen and (max-width: 1500px){.custom-logo{margin-left: 100px;}}
#media only screen and (max-width: 1650px){.custom-logo {margin: 30px; }}
#media only screen (min-width: 1651px) and (max-width: 1850px){.custom-logo {width: 90%;}}
#media only screen and (max-width: 1950px){
.custom-logo {margin-left: -100px;
margin-top: -98px;
position: absolute;}
}
I believe you're missing a closing bracket ("}") in line 3 in the CSS you attached.
Use an online CSS formatter (for example, https://www.cleancss.com/css-beautify/) to format your CSS code and you'll see that most of your media queries are actually below the first one in hierarchy because of that missing curly bracket.
Not sure this is causing the issue, but it's definitely something that can confuse the browsers and cause bugs.
I was having the same problem in Sinatra theme.
I ended up using just width and height but I had to put !important after each.
Here is the css I used:
#media screen and (max-width: 960px) {
img[itemprop="logo"] {
width: 281px !important;
height: 145px !important;
}
}
You have an < img width="450" height="92" .../> hardcoded into your html. I think you need to remove the height and width attributes on the img tag.
I am using media queries to change the font size of some text on my site. However it is not working as I understand them to work.
p {
font-size: 3rem;
#media (min-width: 768px) {
font-size: 2rem;
}
#media (min-width: 992px) {
font-size: 1.5rem;
}
max-width: 1600px;
font-weight: 300;
margin-right: auto;
margin-left: auto;}
Currently the min-width: 768px applies to everything under 992px. For example at 440px width it still has a font size of 2rem. The 3rem font size is never used. One interesting thing to note is that this is only happening in Chromes Responsive device tester. If I make the actual window small then it works.
Since you're going mobile first (using min-width) you are supposed to apply lowest size first.
Try with:
p {
font-size: 1.5rem;
#media (min-width: 768px) {
font-size: 2rem;
}
#media (min-width: 992px) {
font-size: 3rem;
}
max-width: 1600px;
font-weight: 300;
margin-right: auto;
margin-left: auto;}
make sure you include in your <head> this meta tag:
<meta name="viewport" content="width=device-width, initial-scale=1">
This means that the browser will (probably) render the width of the page at the width of its own screen. So if that screen is 320px wide, the browser window will be 320px wide, rather than way zoomed out and showing 960px (or whatever that device does by default, in lieu of a responsive meta tag).
Source: Css tricks
I'm working on making a site mobile friendly, and when I put in the meta tag for viewport it's not recognizing it at all.
I'm still working on media queries, but the viewport isn't doing anything at all.
Site: http://gc200298785.computerstudi.es/test/
Source Code: view-source:http://gc200298785.computerstudi.es/test/
Thank you in advance!
Kayley
It is working fine only. I noticed your css.
#media screen and (max-width: 320px) {
/*main*/
body {
font-size: 16px;
line-height: none;
width: 100%;
}
.container {
max-width: 90%;
padding: none;
margin: 0 auto;
}
a .inside-container {
max-width: 25%;
}
nav {
width: 25%;
}
nav li{
display: inline;
}
#menu {
max-width: 100%;
}
}
add below the code in your css
.container, #paper, #landing, #paper-bottom{width 100%;}
Try adding;
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
Also best practise is to start your css as mobile/ responsive, so in other words dont wrap it in a media query.
Then for desktop start a media query under the main mobile/ responsive css
#media screen and (min-width: 800px) //or what ever size you want {
// insert your styles here
}
You will find that it is a lot easier to approach your development this way.