Rails: CSS not showing in inspector and not applying - html

I've got a weird error and it happens to me regularly.
I am doing some css for a project, and in the middle of it, some CSS just starts not being taken into account.
All the CSS file works fine, it's just one line or one class that just does not work nor appear at all in the inspector (usually when CSS is not working, the class appears but the code not working is crossed).
I've tried everything.
- Disabling the cache in network
- Emptying my cache
- Removing everything in my CSS file to keep just this one class (to make sure there is not a syntax error somewhere)
- Changing the name of the class to make sure it's not conflicting with anything.
- I've also checked in the source and I do see my line of CSS, so it's properly compiled!
When I check the inspector, there is just ZERO code applied for this class. Like it does not exist.
The weirdest thing is that if I change the name of the class, it's still not working. But if I add another class to another line, it does work.
It's just crashing for a particular line. The only way I can make it work, is by adding the CSS directly inlined in my HTML. But I don't want to do that, that's ugly.
It happened to me a lot of time, with different projects for a while.
Sometimes when I try with the exact same code 2 days later, it works. Sometimes not.
I even took a video to reproduce the whole bug because that's so weird, I can't find the solution. I've showed this error to good coder friends and they don't understand either...
Anyone had this before?
Here is the code, just in case
<div class="text-step">
<%= image_tag "pay_icon.png" , height: 40 %>
<h3>Pay by card</h3>
<p>Pay in less than 1 minute</p>
</div>
.text-stepĀ {
width: 45vw;
}
And here is what shows in the inspector:
element.style {
}
*, *::before, *::after {
box-sizing: border-box;
}
user agent stylesheet
div {
display: block;
}
Nothing for "text-step"...
EDIT: The CSS is inside a separate CSS file. With 100 lines of CSS in it. Everything works perfectly, except the line I copied.
That's why I was saying that I've tried to remove everything inside this file just to keep the one I copied (to check there is no syntax errors).
Sorry for the confusion I should have been clearer.
SOLVED: Hey. So, I've solved this mystery. That's actually a bit crazy. The space between my classname and my bracket was a non-breaking space. It happens on mac when you press space + alt at the same time. I probably do this without realising it sometimes... Found the solution somewhere online, but it was almost impossible to debug without knowing it as you can't tell the difference with the eye!
Thanks a lot

