Media query and text - html

I am trying to find a way to place my headline and sub-headline, so they are aligned with eachother. But when i make it fit on 1 device, the text is jumping around on another device. That means I am just going around in circles.
Is there a way where I can say on all mobile devices the margin should be fx: 20px from the left, or how are you guys doing it?
HTML
<div class="max-container-fluid">
<div class="row">
<div class="col-lg-12">
#CurrentPage.GetGridHtml("Grid")
</div>
</div>
</div>
CSS
.header-text h1 {
font-weight: 900;
font-size: 40px;
line-height: 1;
text-transform: uppercase;
color: #fff;
padding-top: 160px;
}
.header-text h2 {
font-size: 20px !important;
margin-bottom: 25px;
font-weight: 900;
color: #fff;
}
/* Smartphones (portrait and landscape) ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
.header-text h2 {
font-size: 20px !important;
margin-left: 20px;
font-weight: 900;
}

Try this:
/* Smartphones (portrait and landscape) ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
.header-text h2, .header-text h1 {
margin-left: 20px;
}
}
You don't need to repeat all the other values if they stay the same — you'll also notice you can combine selectors together, which makes your code lighter.
Also, be careful about using !important (it can make future coding really messy). Try to add specificity before you use that.

Related

Font-sizing issue when rotate from portrait to landscape

solved it:
-webkit-text-size-adjust: 100%;
/* Prevent font scaling in landscape while allowing user zoom */
I have a small font-sizing issue when rotating from portrait to landscape. When testing on responsive mode in safari the font-sizing is working fine, but when testing it on my iPhone 5s the font-size works fine in portrait mode, right font-size the way i set, turning to landscape bigger font-size. The navigation shows the right font-size, but when opening it also changes bigger. All the font-sizing is done on the body tag with px, don't need to specify it separately or use em,rem etc. Can't find where the problem is. Again in responsive mode Safari everything is working.
* {
margin: 0;
padding: 0;
}
body {
font-family: helvetica, arial, sans-serif;
font-size: 23px;
font-weight: normal;
text-align: left;
line-height: 1.2;
color: black;
}
h1, h2 {
font-size: inherit;
font-weight: inherit;
text-decoration: none;
-webkit-hyphens: auto;
hyphens: auto;
}
#media screen and (max-width: 1112px) { /* all after this breakpoint size to 20px */
body {
font-size: 20px;
}
}
#media screen and (max-width: 1024px) { /* all after this breakpoint size to 18px */
body {
font-size: 18px;
}
}
Try to use this media queries:
#media
only screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 1025px),
only screen and ( min--moz-device-pixel-ratio: 2) and (max-width: 1025px),
only screen and ( -o-min-device-pixel-ratio: 2/1) and (max-width: 1025px),
only screen and ( min-device-pixel-ratio: 2) and (max-width: 1025px),
only screen and ( min-resolution: 192dpi) and (max-width: 1025px),
only screen and ( min-resolution: 2dppx) and (max-width: 1025px) {
body {
font-size: 18px;
}
}
For iPhone7 I use this media query:
#media only screen
and (device-width : 375px)
and (-webkit-device-pixel-ratio : 3) {
body {
font-size: 18px;
}
}
Also, you can combine this media queries to resolve your issue.

CSS Media Query Hierarchy - Why Doesn't "Smaller" Media Query Render in Browser / Inspector?

