How to fix this horizontal scroll bar issue? - css

On my main Mac machine (firefox, safari and chrome) my code tags “box” renders normally:
But, on my Windows (chrome/firefox, with different screen res) it shows this empty horizontal scroll bar:
I want the scroll bar to only show up when needed, like on Mac. I'm using this Hugo theme (live demo). Here’s my slightly modded .css (stripped of all colors and unimportant parts):
/* General Page Layout */
body {
margin: 0;
line-height: 1.5;
font-size: 100%;
font-family: 'Source Code Pro', monospace;
}
.container {
max-width: 52em;
margin-left: auto;
margin-right: auto;
}
div.right {
float:right;
}
div.clearfix {
overflow: auto;
}
#media (max-width: 52em) {
.container {
width: 100%;
}
}
article.single section,
.article-list article {
padding-left: 4rem;
padding-right: 4rem;
padding-top: 1rem;
padding-bottom: 1rem;
}
#media (max-width: 52em) {
article.single section,
.article-list article {
padding-left: 2rem;
padding-right: 2rem;
}
}
header, footer {
padding-top: 1rem;
padding-bottom: 1rem;
}
header {
margin-top: 1rem;
margin-bottom: 2rem;
}
#media (max-width: 52em) {
header {
margin-top: 0;
padding-left: 2rem;
padding-right: 2rem;
}
}
footer {
margin-top: 2rem;
margin-bottom: 1rem;
text-align: center;
font-size: 0.9em;
}
#media (max-width: 52em) {
footer {
margin-top: 0;
margin-bottom: 0;
}
}
/* Typography */
h1, h2, h3, h4, h5, h6 {
font-weight: bold;
line-height: 1.25;
margin-top: 1em;
margin-bottom: .5em;
}
p {
margin-top: 0;
margin-bottom: 1rem;
}
h1 { font-size: 2rem }
h2 { font-size: 1.5rem }
h3 { font-size: 1.25rem }
h4 { font-size: 1rem }
h5 { font-size: .875rem }
h6 { font-size: .75rem }
#font-face {
font-family: 'Input';
src: url('/font/Input-Regular.woff2') format('woff2'),
url('/font/Input-Regular.woff') format('woff');
font-weight: normal;
font-style: normal;
font-display: swap;
}
pre, code {
font-family: 'Input', monospace;
font-size: inherit;
}
/* Homepage Layout */
#media (max-width: 52em) {
.homepage {
margin-bottom: 2rem;
}
}
.homepage h1.site-title {
text-align: center;
font-size: 5em;
}
#media (max-width: 52em) {
.homepage h1.site-title {
font-size: 3em;
}
}
.homepage h1.headline {
font-size: 3em;
}
#media (max-width: 52em) {
.homepage h1.headline {
padding-left: 2rem;
padding-right: 2rem;
}
}
.homepage .hero-logo img {
width: 100%;
}
.homepage section.categories,
.homepage section.tags {
padding-left: 2rem;
padding-right: 2rem;
}
.homepage .tag {
margin-right: 2em;
}
/* Post List Layout */
.article-list h1.list-title {
font-size: 3em;
}
.article-list article {
padding-top: 4rem;
padding-bottom: 4rem;
margin-bottom: 4rem;
}
.article-list article h2.headline,
.article-list article h2.headline a {
margin-top: 0;
}
.article-list article .meta {
margin-bottom: 1rem;
}
/* Single Post Layout */
article.single .meta {
font-size: 0.9em;
text-align: right;
}
#media (max-width: 52em) {
article.single .meta {
padding-left: 2rem;
padding-right: 2rem;
}
}
article.single h1.headline {
margin-top: 0;
font-size: 3em;
}
#media (max-width: 52em) {
article.single h1.headline {
padding-left: 2rem;
padding-right: 2rem;
}
}
article.single section.body {
padding-top: 4rem;
padding-bottom: 3rem;
}
#media (max-width: 52em) {
article.single section.body {
padding-top: 2rem;
padding-bottom: 1rem;
}
}
/* Article Elements */
article.single * {
max-width: 100%;
}
article.single pre {
margin-top: 0;
margin-bottom: 1rem;
overflow-x: scroll;
border-radius: 3px;
padding: 2rem;
}
article.single ul code, ol code, p code {
padding: 0em 0.1em;
border-radius: 3px;
}
article.single figure, article.single div.highlight {
box-sizing: border-box;
max-width: 46rem;
width: 46rem;
margin-left: -1rem;
margin-right: 0rem;
margin-bottom: 1rem;
padding-left: 1em;
padding-right: 1em;
padding-top: 1em;
padding-bottom: 0.1em;
}
#media (max-width: 52em) {
article.single figure, article.single div.highlight {
width: 100%;
margin-left: 0;
margin-right: 0;
border-radius: 3px;
}
}