I'm giving an answer here based on the info you've provided, will edit if more info is given.
If you're using the code like you pasted it, then it doesn't work because it's invalid HTML. In order to have it render correctly it needs to be:
<style type="text/css">
.text-step {
width: 45vw;
color: red;
}
</style>
<div class="text-step">
<!-- commenting the below since it's not HTML -->
<!-- <%= image_tag "pay_icon.png" , height: 40 %> -->
<h3>Pay by card</h3>
<p>Pay in less than 1 minute</p>
</div>
Something every dev learns is that the machine is never wrong. If you think the browser is playing tricks on you, it isn't. Browsers are battle-tested, especially for simple tasks such as parsing HTML and CSS, the problem will be with your code.
to make sure there is not a syntax error somewhere
When you want to test this sort of weird behavior, the best way to do it is to run an "independent" test. Open up something like jsBin or Codepen and add the code that is giving you trouble. That way you can test the code itself without and discard other possible issues (your compiler, the site you're using, your caching system, God knows what else).

Try to use like this way :
<style>
.text-step {
width: 45vw;
}
</style>
<div class="text-step">
<img src="pay_icon.png" style="height: 40%">
<h3>Pay by card</h3>
<p>Pay in less than 1 minute</p>
</div>

SOLVED: Hey. So, I've solved this mystery. That's actually a bit crazy. The space between my classname and my bracket was a non-breaking space. It happens on mac when you press space + alt at the same time. I probably do this without realising it sometimes... Found the solution somewhere online, but it was almost impossible to debug without knowing it as you can't tell the difference with the eye!

You can use this code
body {
margin: 0;
padding: 0;
}
*, *::before, *::after {
box-sizing: border-box;
}
div {
display: block;
margin: 0 auto;
}
.text-step {
width: 45vw;
background-color: #dddddd;
padding: 15px;
}
<div>
<div class="text-step">
<%= image_tag "pay_icon.png", height: 40 %>
<h3>Pay by card</h3>
<p>Pay in less than 1 minute</p>
</div>
</div>

Related

Image Does Not Fill Container

This is my first time posting here and I'm entirely self-taught, so bear with me please if I misspeak or say some dumb things.
I have a Wordpress blog. For quite some time, I have had my blog post format set up so that a "header image" displays across the width of the content space. Across the bottom of that image, I list the title of the post and the date.
To do this, I created what I believe is called a class -- I named it "container" and the only defining trait of this class is that it has "position: relative;" inside it's brackets. (It also has a "shadow" border. I tried taking this out and it had no effect.) This was done in the "additional CSS" section of the wordpress site.
.container {
position: relative;
box-shadow: 1px -1px 7px rgba(0,0,0,0.8);
}
I also made a class called "text-block" that is defined as follows:
.text-block {
position: absolute;
bottom: 0px;
right: 0px;
left: 0px;
background-color: rgba(128,128,128,0.6);
color: white;
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 0px;
}
Each post begins with opening a container. Then, immediately inside of the container is the image, with the width set to 100%. Then, still in the container, I put the text-block in, which is oriented across the bottom. The background color is opaque so that you still see the image behind the text, slightly greyed out.
Here is the code that begins the post of which I've attached a screenshot:
<div class="container"><img class="aligncenter wp-image-8056 size-full" style="width: 100%;" src="https://*mysite*/wp-content/uploads/thx-1138-film-confession.png" alt="Robert Duvall as THX 1138" width="831" height="364">
<div class="text-block">
<h2 style="color: white;"><em>THX 1138</em></h2>
<h6 style="color: white;">Review by *me* | November 6, 2020</h6>
</div>
</div>
The crucial part that I need to ask some advice on is the bottom edge of the container. Until recently, the bottom edges of the image, the text-block, and the container all coincided. Now, instead, a small amount of excess "padding" was added to the bottom of the container. So now, the text-block overlaps the image and some un-filled space beneath it, as you can see in the image. I can't seem to attach a second image of what it should look like, but I think it is clear what I'm trying to achieve.
I don't know where this excess "padding" came from. I didn't change anything -- no CSS was changed. I was just writing individual posts, copy-pasting the format from an old post to a new one to get the correct formatting. I was previewing a single new post when I realized the change, and I thought that I had messed something up on that individual post. But then I started clicking through my site and realized every single post now showed the error.
In the past, some other weird formatting things have happened that stemmed from a plug-in. I've deactivated all plug-ins and the issue remained. I've taken the text-block out entirely and the excess "padding" remains.
Like I said, I'm self-taught. I've really only learned things as I needed to know them. So it's possible I'm missing something simple or committing some grave error without knowing it. But it seems to me that my container lacks the definition that would cause it to be larger than an exact fit to what I put inside of it. Further, the fact that I did not change any of the underlying definitions seems to indicate it's some other kind of issue. But I don't know where it could be stemming from.
I would appreciate any help to figure this out!
UPDATE:
First, Akhilesh, thank you for the reply. Your suggestions did not directly lead to a solution but they at least got me into the spirit of trial and error.
I have found two "solutions" to this problem.
The first is to set "line-height: 0px;" inside of the container in "Additional CSS." This isn't ideal because it means that I can't type regular text in this container anymore. Not very elegant.
The second kind of seems like a fluke. As I showed above, my posts begin with:
<div class="container">**here**<img class="aligncenter wp-image-8056 size-full" style="width: 100%;" src="https://*mysite*/wp-content/uploads/thx-1138-film-confession.png" alt="Robert Duvall as THX 1138" width="831" height="364">
That is a single, unbroken line of code. By starting a new line where I indicate above, it solves the issue. As I stated in my initial description, I have not changed anything. All my posts have been like this since I decided on the format. And as Akhilesh stated, it works in the fiddler (which was a new tool for me, so thanks again).
So, problem solved, but what changed to cause the issue? Something in the way that Wordpress interprets HTML code?
Try adding this to the img element : display:block;
Also, try to find whether there's any padding/margin set for the h2 and h6 elements.
Because I don't see any issues when I tried. Here's the fiddle: https://jsfiddle.net/vL80u1a2/
If that didn't helped, try using the Developer Tools in your browser. Just right click on the element and choose Inspect Element. Then when you select an element on the left side, all CSS would appear on the right pane. You can try trouble shooting for the padding using that Developer Tools.
Have a look at this for more details on how to use the Developer Tools: https://developers.google.com/web/tools/chrome-devtools/css

Show background image that repeats on y axis?

This is a relatively small project that I've been working on however it's driving me insane...
I'm trying to port my original website (which was done completely in Dreamweaver, HTML) to a Visual Studio 2013 ASP.NET project where I can add databases, login's etc. for an assignment I have.
The main problem I have is the fact that my CSS code does not want to do what I tell it to do in terms of the layout.
I've tried completely remaking the website entirely step by step, making sure each aspect works correctly before moving on to the next.
This is what my original website looks like:
http://i.stack.imgur.com/sxfeg.png
(Original HTML + CSS) https://gist.github.com/anonymous/7ed94218f9374d41918e
Now, I used a template a long time back in order to get this design and I've experimented to see which CSS code affects the layout and found that the tag main_container (line 13 of the HTML gist) controls the white background of the website.
So if I remove the tag, this will happen: http://i.stack.imgur.com/BFNLE.png
^ This is important in my problem.
When porting over my website, I copied across all the code correctly and adapted it to ASP. (See Gist: https://gist.github.com/anonymous/9c09befeb8950f4c1416)
However, in doing so, I encountered a problem where the CSS code for the main_container was not being used correctly.
#main_container{
width:977px;
background:url(center_bg_repeat.gif) repeat-y center;
The image was not being repeated on the y axis like on the original website and here's the result: http://i.stack.imgur.com/E4TZU.png
Have I got the syntax wrong? Or what is wrong with my code?
I've placed all the images in the same folder as the CSS file for
convenience.
Is this a problem with Visual Studio 2013 or am I doing something
fundamentally wrong?
Is there perhaps another way to port this same design without
causing so many problems?
I'm not entirely clear on what you want to achieve but if it is the same layout as your original site, then it is better to replicate the html and css exactly first to get it working then look at restructuring or refactoring the code. For example, check that all element sizing is the same so that content displays as you expect.
There are a couple of key differences between your original and new code that could affect the behaviour in the new version of your site. In your original css you don't have a repeat style for center_bg_repeat.gif. Also, it looks like #main_container isn't referenced in your original code.
Repeating a background image won't cause content to repeat across the page. You are already including your content in your new html so you just need to use positioning (e.g. floats vs relative/absolute positioning) to get the tiles to layout in the way you want (see code snippet for an example).
html, body, .container
{
height: 100%;
min-height: 100%;
}
.tile {
float: left;
width: 20%;
height: 30%;
margin: 10px;
padding: 20px;
background-color: #ccc;
}
<div class="container">
<div class="tile">first</div>
<div class="tile">third</div>
<div class="tile">second</div>
<div class="tile">fourth</div>
<div class="tile">last</div>
</div>
In your case, if you want #main_container to scale to fit the content then set its style to min-height: 100%;

Overriding Inline Style with CSS for Wordpress Theme

First, the website - http://www.channeltraveldeal.co.uk/blog
Now - That's out the way so lets go... Hi, I'm currently tinkering with a friends WP powered business page. Sadly, I'm not all that experienced with web design, I just know more than my friend and so I'm in need of some assistance if anyone is able to help.
I'm trying to make sure it's viewed correctly across as many platforms as possible, the theme that has been used has responsiveness settings built in which has obviously helped with this, but unfortunately the header image isn't playing ball and is too big (on tablet only).
I read that the best way to sort this out would be to add this to the CSS for the header image -
width: 100%;
height: auto;
... This is the confusing part (for me), I used Firebug to locate the HTML and CSS for the image and this is what I found -
HTML - <img width="1010" height="220" alt="Channel Travel Deal" src="http://channeltraveldeal.co.uk/blog/wp-content/uploads/2014/02/ctdlogotrue.jpg" class="preload-me">
CSS (from the right pane when the linked HTML is clicked on) - http://pastebin.com/6hyN7yTr
I assumed that the "preload.me" img class is the one I needed to amend. I googled for a bit and came up with a few different snippets to try but none of them worked. Here are the ones I tried.
.preload.me {
width: 100%;
height: auto;
}
preload.me {
width: 100%;
height: auto;
}
I tried those two variations with [style] added after the class name (with no space) and/or !important after the CSS values.
Nothing worked. Would someone let me know if I'm doing something wrong, or if there is something stopping me from overriding this inline style. Also, if my method is on completely the wrong track, if I can do it some other way.
If class="preload-me"
then you need to use the css as preload-me not preload.me
and it should be:
.preload-me{}

disabling comments causing display issues in wordpress

http://www.handheldtesting.com/
When either checking "disable comments" in the back end, or adding 'display:none:'
<div id="respond" class="comment-respond" style="display:none;">
in the code.
1/2 of the content on the page disappears, as the footer moves up.
Any ideas?
Thanks so much,
Ken
This piece of CSS seems to be causing the problem:
body.responsive.layout-full #page-wrapper .full-container {
height: 172px;
}
I'm not sure why that height is explicitly set, seems odd. You should probably test the affects before totally deleting it...

Set page background without referring to <body>

I am new to css and web design so please be gentle ;-)
I was wondering if it is possible to define the background of a page (i.e. what color the screen is) without referring to the tag. So not doing the typical:
body { background-color: #fff; }
I need to do this since I am writing css to stylize our login page, but only have access to the template html to be inserted into the page body. So my html looks something like this (very simplified):
<div id="loginpage">
<div id="title"/>
<div id="content"/>
</div>
I couldn't find any answers online since this seems to be an unusual way of doing it.
So: Is this possible, if yes - how?
How about:
<div style="position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; background: #999;"> </div>
(put it above all your other html, and maybe use z-index: 1; if necessary)
You can use the :root selector if you don't mind about losing IE6-8 support.
But have you tried targeting body or html, in spite of the fact that they're not in the code? They still get inserted into the DOM.
In my opinion you need to discuss this with your team members and a superior. If you find a work around you may come to work tomorrow and find that someone has added
body {
background-color: #not-white !important;
}
after your code and your next question is how to override !important in css.
On a side note, whoever made the restriction of not giving you access to css/main template should really not do that. If you continue working like that you'd end up with a lot of workarounds that will likely bite you.
Regardless of the restiction you could add a style tag like so:
<style type="text/css">
body {background-color:#fff;}
</style>
which would take priority over the original body rule (assuming the body flow is not tampered with). This would be safer than setting background colour for * which would have unexpected side-effects. You may also want to set it through the shorthand background:#fff; which will reset any background image etc. previosly applied.
Update
I've just seen your comment
I did do that first (just target body) , but was friendly reminded by
my team members to only style elements that are actually on the page I
am working on... (which is not the case for body).
Assuming it's a valid argument and not some sort of petty tyranny going on, maybe it could be appropriate setting the background on the loginpage element? You could reference elements by ID like so:
<style type="text/css">
#loginpage {background-color:#fff;}
</style>