How to set media queries for high resolution screens in html - css

I have a query. How to set media queries for high-resolution screens like 4k, 5k, retina display etc. As I have been reading about it, I understood we can use resolution specific media queries. But I have a query of how to understand the breakpoints for 4k 5k screens and how to know they reliability towards future high-resolution screens.
Can anyone suggest how to use CSS for high res screens?

If you will use relative units (em, or rem) it will give you a possibility to equal scaling for elements, and to write a minimum media queries.
EDITED:
You can see how to use em on this example:
.parent {
background: red;
font-size: 20px;
padding: 1em;
}
.child {
margin: 1em;
font-size: 15px;
}
.childOfChild {
margin-left: 1em;
font-size: 2em;
}
<div class="parent">
<h2 class="child">
Hello World!
<span class="childOfChild">Some Text</span>
</h2>
</div>
You can see how to use rem on this example:
html {
font-size: 16px;
}
.child {
font-size: 1rem;
padding: 1rem;
background: blue;
color: white;
}
.childOfChild {
font-size: 0.8rem;
margin-left: 1.2rem;
}
#media (min-width: 2000px) {
html {
font-size: 20px;
}
}
#media (max-width: 1200px) {
html {
font-size: 14px;
}
}
#media (max-width: 768px) {
html {
font-size: 12px;
}
}
<div class="parent">
<h2 class="child">
Hello World!
<span class="childOfChild">Some Text</span>
</h2>
</div>

Related

Why do CSS div dimensions differ from Devtools dimensions?

I am testing responsiveness in my react app and I have come across a pretty confusing issue while working with my devtools console. The width of the element I am working with is 768px. These are the same dimensions for a tablet screen. However, the element width only covers part of the screen as shown in the screenshot below.
Where is this extra space on the right coming from? I believe the element should cover the entire width of the screen since the dimensions are equal. I have also in my CSS file:
html, body {
margin: 0;
padding: 0;
}
My full CSS file looks like this:
#import url("https://fonts.googleapis.com/css?family=Akaya+Telivigala&display=swap");
.projects {
display: inline-block;
width: 500px;
font-size: 1.7em;
color: white;
width: 100%;
height: 100vh;
}
.indivProject {
display: grid;
grid-template-columns: 900px 120px;
}
.projImage img {
width: 450px;
height: 450px;
margin-top: 150px;
}
#media screen and (min-width: 320px) {
.projects {
width: 100%;
margin-left: 60px;
height: 100%;
}
}
#media screen and (min-width: 768px) {
.projects {
width: 100%;
margin-left: 60px;
height: 100%;
}
}
.project-text {
color: white;
font-size: 0.8em;
margin-left: 180px;
margin-top: 240px;
}
.tech {
margin-left: 250px;
font-size: 0.7em;
color: rgb(9, 150, 79);
}
#media screen and (min-width: 320px) {
.project-text {
margin-left: 80px;
font-size: 1.7em;
width: 100%;
}
}
#media screen and (min-width: 768px) {
.project-text {
text-align: center;
}
}
#media screen and (min-width: 320px) {
.projImage img {
display: none;
}
}
a {
text-decoration: none;
color: rgb(9, 150, 79);
}
a:hover {
color: saddlebrown;
}
h4 {
color: rgb(15, 89, 102);
text-align: center;
font-size: 1.2em;
}
The corresponding markup looks like this:
import React from 'react';
import './styles.css';
import nutri from '../../images/nutri.png';
import akan from '../../images/akan.png';
import convo from '../../images/convo.png';
function Projects(){
return (
<div className="projects">
<h4>HIGHLIGHTED PROJECTS</h4>
<div data-aos="zoom-out" className="indivProject">
<div data-aos="zoom-out" className="project-text">
<p>
<h3>TEXTR</h3>
This is a mobile-responsive messaging app built using React and leverages the use of ChatEngine to provide an interactive communication experience. Hosted on Netlify.
</p>
<ul className="tech">
<li>React</li>
<li>Chat Engine</li>
<li>React Testing Library</li>
</ul>
</div>
<div className="projImage"><img src={convo} alt=""></img></div>
</div>
<div data-aos="zoom-out" className="indivProject">
<div data-aos="zoom-out" className="project-text">
<p>
<h3>NUTRIAPP</h3>
This is an application that acts more like a remote doctor. By inputing some personal data such as Weight, Height and Physical activity, the user reveives ther caloric intake recommendation and is able to evaluate their health status.
</p>
<ul className="tech">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
<div className="projImage"><img src={nutri} alt=""></img></div>
</div>
<div data-aos="zoom-out" className="indivProject">
<div data-aos="zoom-out" className="project-text">
<p>
<h3>AKAN NAMES</h3>
Akan names are derived from Ghanian culture. Frequently in Ghana, children are given their first name as a 'day name' which corresponds to the day in the week they were born. This application will help you identify an Akan name based on the time you were born.
</p>
<ul className="tech">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
<div className="projImage"><img src={akan} alt=""></img></div>
</div>
</div>
)
}
export default Projects;
I have tried restarting my devtools but still no resolve.