You can try :
pre, code {
font-family: 'Input', monospace;
font-size: inherit;
overflow: auto;
}

Solved by changing overflow-x from scroll to auto in article.single pre.

For me, it happened when I set the direction attribute rtl in <body> tag,
although there's no overflow on default mode (ltr), however, I set the dir attribute for the main div tag under the body, like the following:
<body dir="rtl">
<div>
... <!-- few pixels horizontal overflow -->
</div>
</body>
so the worked solution for me was:
<body>
<div dir="rtl">
... <!-- No horizontal overflow -->
</div>
</body>

It could be resolved as followed.
Please set also for all viewport breakpoints the desired width: % of the .container class.

Related

why max-width in media query is not working

I wrote this piece of code but it's not working
#media (max-width: 767px){
.navbar-brand {
padding-top: 10px;
height: 80px;
}
.navbar-brand h1{
padding-top: 10px;
font-size: 5vw;
}
.navbar-brand p {
font-size: .6em;
margin-top: 12px;
}
.navbar-brand p img {
height: 20px ;
}
#collapsable-nav a {
font-size: 1.2em;
}
#collapsable-nav a span{
font-size: 1em;
}
}
I want to change my navbar when the screen is smaller than 767px but it doesn't work at all.
use min-width instead of using max-width
#media (min-width: 767px) {
.navbar-brand {
padding-top: 10px;
height: 80px;
}
.navbar-brand h1{
padding-top: 10px;
font-size: 5vw;
}
.navbar-brand p {
font-size: .6em;
margin-top: 12px;
}
.navbar-brand p img {
height: 20px;
}
#collapsable-nav a {
font-size: 1.2em;
}
#collapsable-nav a span{
font-size: 1em;
}
}
Visit the following link to understand more about min-widht in css:
https://www.w3schools.com/cssref/playdemo.php?filename=playcss_min-width
You should probably use min-width for your media query in this case. Please read how to ask a proper question and update your question so we can better help you?

Image/banner not showing in phones

My coding knowledge is next to none but I have been getting by ok with the use of Joomla and preset templates etc. But now I've hit the brick wall head first. While the two banners (right and bottom) are displayed correctly on desktops and tablets, only bottom one is displayed on phones.
Here's the site: http://www.chokladsajten.com
How do I get both to be displayed on smaller screens? (A bonus would of course be if they also were responsive.) Any help or ideas are appreciated!
Custom.css:
#font-face {
font-family: 'DroidSerifBoldItalic';
src: url('../fonts/DroidSerif-BoldItalic-webfont.eot');
src: url('../fonts/DroidSerif-BoldItalic-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/DroidSerif-BoldItalic-webfont.woff') format('woff'),
url('../fonts/DroidSerif-BoldItalic-webfont.ttf') format('truetype'),
url('../fonts/DroidSerif-BoldItalic-webfont.svg#DroidSerifBoldItalic') format('svg');
font-weight: normal;
font-style: normal;
}
/* Logo */
.custom-logo {
width: 104px;
height: 70px;
background-image: url(../../../images/yootheme/logo.png);
background-position: 0 0;
background-repeat: no-repeat;
background-size: contain;
}
/* Only Phones */
#media (max-width: 767px) {
#header-responsive .logo { margin-bottom: 10px; }
}
/* Parallax Effect */
.box-parallax { background-image:
url(../../../images/yootheme/demo/teaser/home_teaser_default.jpg); }
.box-parallax h1 { font-family: "DroidSerifBoldItalic", "TimesNewRoman",
"serif"; }
/* Frontpage Title */
.bigger-title {
margin-top: 0;
margin-bottom: 10px;
font-size: 24px;
line-height: 24px;
}
/* Frontpage List Line */
ul.line.frontpage > li {
margin-top: 30px;
padding-top: 30px;
}
ul.line.frontpage > li:first-child {
margin-top: 0;
padding-top: 0;
}
/* Only Tablets (Portrait) */
#media (min-width: 768px) and (max-width: 959px) {
.frontpage-teaser { height: 280px; }
.frontpage-teaser h2 {
margin-bottom: 0;
line-height: 75px;
font-size: 68px;
}
.frontpage-teaser h4 {
line-height: 28px;
font-size: 23px;
}
}
/* only phones */
#media (max-width: 767px) {
.frontpage-teaser { height: 150px; }
.frontpage-teaser h2 {
margin-top: 10px;
margin-bottom: 0;
line-height: 50px;
font-size: 40px;
}
.frontpage-teaser h4 {
margin-top: 0;
font-size: 12px;
line-height: 16px;
}
}
#banner {
position: absolute;
top: 0;
right: -230px;
}
#footer {
position: center;
bottom: 30px;
}
}
You can specify custom styles for the 1220px breakpoint like this:
#media (max-width: 1220px) {
#banner {
display: block;
position: static;
margin-top: 1.5em;
text-align: center;
}
.bannerItem img {
width: 100%;
height: 150px;
}
}
In your current version, for this breakpoint #banner have a property display: none;, therefore it fades away once the window's width exceeds 1220px

