Limit div width and center - css

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

Related

how to center wordpress navigation

What would be the best way to center the navigation on this wordpress page:
tried this:
#media (min-width: 768px) {
.navbar-nav {
float: none;
padding: auto;
}
.nav {
padding-left: 10%;
}
}
from here: https://colorlib.com/wp/forums/topic/how-do-i-center-my-sites-navigation-bar/
but has absolute no affect
Thanks in advance.
Add this snippet in your style :
#media only screen and (min-width: 60.001em){
.main-navigation-menu>li {
float: none;
display: inline-block;
}
#menu-oberes-menue {
text-align: center;
}
.main-navigation-menu ul li{
text-align:left;
}
}
<div class="menu-wrap"> // need to add this div before ul
<ul id="menu-oberes-menue" class="main-navigation-menu">
{your menu list}
</ul>
</div>
Add your css
.menu-wrap {
display: table;
margin-left: auto;
margin-right: auto;
}

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>

Responsive navigation menu with hiding on small screens in pure CSS

I want to create a simple navigation menu with a special feature:
On a desktop browser it shows as a bar like "item1 | item2 | item3"
On a mobile browser it shows a button. When tapping on it, it shows the menu as stack
I'm searching a solution without Javascript. I know about media queries in CSS but I don't know how to add a menu with this requirement.
This is the menu for example:
<nav>
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
</nav>
CSS:
/* default for all browsers */
nav>ul {
padding: 0;
margin: 0;
list-style: none;
background-color: #3d3d3d;
}
nav>ul>li>a {
display: block;
color: #ffffff;
}
#media only screen and (max-width: 360px) {
/* mobile */
/* WHAT NOW? */
}
#media only screen and (min-width: 361px) {
nav>ul>li {
/* bar layout */
display: inline-block;
}
}
fiddle: https://jsfiddle.net/1fg4qkx5/
i have edited your jsfiddle and found a rather "Simple" solution for you,
jsfiddle
I have not (yet) found a way to do this completely without javascript to catch the button click.
to post out the results here:
HTML
<nav>
<button class='hide-lg right'>
☰
</button>
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
css
/* default for all browsers */
*{
margin: 0;
padding: 0;
}
body{
min-width: 100%;
min-height: 100%;
}
button{
border:1px solid gray;
background-color: transparent;
display: inline-block;
}
.show{
display: inline-block;
}
.right{
float:right;
}
nav{
background-color: #3d3d3d !important;
color: #ffffff;
height:auto;
width: 100%;
display: block;
}
nav>ul {
padding: 0;
margin: 0;
list-style: none;
background-color: #3d3d3d;
}
nav>ul>li>a {
display: block;
color: #ffffff;
}
#media only screen and (max-width: 360px) {
.hide-lg{
display:inline-block;
}
ul{
display: none;
}
/* mobile */
/* WHAT NOW? */
}
#media only screen and (min-width: 361px) {
.hide-lg{
display: none !important;
}
nav>ul{
display: block;
}
nav>ul>li {
/* bar layout */
display: inline-block;
}
nav>ul>li>a{
display: block;
width:100%;
height: 100%;
}
}
Javascript/jQuery
$(document).ready(function(){
$('button').click(function(){
$('ul').toggleClass('show');
});
});
I hope you find my answer helpfull,
Giovanni

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.

Resources