How to modify responsive timeline?

http://codepen.io/kjohnson/pen/azBvaE
My friend and I are thinking of using that timeline in our website. But the problem is we've 5 sections that needs to be added to timeline, whereas the original timeline have only 3 sections.
I've tried to add two more sections to that code, but it's losing its shape and responsiveness.
Is it possible to extend that timeline and maintain its responsiveness?
HTML
<!-- STEPS -->
<section id="Steps" class="steps-section">
<h2 class="steps-header">
Responsive Semantic Timeline
</h2>
<div class="steps-timeline">
<div class="steps-one">
<img class="steps-img" src="http://placehold.it/50/3498DB/FFFFFF" alt="" />
<h3 class="steps-name">
Semantic
</h3>
<p class="steps-description">
The timeline is created using negative margins and a top border.
</p>
</div>
<div class="steps-two">
<img class="steps-img" src="http://placehold.it/50/3498DB/FFFFFF" alt="" />
<h3 class="steps-name">
Relative
</h3>
<p class="steps-description">
All elements are positioned realtive to the parent. No absolute positioning.
</p>
</div>
<div class="steps-three">
<img class="steps-img" src="http://placehold.it/50/3498DB/FFFFFF" alt="" />
<h3 class="steps-name">
Contained
</h3>
<p class="steps-description">
The timeline does not extend past the first and last elements.
</p>
</div>
</div><!-- /.steps-timeline -->
CSS
$outline-width: 0;
$break-point: 500px;
#import url(http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic);
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
font-family: lato;
}
$gray-base: #999999;
$brand-primary: #3498DB; //Zen Blue
.section-header {
color: $brand-primary;
font-weight: 400;
font-size: 1.4em;
}
.steps-header {
#extend .section-header;
margin-bottom: 20px;
text-align: center;
}
.steps-timeline {
outline: 1px dashed rgba(red, $outline-width);
#media screen and (max-width: $break-point) {
border-left: 2px solid $brand-primary;
margin-left: 25px;
}
#media screen and (min-width: $break-point) {
border-top: 2px solid $brand-primary;
padding-top: 20px;
margin-top: 40px;
margin-left: 16.65%;
margin-right: 16.65%;
}
&:after {
content: "";
display: table;
clear: both;
}
}
.steps-one,
.steps-two,
.steps-three {
outline: 1px dashed rgba(green, $outline-width);
#media screen and (max-width: $break-point) {
margin-left: -25px;
}
#media screen and (min-width: $break-point) {
float: left;
width: 33%;
margin-top: -50px;
}
}
.steps-one,
.steps-two {
#media screen and (max-width: $break-point) {
padding-bottom: 40px;
}
}
.steps-one {
#media screen and (min-width: $break-point) {
margin-left: -16.65%;
margin-right: 16.65%;
}
}
.steps-two {
}
.steps-three {
#media screen and (max-width: $break-point) {
margin-bottom: -100%;
}
#media screen and (min-width: $break-point) {
margin-left: 16.65%;
margin-right: -16.65%;
}
}
.steps-img {
display: block;
margin: auto;
width: 50px;
height: 50px;
border-radius: 50%;
#media screen and (max-width: $break-point) {
float: left;
margin-right: 20px;
}
}
.steps-name,
.steps-description {
margin: 0;
}
.steps-name {
#extend .section-header;
#media screen and (min-width: $break-point) {
text-align: center;
}
}
.steps-description {
overflow: hidden;
#media screen and (min-width: $break-point) {
text-align: center;
}
}
If you a novice I'd recommend you LEARN first. Copy templates/snippets is good to save your time when you know what you are doing.
I found a perfect tutorial for you here
Just to emphasize that's my opinion, I hope it helps in a certain way..
EDIT: If still want to develop in that way here's a codepen snippet with a fully responsive horizontal timeline. Just have to put more <li> inside the <ul>

