I'm trying to create a responsive layout, but for some reason, when I wrap the relevant CSS in a media query, it isn't recognized: i.e., if I resize my browser window or check it out on my iPhone, the CSS is not applied. I'm not sure what I'm doing wrong here. Here is the relevant code (note that I'm working with the Types plugin within WordPress, hence all the bracketed stuff):
HTML
<div class="client-stats">
<h3>Stats</h3>
<p><strong>Event Date:</strong> [types field="date-of-event" style="text" format="F j, Y"][/types] </p>
<p><strong>Event Type:</strong> [types field="event-type"][/types]</p>
<p><strong>Special Effects:</strong> [types field="special-effects"][/types]
<p><strong>Equipment Used:</strong> [types field="equipment-used"][/types]</p>
</div>
<div class="client-description">
<div class="portfolio-description">
[wpv-post-body view_template='None']
</div>
</div>
CSS
.client-stats {
width: 325px;
float: left;
margin-right: 15px;
padding: 0 7px 0 35px;
background-color: #333;
background-image: url('/wp-content/uploads/2016/05/paper-1.jpg');
min-height: 350px;
line-height: 1.5;
color: #fff;
}
.client-stats p, strong, h3 {
font-family: "Courier New",monospace;
}
.client-stats h3 {
text-transform: uppercase;
margin-bottom: 20px;
color: #fff;
}
.client-stats strong {
text-decoration: underline;
font-family: "Courier New",monospace;
}
.client-description {
margin-left: 350px;
}
#media only screen and (max-width: 768) {
.client-stats {
width: 100%;
float: none;
margin-right: 0;
}
.client-description {
width: 100%;
margin-left:0;
}
}
If I remove the media query wrap, the CSS is applied fine (so it's not the CSS rules, specifically that are the problem).
The relevant page is here, if that helps: http://107.170.41.117/client/client-6/
#media only screen and (max-width: 768) {
CSS lengths require units. 768 is not a valid width.
This would have been picked up if you had used a validator.
Related
I have this div named "container" that is supposed to be displayed when the max-width gets to 47em. This can be triggered through zooming in. It's initial display is none but in the media query i change it to display block. The problem is that even after zooming in enough to get the max-width to become 47em, it's still not displaying anything. Why is this and how can i go about fixing the problem?
Code: http://codepen.io/anon/pen/RWBJXv
html,
body {
height: 100%;
margin: 0px;
font-family: verdana, arial, helvetica, sans-serif;
}
#media (max-width: 47em) {
#container {
display: block;
}
}
div#container {
display:none;
}
div#nav {
position: relative;
width: 100%;
background: white;
box-shadow: 1px 1px 15px #888888;
}
div#logo {
border-right-style: solid;
border-width: 1px;
border-color: rgba(0, 0, 0, 0.15);
font-family: 'Myriad Pro Regular';
font-weight: normal;
color: #1E3264;
font-size: 2em;
}
<body>
<div id="container">
<div id="nav">
<div id="logo">TEST</div>
</div>
</div>
Your code has several problems:
First of all, div#container is a css selector with a higher specificity than #container, which you are using inside your media query, so the general rule takes precedence.
Second, make sure you always put your media-queried rules after your general rules.
http://codepen.io/anon/pen/zvLLPa
Seems to be an order & specificity issue.
Try changing this
#media (max-width: 47em) {
#container {
display: block;
}
}
div#container {
display:none;
}
to this:
#container {
display:none;
}
#media (max-width: 47em) {
#container {
display: block;
}
}
Codepen Demo
If you swap around your media query with your general css, and add an important tag this sorts out your issue example:
#container {
display:none;
}
#media (max-width: 47em) {
#container {
display: block;
}
}
Check out this codepen: http://codepen.io/sshhdaniella/pen/EVppwR
I have this site:
http://dl.dg-site.com/functionmentes/
This is code CSS:
#media screen and (width:1024px)
{
#titlu_footer
{
margin-left:90px;
}
}
I tried to add this code but not working.
What is wrong?
In your media query change width to min-width or max-width
Additional problem
This is currently your CSS for #titlu_footer
.page-id-1637 #titlu_footer {
color: #264572;
font-family: muli, sans-serif;
letter-spacing: 2px;
line-height: 1.4;
font-weight: 400;
margin-left: 302px;
margin-top: 30px;
padding-top: 20px;
}
If you look using chrome/firefox developer tools you'll see that margin-left 302px is taking precedence over your media queries.
I am really struggling to find what is making the grey space at the bottom of my site. This is the first time I have attempted any coding so any simply put answers would be greatly appreciated. I am sure there are numerous errors in the code / conflicting codes but
I have also been trying media queries which may also be making stuff go wrong? Any help would be really well received... Here is the code so far...
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Your Website</title>
<style>
a:link {
text-decoration: none;
font-family: "georgia";
font-style: normal;
font-size: 20px;
font-weight:lighter;
color: #7a5131;
}
a:visited {
text-decoration: none;
font-family: "georgia";
font-style: normal;
font-weight:lighter;
color: #7a5131;
}
a:hover {
text-decoration: none;
font-style: normal;
font-family: "georgia";
font-weight:lighter;
color: #c57b43;
}
a:active {
text-decoration: none;
font-style: normal;
font-family: "georgia";
font-weight:lighter;
color: #7a5131;
}
* {
padding: 0px;
margin: 0px;
margin-top: -5px;
}
#footer {
position: fixed;
clear: both;
width: 104%;
height: 30px;
bottom: 0;
border: none;
padding: 13px 0 0 0;
text-align:
center; color: #ffffff;
background-color: #ffffff; }
body {
background-color:grey;
height: auto;
background-size: 100% 100%\9
}
}
#container {
width: 100%;
height: auto;
color:blue;
margin-left:0;
padding-left: 0;
margin-top: 0;
padding-top: 0;
position: absolute;
}
#nav {
width: 100%;
height: 100%;
text-align: center;
margin-left:0;
padding-left: 0;
padding-top: 0px;
height: 100px;
font-family: "georgia";
font-weight:lighter;
color: #7a5131;
font-size: 20px;
word-spacing: 20px;
float:left;
}
navtype {
position: absolute;
top: 60px;
left: 0;
width: 100%;
font-family: "georgia";
font-weight:lighter;
color: #7a5131;
font-size: 20px;
word-spacing: 20px;
}
#images {
position: relative;
width:100%; /* you can use % */
height: auto;
font-family: "georgia";
font-weight:lighter;
color: #7a5131;
font-size: 20px;
top: 0px;
}
#fullscreen {
position: relative;
width:100%; /* you can use % */
height: auto;
margin-left: auto;
margin-right: auto;
padding-top: 40px;
padding-bottom: 0px;
min-width: 50%;
text-align: center;
}
#test {
position: absolute;
width:100%; /* you can use % */
height: auto;
margin-left: auto;
margin-right: auto;
min-width: 50%;
text-align: center;
background-size: 100%;
background-position: top center;
background-repeat: no-repeat;
display: block;
}
#ourstory {
position: relative;
width:100%; /* you can use % */
height: auto;
margin-left: auto;
margin-right: auto;
padding-top: 40px;
padding-bottom: 50px;
min-width: 50%;
text-align: center;
background-image: url("/Users/DESIGNHAPPY04/Desktop/NEW
SCROLL DOWNSITE/images/storyback.jpg" );
background-size: 100%;
}
#type {
position: relative;
margin-left: 15%;
margin-right: auto;
max-width: 70%;
font-family: "georgia";
font-style: italic;
font-weight:lighter;
color: #5f4029;
line-height: 180%;
font-size: 15px;
}
#media all and (min-width: 601px) {
#test {background-image:url("/Users/DESIGNHAPPY04/Desktop/NEW
SCROLL DOWN SITE/images/breaker.jpg" );
width:100%;height:100%;
}
}
#media all and (max-width: 600px) {
#test {background-image:url("/Users/DESIGNHAPPY04/Desktop/NEW
SCROLL DOWN SITE/images/breakermobile.jpg" );width:100%;height:100%;
}
#type {
position: relative;
margin-left: 15%;
margin-right: auto;
max-width: 70%;
font-family: "georgia";
font-style: italic;
font-weight:lighter;
color: #5f4029;
line-height: 180%;
font-size: 10px;
}
a:link {
text-decoration: none;
font-family: "georgia";
font-style: normal;
font-size: 13px;
font-weight:lighter;
color: #7a5131;
}
a:visited {
text-decoration: none;
font-family: "georgia";
font-style: normal;
font-weight:lighter;
color: #7a5131;
}
a:hover {
text-decoration: none;
font-style: normal;
font-family: "georgia";
font-weight:lighter;
color: #c57b43;
}
a:active {
text-decoration: none;
font-style: normal;
font-family: "georgia";
font-weight:lighter;
color: #7a5131;
}
* {
padding: 0px;
margin: 0px;
margin-top: -5px;
}
#nav {
width: 100%;
text-align: center;
margin-left:0;
padding-left: 0;
padding-top: 0px;
height: 60px;
font-family: "georgia";
font-weight:lighter;
color: #7a5131;
font-size: 20px;
word-spacing: 20px;
position:relative;
}
navtype {
position: absolute;
top: 30px;
left: 0;
width: 100%;
font-family: "georgia";
font-weight:lighter;
color: #7a5131;
font-size: 20px;
word-spacing: 20px;
}
}
</style>
</head>
<body>
<div id="container">
<div id="nav">
<navtype><span>
Story
Testimonial
Recipes
Spreads
</span></navtype>
<a name="top"></a>
<img src="/Users/DESIGNHAPPY04/Desktop/NEW SCROLL DOWN SITE/ images/headerbar.jpg"
alt="HTML5 Icon"style="width:100%;height:100%">
</div>
<div id="images">
<img src="/Users/DESIGNHAPPY04/Desktop/NEW SCROLL DOWN SITE/ images/landscape.jpg"
alt="HTML5 Icon"style="width:100%;height:100%">
</div>
<div id="ourstory">
<a name="storyanchor"></a>
<div id="images">
<img src="/Users/DESIGNHAPPY04/Desktop/NEW SCROLL DOWN SITE/ images/storypics.png"
alt="HTML5 Icon"style="width:100%;height:100%">
</div>
<div id="type">
How it all began
<br>
The emergence and growth of blogs in the late 1990s coincided with the advent o
web publishing tools that facilitated the posting of content by non tec
(Previously, a knowledge of such technologies as HTML and FTpu Indeed, bloggers do not only produce content to post on theirblogs, but also build social relations
<br><br>
Click Here For More Recipe ideas
</div>
</div>
<a name="testimonial"></a>
<img src="/Users/DESIGNHAPPY04/Desktop/NEW SCROLL DOWN SITE/images/breaker.jpg"
alt="HTML5 Icon"style="width:100%;height:100%">
</div>
<div id="ourstory">
<a name="ourspreads"></a>
<div id="images">
<img src="/Users/DESIGNHAPPY04/Desktop/NEW SCROLL DOWN SITE/ images/jars.png"
alt="HTML5 Icon"style="width:100%;height:100%">
</div>
<div id="type">
Our Spreads and Jams
<br>
The emergence and growth of blogs in the late 1990s coincided with the advent of ` web publishing tools that facilitated the posting of content by non-technical users. (Previously, a knowledge of such technologies as HTML and FTP had been required to publish ;content on the Web.)Indeed, bloggers do not only produce content to post on their blogs, but also build social relations
</div>
<div id="fullscreen">
<a name="recipes"></a>
<div id="images">
<img src="/Users/DESIGNHAPPY04/Desktop/NEW SCROLL DOWN SITE/ images/recipes.jpg"
alt="HTML5 Icon"style="width:100%;height:100%">
</div>
</div>
<div id="test">
</div>
</div>
<div id="footer">
Back to top</p>
</div> <!--END OFCONTAINER browser-->
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="/Users/DESIGNHAPPY04/Desktop/NEW SCROLL DOWN SITE/java/smoothscroll.js"></script>
</body>
</html>
Congratulations on coding your own site. Here are some things that could be causing the odd gap:
Two default CSS styles that will effect spacing
Small space under an image, and this may be your bug. One quick fix is to change the image to display:block;. Another solution is to use vertical-align: bottom;, as demonstrated in this easy article: http://salman-w.blogspot.com/2012/10/remove-space-below-images-and-inline-block-elements.html
Margin Collapse happens when a top or bottom margin from one html element (divs, headings...) touch another without a border, padding or anything else in-between. One margin is deleted or the margins are added together, and will only be applied to one element. Please see this article for more info: http://www.sitepoint.com/web-foundations/collapsing-margins/
Potential problems within your code:
As Sable Foste suggested, run your code through the validator, and concentrate on the code errors. (You may not be able to fix everything the validator suggests.) Remember to fix the errors mentioned in the comments above, along with fixing the missing opening <p> tag in the footer, and removing the extra closing brackets } in the css under the body and navtype. Add the additional media query closing brackets } (they need 2: one for the actual style and one to close the media query). Remember to fix * {padding: 0px; margin:0px; margin-top:-5px;} by removing the margin-top:-5px, and assign this only to the styles that need a -5px top margin. These may seem trivial, but coding errors can wreak havoc on your layout.
It looks like your using <div id="test"> at the bottom to test the media queries. What you can do is use #test {display:none;} to hide the div in the regular css, and turn it back on by adding #test {display:block;} in the media queries. This may help you see if the test div is causing problems.
You asked about using a code snippet. Since this is an entire web page, perhaps a JSFiddle would be helpful.
JSFiddle Tutorial - this site lets you paste your html, css, and scripts in a separate, editable environment. It then displays the results in a small browser window. You can paste the link, and we can troubleshoot and demonstrate the fixes in a real environment. For example, the code you supplied does not show your problem, but if you had it in a JSFiddle, we could see the issue, help troubleshoot it, and offer a real example solution. If you have a JSFiddle example, people are more willing to help.
Useful Info
Developer Tools - learn how to use the built in developer tools in your browser because it'll be your best friend when troubleshooting your site. (Like the rest of us, this won't be your last bug). You can view your html and css code, and it has the added benefit of being able to turn off and even delete html elements and css styles. This helps to quickly find the offending element. It is safe to make edits in this environment because the changes are in the browser, and will not change your real code. Hit F12 in your browser to open developer tools, then use the little arrow and mouse over your elements in the browser window, and the code that displays below. Right click on the element to see more options. You can use Firefox with the downloadable Firebug extensions. This lets you edit the html and css. Lots of people like Chrome's developer tools, and you are in luck because CodeSchool offers a fun, free and easy course. It'll be well worth your time to take this because in the time it takes you to troubleshoot one bug, you could have finished this course.
When using this site, upvote the comments and answers that are helpful, and accept the answer that solves your problem. Upvoting and accepting builds your reputation and shows you are an active participant with your own questions, it builds the reputation of the people that answer your questions, and it builds the reputation of the question. If you find your own solution, it's helpful to post the fix.
Got another question open on this problem, but I'll make it more specific here, and may be if I get a right solution here, it will help to fix the rest.
Live link here
http://soloveich.com/pr6/blog/
So, I have a background div for date. For some reason, it only displays correctly on narrow screens, and styling of it doesn't even show in source code on wider ones. The styling is there. Checked it in wp admin panel theme editor.
html
<div class="date3">
<div class="datetxt">
<div class="month"><?php the_time('M ') ?></div>
<div class="day"><?php the_time('j ') ?></div>
</div></div>
css
.date3 {
width:100px;
height: 100px;
border: 2px solid transparent;
border-radius: 100px;
background-color: #7E7E7E;
color: #fff;
text-align: center;
}
#media screen and (max-width: 530px) {
.date3 {
width:100px;
height: 100px;
border-radius: 60px;
}
}
.month {
text-align: center;
margin-top: 12px;
text-transform: uppercase;
font-size: 24px;
font-weight: 200;
font-family: 'Exo 2', sans-serif;
}
.day {
text-align: center;
margin-top: -8px;
text-transform: uppercase;
font-size: 40px;
font-family: 'Exo 2', sans-serif;
}
Also, tried to cheat and set up mediaquery for larger resolution. No luck.
p.s.
all of that started happening after posting a youtube video with post breaker in text
The css for .date3 only exists in media queries that's why it works on lower resolution screens. Try putting it above all the media queries. Should work
I've generated some labels using HTML and CSS which I intend to print onto to pre-printed label paper. The labels should have a fixed width of 45mm * 35mm, which I've set in CSS, but when printed they come out at different sizes.
I've also tried converting the HTML to a PDF using HTML to PDF, but this hasn't helped. What am I doing wrong?
My Html:
<html>
<head>
<style>
#media screen , print {
body {
margin: 0;
border: 0.264583333mm solid green;
}
.table_style {
width: 100%;
}
.table_style td {
text-align: left;
padding: 0 0 3.175mm 5.291666667mm;
}
.space {
height: 2.645833333mm;
}
.div_print {
width: 63mm;
height: 37.735416667mm;
margin-top: 3.735416667mm;
border-width: 1px;
border-style: solid;
border-color: red;
}
.part_dec_print {
font: 3mm arial;
text-align: left;
padding-left: 1.5875mm;
height: 8.5mm;
}
.p_tag {
height: 100%;
vertical-align: middle;
padding-top: 1.5875mm;
}
.qty_span {
padding-top: 1.5875mm;
}
.part_print {
font: 6.5mm arial;
height: 6.5mm;
text-align: left;
padding-left: 1.5875mm;
}
.bar_print {
padding-left: 3.96875mm
}
.qty_print {
font: 6.5mm arial;
text-align: center;
height: 6.5mm;
}
.date_print {
font: 2mm arial;
text-align: right;
padding-right: 4.645833333mm;
margin-top: 4.995833333mm;
height: 2mm;
}
}
</style>
</head>
<body cz-shortcut-listen="true">
<div class="div_print">
<div class="part_dec_print">
<div class="p_tag">REAR FABRIC SCVR</div>
</div>
<div class="part_print">PZQ22-12100</div>
<div class="bar_print">
<img alt="testing" src="http://anybarcode_image_here201x29.png">
</div>
<div class="qty_print">1</div>
<div class="date_print">23A4</div>
</div>
If the problem is differences between browsers (as I think it is now from your comments), then the issue is that your widths include fractional measurements, e.g. 4.645833333mm.
Each browser round decimals slightly differently as discussed here - there's no guaranteed away around it other than to not include fractional widths.
What about creating a PDF in PHP (with something like dompdf) and then styling the PDF so it has the correct widths and heights for your label cells. The PDF and styled formatting should always be the same size no matter the browser.
From device preferences, you have to set page size according to your label and it will work. I just did it for TSC TA210 device!
page size css never work in this case! it will print lots of empty label for you.