Media Queries-Why is the css code that sould be executed not excuting

So here is the css code and when i go to developer tools (Mozila) the code isn`t executed in responisve mode as it should.
The margin-left:auto; is underlined as u can see in the picture that i uploaded.
I am new to responsive design.If you wanna see the whole project(page) click here, please help.
Developer tools image
#media screen and (max-width: 750px) {
img {
margin-left: auto;
}
}
body {
margin: 0;
overflow: auto;
background-color: #a6a6a6;
}
img {
margin-left: 40%;
}
p {
text-align: center;
font-size: 1.2em;
}
ul {
font-size: 1.3em;
margin-left: 15%;
margin-right: 15%;
}
small {
text-align: center;
margin-left: 45%;
}
hr {
display: block;
height: 1em;
border: 0;
border-top: 0.1em solid #4d4d4d;
margin-right: 10%;
margin-left: 10%;
padding: 0;
}
#title {
float: left;
text-align: center;
background-color: #cccccc;
width: 100%;
top: 0;
position: fixed;
margin-left: 0;
font-size: 1.25em;
}
#content {
background-color: #e6e6e6;
margin-left: 5%;
margin-top: 10%;
margin-right: 5%;
margin-bottom: 6%;
}
#e {
font-size: 2em;
}
#timeline {
font-size: 1.5em;
}
#sources {
font-size: 1.8em;
}
#Author {
font-size: 1.6em;
}
a {
cursor: pointer;
text-decoration: none;
}
a:visited {
cursor: pointer;
text-decoration: none;
color: blue;
}
a:hover {
cursor: pointer;
text-decoration: none;
}
Order of declarations in CSS matters. Move the media query BELOW the img { margin-left:40%; } and it should work.
The media queries you see in style sheets tend to be better placed at the bottom. Place
#media screen and (max-width:750px){
img{
margin-left:auto;
}
}
underneath the last CSS declaration

How can I get my sass landing page working on codepen?

there are three files in three pens here, I've tried linking them all together but it still doesn't work. I'd appreciate the help thanks.
#import "reset";
#import "variables";
#import "mixins";
#main-nav{
background: $deepBlue;
ul{
width: 100%;
}
li{
float: left;
width: (100% / 6);
#include mQ(600px){
width: 100%;
}
}
a{
color: $offWhite;
text-decoration: none;
padding: 16px;
display: block;
text-align: center;
&:hover{
background: lighten($deepBlue, 6);
}
}
#include clearFix;
}
section h1{
margin: 40px 0;
text-align: center;
text-transform: uppercase;
color: $deepBlue;
font-size: $sectionHeading;
}
#services{
li{
float: left;
width: 33.33%;
box-sizing: border-box;
text-align: center;
}
img{
width: 60%;
margin: 20px 20%;
}
a{
text-decoration: none;
color: $deepBlue;
font-weight: bold;
&:hover{
color: complement($deepBlue);
}
}
#include clearFix;
margin-bottom: 60px;
}
.lead-banner{
#include banner;
text-align: right;
}
.lessons-banner{
#include banner;
text-align: left;
li{
text-transform: uppercase;
font-size: 20px;
max-width: 500px;
margin: 60px 0;
}
}
#projects li{
#include grid(6, 2%);
img{
width: 100%;
}
}
Here is the variables.sccs file
$deepBlue: #032f3e;
$sectionHeading: 28px;
$offWhite: #f8f9fb;
$bannerHeading: 46px;
here is the
reset.scss file
body {font-family: arial; background: #f8f9fb}
html, body, ul, ol, li, form, fieldset, legend
{
margin: 0;
padding: 0;
}
h1, h2, h3, h4, h5, h6, p { margin-top: 0; }
fieldset,img { border: 0; }
li { list-style: none; }
.wrapper{
width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
box-sizing: border-box;
}
here is the compiled code
#mixin banner{
width: 100%;
position: relative;
color: white;
.banner-content{
position: absolute;
top: 50px;
width: 100%;
}
img{
width: 100%;
}
span{
font-size: $bannerHeading;
display: block;
text-transform: uppercase;
font-weight: bold;
#include mQ(3000px, 1200px){
font-size: 68px;
}
}
span.sub-title{
font-weight: normal;
margin-bottom: 30px;
}
#include mQ(1200px){
max-height: 640px;
overflow: hidden;
}
}
#mixin clearFix{
&:after{
content: "";
display: block;
clear: both;
}
}
#mixin grid($cols, $mgn){
float: left;
width: ((100% - (($cols - 1) * $mgn)) / $cols );
margin-right: $mgn;
margin-bottom: $mgn;
&:nth-child(#{$cols}n){
margin-right: 0;
}
}
#mixin mQ($args...){
#if length($args) == 1{
#media screen and (max-width: nth($args, 1)){
#content;
}
}
#if length($args) == 2{
#media screen and (max-width: nth($args, 1)) and (min-width: nth($args, 2)){
#content;
}
}
}
Here is the link to my pen
https://codepen.io/nezmustafa123/pen/OpEBov
you have to import your files in the settings of codepen and then the codepen import it

same class looks different on different pages

I'm trying to figure out what's wrong with my responsive website.
On a desktop it looks fine, but when you view the mobile version, the class ".game-box" looks fine on the main page, but on other pages the text inside that class looks tiny.
I coded the styles in SCSS. Here is the full code:
/* MIXIINS */
#mixin hFonts($font-size, $device-font-size) {
font-size: $font-size;
font-family: $font-serif;
color: $font-color-med;
#media screen and (max-device-width: $media-mobile-med) {
font-size: $device-font-size;
}
}
/* FONTS */
#import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro");
#import url("https://fonts.googleapis.com/css?family=Alegreya:700");
$font-serif: 'Alegreya', serif;
$font-sans: 'Source Sans Pro', sans-serif;
$font-color-dark: #222;
$font-color-med: #444;
$font-color-light: white;
$font-size-small: 12px;
$font-size-med: 16px;
$font-size-large: 24px;
$font-size-xl: 32px;
$font-size-xxl: 48px;
$font-size-nav: 19px;
/* COLORS & BACKGROUNDS */
#import 'gradient';
$websiteBackground: #343434 url("/img/footer_lodyas.png");
$navBackground: #505050 url("/img/tweed.png");
$contentBackgroundColor: ghostwhite;
$sidebarColor: ghostwhite - #111;
/* VARIABLES */
$headerHeight: 150px;
$navHeight: $headerHeight - 90px;
$imgPosition: $headerHeight - 184px;
$titlePosition: ($headerHeight - $navHeight) / 2 - 18px;
$foot-height: 90px;
$sidebarWidth: 300px;
$gutter: 10px;
$media-narrow: 845px;
$media-mobile-small: 640px;
$media-mobile-med: 720px;
$media-mobile-large: 1080px;
/* RESET */
%reset { margin: 0; padding: 0; }
html, body {#extend %reset; background: $websiteBackground; height: 100%;}
div {#extend %reset;}
h1 { #include hFonts($font-size-large, $font-size-xxl); }
h2 { #include hFonts($font-size-med, $font-size-xl); }
p, li, a, q, blockquote { font-family: $font-sans; color: $font-color-med;}
/* CLASSES */
.container { padding: 0 $gutter; }
.light-text { color: $font-color-light; }
.link-inactive { text-decoration: line-through; }
.game-box {
font-family: $font-sans;
float: left;
width: calc(33% - 2 * #{$gutter});
min-height: 300px;
margin: $gutter; padding: 0;
border: 1px solid blue;
border-radius: $gutter / 2;
overflow: hidden;
box-shadow: 1px 1px $gutter / 2 0 black;
background-color: white;
.box-title {
padding: $gutter;
color: $font-color-light;
#extend .blueGradient;
}
.box-description {
padding: 0 $gutter;
}
#media screen and (max-device-width: $media-mobile-med) {
margin: 2 * $gutter;
width: calc(100% - 4 * #{$gutter});
font-size: $font-size-large;
}
}
.top-image {
background: {
position: center center;
size: cover;
repeat: no-repeat;
}
width: 100%; height: 360px;
float: right;
&--main {
#extend .top-image;
background-image: URL("/img/epicFrontPage.png");
height: 500px;
}
&--syshack {
#extend .top-image;
background-image: URL('/img/SysHackGamePhoto.png');
}
}
.quarter-image {
float: right;
width: calc(25%);
}
/* ELEMENTS & ID'S */
#wrapper {
max-width: 1080px; width:100%; min-width:720px;
height: 100%;
margin: 0 auto;
}
header {
float: left;
width: 100%; height: $headerHeight;
#extend .blueGradient;
nav {
background: $navBackground;
height: $navHeight;
}
h1 {
display: inline-block;
color: $font-color-light;
margin-top: $titlePosition;
margin-left: 290px;
font-size: $font-size-xl;
#media screen and (max-device-width: $media-mobile-med) {
margin-top: 15px;
font-size: $font-size-xxl;
}
}
#teg-brain {
position: absolute;
top: $imgPosition;
}
}
#nav-menu {
float: right;
margin: 0; padding: 0;
li {
display: inline-block;
#extend %reset;
color: $font-color-light;
text-decoration: none;
font-size: $font-size-nav;
a {
display: inline-block;
color: inherit;
text-decoration: inherit;
font-size: inherit;
padding: 18px $gutter;
#media screen and (max-device-width: $media-mobile-med) {
padding: 10px $gutter;
}
}
& > ul.submenu {
position: absolute;
top: $navHeight;
//margin-left: 22px;
padding-left: 0;
display: none;
z-index: 10;
li {
background-color: rgb(64,64,64);
display: block;
a { display: block; padding: 18px $gutter; }
&:hover {
background-color: rgb(128,128,128);
}
}
#media screen and (max-device-width: $media-mobile-med) {
margin-left: 51px;
}
}
&:hover {
background-color: rgba(255,255,255,.2);
& ul.submenu {
display: block;
}
}
#media screen and (max-device-width: $media-mobile-med) {
font-size: $font-size-xl;
// padding: 9px $gutter;
}
}
}
#main {
float: left;
width: 100%;
background-color: $contentBackgroundColor;
min-height: calc(100% - #{$headerHeight} );
//overflow-y: auto;
//overflow-x: hidden;
}
#latest-news {
font-size: 16px;
float: left;
width: calc(100% - 2 * #{$gutter});
#media screen and (max-device-width: $media-mobile-med) {
font-size: $font-size-large;
}
}
#BMG-meetup {
margin: $gutter;
#media screen and (max-device-width: $media-mobile-med) {
display: none;
}
}
blockquote {
background-color: $contentBackgroundColor - #111;
border-left: $gutter solid #{$contentBackgroundColor - #333};
margin: 1.5em $gutter;
padding: 0.5em $gutter;
quotes: "\201C""\201D";
&:before {
color: $font-color-med;
content: open-quote;
font-size: 4em;
line-height: 0.1em;
margin-right: 0.25em;
vertical-align: -0.4em;
}
p { display: inline; }
}
/*
#sidebar {
float: left;
background-color: $sidebarColor;
width: $sidebarWidth - 2 * $gutter;
min-height: calc(100% - #{$headerHeight} );
}
*/
#mc_embed_signup {
float: right;
width: $sidebarWidth;
font:14px Helvetica,Arial,sans-serif;
#media screen and (max-width: $media-narrow) {
display: none;
}
}
#mc_embed_signup input.button { display: inline-block; }
#mc_embed_signup input.email { display: inline-block; }
I changed the font size to 2em in this media query and it seems to look better.
#media screen and (max-device-width: 720px)
.game-box, .game-box--right {
margin: 20px;
width: calc(100% - 4 * 10px);
font-size: 2em;
}

Resources