How to create Bootstrap 3 responsive text using rem units

I am attempting to create a rem based site using Twitter-Bootstrap 3. In particular my text is not behaving responsively. It is just wrapping without changing font size or line height. I added a color change to the #media statements to visually track the break points. I'm not seeing any color changes either so the custom #media code is also not working. From what I have researched, it should be working. Obviously, I'm missing something. Please take a look at https://jsfiddle.net/dlearman/995w62e0/4/ and steer me in the right direction.
html {
font-family: 'NimbusSanNov-Reg', "HelveticaNeueLight", "HelveticaNeue-Light", "Helvetica Neue Light", "HelveticaNeue", "Helvetica Neue", sans-serif;
font-size: 15px;
/* set default 1rem = 15px */
color: #302C25;
line-height: 1.618;
-webkit-text-size-adjust: 100%;
/* why is this needed? */
-ms-text-size-adjust: 100%;
}
body {
background-color: #FFF;
}
#page {
position: relative;
top: 5.33rem;
left: 7.4rem;
padding-bottom: 7.667rem;
}
.container-full-width {
position: relative;
padding-left: 0;
padding-right: 0;
margin-left: 0;
margin-right: 0;
}
.row-centered {
text-align: center;
}
#testBox {
position: relative;
display: inline-block;
margin-top: 0;
margin-left: 60rem;
width: 10rem;
height: auto;
}
.bigText {
font-family: 'NimbusSanNov-Reg''HelveticaNeueLight', 'HelveticaNeue-Light', 'Helvetica Neue Light', 'HelveticaNeue', sans-serif;
font-size: 1rem;
margin: 0 0 1.667rem 0;
letter-spacing: .0667rem;
}
.bigTextItalic {
font-family: 'NimbusSanNov-RegIta', 'HelveticaNeueLightItalic', 'HelveticaNeue-LightItalic', 'Helvetica Neue LightItalic', 'HelveticaNeueItalic', sans-serif;
font-size: 1rem;
letter-spacing: .0667rem;
margin: 0 0 1.667rem 0;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<div id="page" class="container-fluid container-fluid-full-width">
<div id="homeBrandCopy" class="container-fluid container-full-width">
<div class="container">
<div class="row row-centered">
<div class="col-md-2">
</div>
<div class="col-md-8">
<div class="testBox center-block">
<p class="text-center bigText">Every writer is cursed or blessed with a unique creative metabolism: the distinctive speed and efficiency with which he or she converts the raw fuel of life into the mystical,<span class='bigTextItalic'> dancing blue smoke of art. </span>
</p>
</div>
</div>
<div class="col-md-2">
</div>
</div>
</div>
</div>
</div>
Please make sure there is no space between the # and media because CSS sees #media as a media query.
CSS:
#media only screen and (max-width 1200px) {
html {
font-size: 1.333rem;
line-height:2.157;
color:#000FFF;
}
}
#media only screen and (max-width 992px) {
html {
font-size: 1rem;
line-height:1.618;
color:#FF0000
}
}
#media only screen and (max-width 768px) {
html {
font-size: .933;
line-height:1.510;
color:#00FF00;
}
}
#media only screen and (max-width 480px) {
html {
font-size: 1.067;
line-height:1.726;
color:0000FF;
}
}
#media only screen and (max-width 320px) {
html {
font-size: 1.333;
line-height:2.157;
color:#FF00FF;
}
}
Reference: http://www.w3schools.com/cssref/css3_pr_mediaquery.asp

Are REM units unusable with media queries? How to update root font-size?