I have several media queries, but there are two that I'm trying to use to style a certain element:
.navbar-default .navbar-nav>li>a
Here is my CSS including previous media queries:
#media (min-width: 1024px) {
.header-column-secondary {
width: 13%;
}
}
#media (min-width: 768px) {
#gatewaylogo {
height: 85px;
padding-left: 0px;
padding-top: 10px;
}
.phone-number {
font-family: 'Oswald', sans-serif;
color: #ffffff;
font-size: 16px;
position: relative;
}
.social-media {
color: #ffffff;
display: table-cell;
padding: 5px 0 5px 5px;
transform: translateY(-7%);
}
}
#media screen and (max-width: 1024px) {
.navbar-default .navbar-nav>li>a
{
font-family: 'Oswald', sans-serif;
color: #1B3764;
text-transform: uppercase;
font-size: 22px;
line-height: 100px;
margin-right: 60px;
padding-left: 0;
padding-right: 0;
}
}
#media screen and (max-width: 768px) {
.navbar-default .navbar-nav>li>a {
font-family: 'Oswald', sans-serif;
color: #1B3764;
text-transform: uppercase;
font-size: 22px;
line-height: 100px;
margin-right: 20px;
padding-left: 0;
padding-right: 0;
}
}
You can see that the media queries that are applying to .navbar-default .navbar-nav>li>a are (max-width: 1024px) and (max-width: 768px)
The idea is that from 1024px - 769px, I want .navbar-default .navbar-nav>li>a to get margin-right: 60px, and at 768px, tablet size, I want .navbar-default .navbar-nav>li>a to get margin-right: 20px. I plan on continuing to add media queries as the browser width gets smaller - 475px, 375px, and 320px.
So why is it that at 768px, the media query doesn't render? It seems that the media query for 1024px is still getting the style and overriding it. I don't want to add !importants, because then I will continue to have to add !importants all the way down to 320px.
A problem is that I like to design from desktop to mobile - not mobile first. Any suggestions? The website is live here: http://nowordpress.gatewaywebdesign.com/
Thanks
Your are missing a viewport meta tag in the head of your page, add something like the following:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Good luck!
There are 2 issues in this problem:
viewport definition is missing
both min-width and max-width need to be defined to get media query in this scenario to work.
Here is some detail explanation:
There is no rule_override_based_on_min/max_width in media query. That is, if there are 2 media query rule-set, one is (max-width: 1024px) and another is (max-width: 768px), there is no guarantee that rules inside (max-width: 768px) will override rules inside (max-width: 1024px) -- when conflict happens between 2 rules inside 2 different media query rule-set, the one that appear later in the CSS win. That's why you need both min-width and max-width for media query.
Here is a simple example: although (max-width: 5000px) is a more reasonable rule to take effect, the final background color is pink.
#media (max-width: 5000px) {
.testd {
background: yellow;
}
}
#media (max-width: 100000px) {
.testd {
background: pink;
}
}
<div class="testd">DDD</div>
And David is correct, the viewport definition is missing. Without it, media query is impossible due to pixel ratio.
I think you need a media query like this:
#media (min-width: 768px) and (max-width: 1024px)

CSS Mobile Definition Not Applying?

I made a site here. It works great on all screens except mobile where the slogan is too large. So i added a mobile css definition for the slogan "Always coding and brewing up something good" but on my phone it does nothing? I am using bootstrap but only with the grid and responsive elements. The css I applied is the below in question is:
#media (max-width: 480px) {
.grabber{
font-size: 12px;
}
}
You defined in your stylesheet.css a following order of styles:
#media (max-width: 480px) {
.grabber{
font-size: 12px;
}
}
.grabber{
color: #3498db;
font-size: 2em;
font-family: 'black_roseregular', Arial, sans-serif;
}
and due to processing css-rules consequentially latest font size style applied to .grabber will be font-size: 2em;. All you need is to swap these statements like this:
.grabber{
color: #3498db;
font-size: 2em;
font-family: 'black_roseregular', Arial, sans-serif;
}
#media screen and (max-width: 480px) {
.grabber{
font-size: 12px;
}
}

Re size HTML website for different screen resolution sizes (School assignment)

