How to create Bootstrap 3 responsive text using rem units - css

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

Related

Limit div width and center

I'm writing a tag cloud. When displayed on a phone, it displays the full width and looks fine. But on a desktop, it also displays the full width and doesn't look as I want. I would like to limit the width of the div on a desktop to some part of the total width, say 60%. But as you can see in my jsfiddle, when the display is widened, the text becomes one long-line. I've tried applying various suggestions I've found here, like max-width, but none seem to make a difference. Can someone please point out how to do this? Here's my code:
<style>
#container {
width:100%;
text-align:center;
}
.cloud {
display:inline;
list-style-type:none;
max-width:50%;
width:100%;
}
.cloud li {
list-style: none;
display: inline;
}
#tagcloud .smallest { font-size:.8em; font-weight:400; }
#tagcloud .small { font-size:.9em; font-weight:500; }
#tagcloud .medium { font-size:1em; font-weight:600; }
#tagcloud .large { font-size:1.3em; font-weight:700; }
#tagcloud .largest { font-size:1.6em; font-weight:800; }
</style>
<div id="container">
<ul class="cloud" id="tagcloud">
<li class="small">performance testing</li>
<li class="largest">stress testing</li>
<li class="large">conformance testing</li>
<li class="medium">acceptane testing</li>
<li class="small">smoke testing</li>
<li class="smallest">smoke testing</li>
<li class="small">performance testing</li>
<li class="largest">stress testing</li>
<li class="large">conformance testing</li>
<li class="medium">acceptane testing</li>
<li class="small">smoke testing</li>
<li class="smallest">smoke testing</li>
</ul>
</div>
You have to use media queries to control the width in certain screen sizes. Note that I used 4 media queries, which are the common breakpoints for various screen sizes (commonly used by Bootstrap 4); for the smallest screen size (<576px width), the CSS style is set outside the media queries.
Also note that I have changed the display of container from inline to inline-block, to give width attribute to the element.
#container {
width: 100%;
text-align: center;
}
.cloud {
display: inline-block;
list-style-type: none;
width: 90%;
}
.cloud li {
list-style: none;
display: inline;
}
#tagcloud .smallest {
font-size: .8em;
font-weight: 400;
}
#tagcloud .small {
font-size: .9em;
font-weight: 500;
}
#tagcloud .medium {
font-size: 1em;
font-weight: 600;
}
#tagcloud .large {
font-size: 1.3em;
font-weight: 700;
}
#tagcloud .largest {
font-size: 1.6em;
font-weight: 800;
}
/* ---------------------------------------------
Media Queries
--------------------------------------------- */
/* SM Small devices */
#media(min-width: 576px) {
.cloud {
width: 80%;
margin: auto;
}
}
/* MD Tablets */
#media (min-width: 768px) {
.cloud {
width: 70%;
margin: auto;
}
}
/* LG Desktop */
#media (min-width: 992px) {
.cloud {
width: 60%;
margin: auto;
}
}
/* XL Modern desktop */
#media (min-width: 1200px) {
.cloud {
width: 50%;
margin: auto;
}
}
Demo: JSFiddle

Why CSS is not working as desired on android?