So, I have a website using lots of "ems" for fonts, they're literally everywhere. I managed to replace them all with rems, and now my media queries doesn't seem to be working as I've been changing my root font-size in them.
Here's the HTML:
<div id="em">
<h1>EMs are better?</h1>
<p>A text.</p>
</div>
<div id="rem">
<h1>REMs aren't?</h1>
<p>Sad panda.</p>
</div>
And CSS:
body {
font-size: 14px;
}
div {
margin: 10px;
padding: 20px;
text-align: center;
background: #efefef;
}
#em h1 { font-size: 2em; }
#em p { font-size: 1em; }
#rem h1 { font-size: 2rem; }
#rem p { font-size: 1rem; }
#media screen and (max-width: 500px) {
body {
font-size: 6px;
background: red;
}
}
Try resizing window to see what happens, REM box doesn't seem to change at all...
http://jsfiddle.net/Q5vSC/
Rem units are based off the font size of the html element, not the body.
Your css would change to this:
html { // changed from body to html
font-size: 14px;
}
div {
margin: 10px;
padding: 20px;
text-align: center;
background: #efefef;
}
#em h1 { font-size: 2em; }
#em p { font-size: 1em; }
#rem h1 { font-size: 2rem; }
#rem p { font-size: 1rem; }
#media screen and (max-width: 500px) {
html { // changed from body to html
font-size: 6px;
background: red;
}
}
Notice we target the html element in the first line and in the media query.
Here is your jsfiddle modified to work with rems.

css - how to determine why a particular css rule is being overwritten

I'm trying to troubleshoot a css problem (using bootstrap.css btw).
I've created my own custom css file so that I can add to / or in some cases, replace the bootstrap rule.
I've been using the "Inspect" tool in firefox - under the Web Developer options.
I can see that the style I think should be applied to my page has been crossed out. I just read in another post here on stackoverflow that that means the style has been overwritten. But i don't understand why this is being overwritten or how to further troubleshoot this issue.
The css rule itself is a media query - I'm trying to check for the size of the browser, and then depending on how big it is, change an image. How am i changing my browser size? I'm using Firefox's responsive design view tool instead of doing it manually.
Here's the rule that is being overwritten:
#media (max-width: 360px) {
.hero-unit h1 {
margin-bottom: 0;
font-size: 0.2em;
line-height: 1em;
letter-spacing: -5px;
color: inherit;
}
.hero-unit p {
font-size: 0.2em;
font-weight: 50;
line-height: 1em;
color: inherit;
}
.hero-unit {
background: url("../img/1.jpg");
padding: 1em;
margin-bottom: 2em;
background-color: #eeeeee;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
}
This is the one that is being applied:
#media (max-width: 979px){
.hero-unit h1 {
margin-bottom: 0;
font-size: 2.0em;
line-height: 1.5;
letter-spacing: -1px;
color: inherit;
}
.hero-unit p {
font-size: 1.2em;
font-weight: 20;
line-height: 1.5em;
color: inherit;
}
.btn-large {
padding: 6px 10px;
font-size: 11px;
line-height: normal;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.hero-unit {
padding: 1em;
margin-bottom: 2em;
background-color: #eeeeee;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
h2 {
font-size: 1.5em;
line-height: 2em;
}
}
Can you tell me where I've gone wrong? Thanks.
EDIT 1:
Here's the actual html where this css is supposed to be applied to:
<div class="container">
<div class="span8">
<div class="hero-unit">
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
</div>
<div class="row-fluid">
<div class="span4">
<h2>list 1 </h2>
<p>list</p>
<p><a class="btn" href="<?php echo base_url();?>index.php/list1/"><i class="icon-list-alt"></i> View details »</a></p>
</div><!--/span-->
<div class="span4">
<h2>list2</h2>
<p>some other list</p>
<p><a class="btn" href="<?php echo base_url();?>index.php/list2/"><i class="icon-globe"></i> View details »</a></p>
</div><!--/span-->
<div class="span4">
<h2>routes</h2>
<p>list of all routes</p>
<p><a class="btn" href="<?php echo base_url();?>index.php/routes/"><i class="icon-globe"></i> View details »</a></p>
</div><!--/span-->
</div>
</div>
It's the hero-unit that has a background image defined in the css. I'm not sure if this is the best way to do this or not, but for the most part, it seems to be working.
Thank you.
If the width of the browser is 360px and the max-width: 979px is below the max-width: 360px in your CSS it will take precedence since both apply to a browserwidth of 360px.
Either move the max-width: 360px below or set a #media (max-width: 979px) and (min-width: 361px).
Also, this is a good read on precedence in CSS, http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/

Resources