this is my first post on this site so I'll try doing things right but sorry if I format things wrong or do anything stupid.
I'm doing an assignment for school due on Thursday June 2nd so I'm really looking for a quick answer as kind of desperate. I need my website to be able to re size for different screen resolutions, I've looked at other answers on this site but most are in reference to making mobile websites. I've read about the media queries rule but everything I read about it is just about making mobile websites, but that looks like a good solution. Really appreciate any help I can get :), here's my code for anyone to look at:
HTML:
<!DOCTYPE html>
<html>
<link href='https://fonts.googleapis.com/css?family=Raleway:300' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.indigo-pink.min.css">
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ann Mockett</title>
<script src="code.js" type="text/javascript" charset="utf-8"></script>
<link href="style.css" rel="stylesheet" type="text/css">
<!__NEEDS DESCRIPTION__>
<meta name="description" content="Description of Site">
<!__NEEDS KEYWORDS__>
<meta name="keywords" content="Selection of Search Terms">
</head>
<body>
<nav>
<ul>
<li><div id="Ann-Nav"><a class="active" href="index.html">Ann Mockett</a></div></li>
<li class="dropdown">
Work
<div class="dropdown-content">
TV
Film
Other
</div></li>
<li>Contact</li>
<li>About</li>
</ul>
</nav>
<div class="bodyimg">
<img src="images/placeholder.png">
</div>
<div class="box"><h3>TV Shows</h3><img src="images/placeholder.png"></div>
<div class="box"><h3>Movies</h3><img src="images/placeholder.png"></div>
<div class="box"><h3>Other Projects</h3><img src="images/placeholder.png"></div>
</body>
CSS:
html{
background-color: #fafafa;
}
h3 {
margin: 0;
font-size: 25px;
font-family: font-family: 'Roboto', sans-serif;
}
body{
width: auto;
margin: auto;
text-align: center;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #009688;
box-shadow: 0px 3px 9px 0px rgba(0,0,0,0.67);
}
li {
float: left;
}
li a, .dropbtn {
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: #004D40;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
background-color: #80CBC4;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #4DB6AC;
}
.dropdown:hover .dropdown-content {
display: block;
}
#Ann-Nav {
font-family: 'Raleway', sans-serif;
font-size: 30px;
}
.bodyimg img{
height: 390px;
width: 100%;
display: block;
margin-bottom: 16px;
}
.box {
background-color: #A7FFEB;
height: 230px;
width: 32%;
float: left;
margin-left: 15px;
margin-bottom: 12px;
display: block;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.box img{
height: 175px;
width: 95%;
display: block;
margin: auto;
position: relative;
top: 50%;
transform: translateY(-63%);
}
Thanks for any help.
You might want to use media queries.
#media screen and (max-width: 480px) {
body {
background-color: lightgreen;
}
}
As for this example, when the screen width gets smaller than 480px, the background-color changes to lightgreen. You can find more on W3Schools!
You could also use bootstrap for a responsive design and pre-made CSS. It's less work and a great solution.
Since you have asked a HW question here, I want to reply in a line : use bootstrap
As Nitsan, Tawfiq, and Danooned said, you should look into media queries. They allow you to design certain aspects of your page differently for different device specifications. Here's a link to get you started:
https://developers.google.com/web/fundamentals/design-and-ui/responsive/fundamentals/use-media-queries?hl=en
** If your teacher/professor allows you to use bootstrap, I would definitely start there, as it does most of the heavy lifting for you.
I hope this can be an answer for what you need. I use it to create html template on just 20 minutes from zero to about 5 responsive pages.
http://tools.qixstudio.com/reycss.css
example of web : http://www.supersukses.net/, http://microsite.detik.com/display/kabar-dpd/, http://microsite.detik.com/display/preview-telkom/.
It's not a perfect css yet, but hopely can be a shortcut to build your responsive website.
Below are the media queries for all devices. You can use them to make your website responsive.
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* STYLES GO HERE */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* STYLES GO HERE */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* STYLES GO HERE */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* STYLES GO HERE */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* STYLES GO HERE */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* STYLES GO HERE */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* STYLES GO HERE */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* STYLES GO HERE */
}
/* iPhone 5 (portrait & landscape)----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 568px) {
/* STYLES GO HERE */
}
/* iPhone 5 (landscape)----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 568px)
and (orientation : landscape) {
/* STYLES GO HERE */
}
/* iPhone 5 (portrait)----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 568px)
and (orientation : portrait) {
/* STYLES GO HERE */
}
Also You can visit https://css-tricks.com/css-media-queries/

How to change CSS id property depending upon screen size

I do know how to use media-screen functionality, but wanna ask you guys something else, something which I really needed for my project. Let me paste some code snippet so that I can elaborate you exactly what I'm looking for.
In below I'm pasting a css ID which I made for my site design:
#Disp_name {
color: #424854;
font-family: 'Open Sans',sans-serif;
font-size: 5.5em;
font-weight: bold;
line-height: 105px;
/*margin: 200px 0 25px;*/
margin: 0px 0 25px;
text-rendering: optimizelegibility;
transition: color 0.3s ease 0s; }
Now I want when anyone open up my project from a small screen device, like
**When open up from 400> and <450px the font-size will be 4em and if >300 and <400px then 3em and if less than <300px then 2em.
What should I do? Please help
As DevIshone said, media queries are exactly what you're looking for. In that case it would look something like this
#media (max-width: 450px) and (min-width: 400px) {
font-size: 4em;
}
#media (max-width: 400px) and (min-width: 300px) {
font-size: 3em;
}
#media (max-width: 300px) {
font-size: 2em;
}
use media queries in your css
for example:
#media screen and (max-device-width: 480px) {
.classname{
font-size: 6em;
}
}