The CSS media query for small devices isn't working for Android when screen is rotated in landscape mode, the background color isn't changing, and the form overflows.
The site works good, when screen rotation is turned off, I don't know why is this happening, since there is no problem in IOS, only in Android.
The CSS code:
* {
box-sizing: border-box;
}
*:focus {
outline: none;
}
body,
html {
height: 100%;
margin: 0;
}
body {
background: linear-gradient(to top left, #5487ab 17%, #ffffff 102%) fixed;
background-repeat: no-repeat;
background-size: cover;
}
#media screen and (max-width: 549px) {
.houseImg {
display: none;
}
.container {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
background-color: #f1f1f1e0;
height: 386px;
width: 278px;
border-radius: 9px;
margin: auto;
margin-top: 4rem;
}
.brand {
display: block;
margin: auto;
width: 29%;
padding-top: 28px;
}
.brandName {
font-family: 'Source Serif Pro', serif;
display: block;
text-align: center;
font-size: 19px;
color: #0060a3;
letter-spacing: 0.4px;
margin: 0;
margin-top: 7px;
}
.usrTxtField {
background-color: #f1f1f1e0;
width: 237px;
height: 31px;
border: 1px solid #8c8b8b;
border-radius: 7px;
font-size: 16px;
padding-left: 8px;
font-family: 'Maven Pro', sans-serif;
color: #252525;
transition: none;
display: block;
margin: auto;
}
.usrTxtField:focus {
border: 2px solid #3d79a2;
}
.usr {
margin-left: 20px;
margin-bottom: 4px;
margin-top: 20px;
font-family: 'Maven Pro', sans-serif;
font-size: 12.5px;
color: #5a5a5a;
}
.submitLogIn {
background-color: #0060a3;
border: none;
display: block;
margin: auto;
text-align: center;
height: 40px;
width: 125px;
margin-top: 17px;
border-radius: 25px;
color: #fff;
font-size: 14px;
letter-spacing: 0.4px;
font-family: 'Maven Pro', sans-serif;
cursor: pointer;
}
.checkboxSave {
margin-left: 20px;
margin-top: 10px;
}
.saveText {
font-family: 'Maven Pro', sans-serif;
color: #5a5a5a;
font-size: 12px;
}
.forgotPassword {
font-family: 'Maven Pro', sans-serif;
color: #0060a3;
font-size: 12px;
text-decoration: none;
margin-left: 18px;
}
}
The HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Art</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href="https://fonts.googleapis.com/css?family=Source+Serif+Pro:600&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Maven+Pro:500&display=swap" rel="stylesheet">
</head>
<body>
<div class="gridContainer">
<div class="container">
<img src="img/artLogo.png" class="brand">
<p class="brandName">ART PS GROUP</p>
<form autocomplete="off">
<p class="usr">Username</p>
<input type="text" name="usrTxt" class="usrTxtField">
<p class="usr">Password</p>
<input type="password" name="password" class="usrTxtField">
<input type="submit" name="submit" value="Log In" class="submitLogIn">
<input type="checkbox" name="save" class="checkboxSave"><span class="saveText">Remember me</span>Forgot Your Password?
</form>
</div>
<div class="container2">
<img src="img/birdHouse.jpg" class="houseImg">
</div>
</div>
</body>
</html>
This happens because your android device screen has a height greater than 549px (considering your media query specifications). Naturally in landscape mode, this height becomes device width and hence your media query is ignored.
this is the media query you can target for almost all phones
/* phones (portrait and landscape) ----------- */
#media only screen and (min-width : 320px) {
/* Styles */
}
/* phones (portrait only) ----------- */
#media only screen and (max-width : 480px) {
/* Styles */
}
It is not possible to accomplish responsive design with only one media query. For making responsive design right, please visit and check this site, where media queries are explained and are examples on how to use it.
Android phone and iOS phone doesn't necessarily use the same width and height, most iOS phones uses width: 375px and height: 667px(or width: 667px and height: 375px when in landscape mode), although that is only for iPhone 6/7/8 excluding Plus and other models, you can check width/height which phone use which in Chrome/Mozzila Firefox/etc. in developer mode while emulating mobile devices.
Giving fixed width for DOM elements can mess up the view in small devices. particularly when the given width is not available as the device width goes less than that width.
So while writing media queries for smaller devices, say mobile phones, It would be great if you replace all the fixed widths to percentages. So that they will not overflow from the available space and will stay within the device width.
If you are having issues specifically for landscape, you can handle them using media query and orientation combination.
#media all and (max-width: 768px) and (orientation: landscape) {
}
Above code is enough for writing rules for small devices when used in landscape orientation.

How to set media queries for high resolution screens in html

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>

text-align/margin-left/etc. not working for my animated header

I have an animated header that is basically one stagnant word and preceeding it is a carousel of many words (in the same position) that fade in and out (thanks to animate.css). I followed a tutorial on youtube to get the basic webpage so it may look familiar or simple.
However, the preceeding words are stuck in complicated div's and headers to attempt to get multiple animations (enter and exit for each).
The problem is that when a long word comes onto the screen, it overlaps on the second word.
(Picture included)
To explain briefly, the button and text are all in a "display:table;" div and the words were normally just one cohesive sentence and worked fine. However, I've had to split them up and the only way to prevent them from being above/below one another (VERY annoying) was to force them to float left and right. However, when I delete the floats now (after much 'debugging') it doesnt seem to actually change the design, which greatly worries me. I have included my code. Please help! My idea right now is to make the text right aligned and relative to the second word, but everything I try seems to do absolutely nothing. If there are any other solutions I am all ears.
<section class="intro">
<div class="inner">
<div class="content">
<section style="clear: both">
<div style="position:absolute" z-index="1">
<h1 z-index="inherit"display="inline-block" class="os-animation" data-os-animation="fadeInDown" data-os-animation-delay="0s">
<div text-align="right" z-index="inherit" class="os-animation" data-os-animation="fadeOutDown" data-os-animation-delay="1s">Loving</div></h1>
</div>
<div style="position:absolute" margin-left="15%" z-index="2">
<h1 z-index="inherit" display="inline-block" class="os-animation" data-os-animation="fadeInDown" data-os-animation-delay="1s">
<div text-align="right" z-index="inherit" class="os-animation" data-os-animation="fadeOutDown" data-os-animation-delay="2s">Enjoying</div></h1>
</div>
<div style="position:absolute" z-index="3">
<h1 z-index="inherit" display="inline-block" class="os-animation" data-os-animation="fadeInDown" data-os-animation-delay="2s">
<div text-align="right" z-index="inherit" class="os-animation" data-os-animation="fadeOutDown" data-os-animation-delay="3s">Exploring</div></h1>
</div>
<h1 style="float: right">Irelnd</h1>
</section>
<section style="clear:both" class="os-animation" data-os-animation="fadeInUp" data-os-animation-delay="5s">
Get Started
</section>
</div>
</div>
</section>
css:
#import url('https://fonts.googleapis.com/css?family=Yantramanav:100');
#import url('https://fonts.googleapis.com/css?family=Montserrat:400');
html,body{
margin:0;
padding:0;
height:100%;
width:100%;
}
#carousel {
background-color: green;
text-align: center;
vertical-align: middle;
float: left;
}
#Dubai{
background-color: red;
}
.intro{
height:100%;
width:100%;
margin:auto;
background: url(https://static.pexels.com/photos/470641/pexels-photo-470641.jpeg) no-repeat ;
display: table;
top:0;
background-size:cover;
}
.intro .inner{
display: table-cell;
vertical-align:middle;
width: 100%;
}
.content{
max-width:480px;
margin: 0 auto;
text-align: center;
padding-bottom: 28%;
padding-left: 4%;
}
.content h1 {
font-family: 'Yantramanav', sans-serif;
font-size: 600%;
font-weight: 100;
color: #E1efe9;
line-height: 55%;
}
.btn {
font-family: 'Montserrat', sans-serif;
font-size: 135%;
font-weight: 400;
color: #3c4f1f;
text-transform: uppercase;
text-decoration: none;
border: solid #3c4f1f;
padding:10px 20px;
border-radius: 9px;
transition: all 0.3s;
}
.btn:hover{
color: #a0afa8;
border: solid #a0afa8;
}
p{
font-size: 150%;
line-height: 120%;
font-family: sans-serif;
}
/*--- Media Queries --*/
#media screen and (max-width: 900px) {
.content{
padding-bottom: 30%;
max-width: 320px;
}
.content h1{
font-size: 450%;
}
.btn{
font-size: 130%;
padding: 9px 15px;
}
}
#media screen and (max-width: 768px) {
.content{
padding-bottom: 40%;
max-width: 210px;
}
.content h1{
font-size: 300%;
}
.btn{
font-size: 110%;
padding: 9px 15px;
}
p{
font-size: 120%;
line-height: 100%;
}
}
#media screen and (max-width: 480px) {
.content{
padding-bottom: 50%;
max-width: 173px;
}
.content h1{
font-size: 250%;
}
.btn{
font-size: 90%;
padding: 4px 12px;
}
p{
font-size: 100%;
line-height: 100%;
}
}

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>

Resources