petros

petros

This one has left me rather confused.

I followed How to remove tailwind from Phoenix completely ? (I only want vanilla CSS) - #3 by abar to remove Tailwind CSS from a recent (latest version) Phoenix app I have started building.

I then added Simple CSS via the CDN option to the root.html.heex layout. Here’s the relevant part:

    <.live_title suffix="">
      <%= assigns[:page_title] || "Our Next Book" %>
    </.live_title>
    <link phx-track-static rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css" />
    <link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
    <script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
    </script>

When I visit the root of the app, which is handled by a normal HTML page (not a LiveView), the styling looks fine for the header and footer. But then, when I visit any LiveView most of the styling looks fine, except the header and footer:

Normal root page:

A LiveView:

Notice how the header and footer is missing some of the styling. Other than that, the rest of the page using the correct styling.

I haven’t changed anything else in the default configuration as far as I can tell.

What might be the issue?

Showing Posts 1 to 9

josevalim

josevalim

Creator of Elixir

Have you compared the generated HTML in the browser for both and used the class inspector to see which classes are being applied?

petros

petros OP

Thank you for the suggestion @josevalim. Indeed, I hadn’t tried, but I have now. Here’s what I see (disclaimer, I am not an expert in CSS, nor do I understand how Phoenix LiveView is relying on the two default layouts (root and app)).

Here’s what I notice. The left page has this body > header style, that gives it those properties (light blue background, centered text, a horizontal divider etc.).

With the right page (LiveView), it seems some styles are not carried over or maybe they are overridden by something? Totally speculating here.

Maybe the way I have removed Tailwind CSS, has left something in place that messes this up? Again speculating.

When I compare the HTML, the only different (which probably makes sense) is that the LiveView has the body wrap in a div that has LiveView related attributes. Probably makes sense based on what I read in the docs.

At this point, I am not sure what to investigate.

What I am going to do, is create a totally fresh Phoenix project but this time use the -no-tailwind option. Then do a minimal example to replicate the situation. I will report back the result.

tcoopman

tcoopman

what’s in the simple.css file?
Where does the rule body > header come from?
how is it generated?

update: I see now, it comes from simple.css/simple.css at 3abdc127ca0c8e4b8fe6640ba7e625c5c4e628f2 · kevquirk/simple.css · GitHub

The issue probably is that simple.css expects a certain structure and that because of the injected div from liveview this structure breaks. You can read here about this container: Phoenix.Component — Phoenix LiveView v1.2.5

If you want to use simple.css I would just copy it in your project instead of using it via a cdn and then modifying it, so it works for you.

petros

petros OP

what’s in the simple.css file?

Here’s the whole file on GitHub.

Where does the rule body > header come from?

I think this is where it comes from: simple.css/simple.css at 3abdc127ca0c8e4b8fe6640ba7e625c5c4e628f2 · kevquirk/simple.css · GitHub

how is it generated?

I don’t think it’s generated. It’s just a direct reference using <link rel="stylesheet" href="https://cdn.simplecss.org/simple.css" />

tcoopman

tcoopman

I updated my previous post with some more information. I noticed your first post too late.

petros

petros OP

Oh right! Indeed, that extra div changes the structure that Simple CSS expects. I have experimented a bit by just adding the exact same header and footer CSS to my app.css file, with the only difference that I have added that extra div:

body > div > header {
    background-color: var(--accent-bg);
    border-bottom: 1px solid var(--border);
    text-align: center;
    padding: 0 0.5rem 2rem 0.5rem;
    grid-column: 1 / -1;
}

body > div > header > *:only-child {
    margin-block-start: 2rem;
}

body > div > header h1 {
    max-width: 1200px;
    margin: 1rem auto;
}

body > div > header p {
    max-width: 40rem;
    margin: 1rem auto;
}

body > div > footer {
    margin-top: 4rem;
    padding: 2rem 1rem 1.5rem 1rem;
    color: var(--text-light);
    font-size: 0.9rem;
    text-align: center;
    border-top: 1px solid var(--border);
}

With this addition I am almost there:

I think there must be some other rule I haven’t brought from Simple CSS. I will keep on looking.

@josevalim I don’t think there’s anything at fault here. But I still wonder, would there be a way to not have to make all these adjustments to bring a plain simple CSS file and be sure it works consistently with both dead and live views?

Would you say Simple CSS’s choice to rely on body > header and body > footer, expecting that’s the definite structure across the web, is at fault here? Would it make sense proposing a different approach to the folks behind it?

petros

petros OP

Alright, here’s what I did, and now the header displays consistently across all views. I moved the header and footer tags from app to root. This removed the div between body and header.

tcoopman

tcoopman

I’d say it depends on their vision, if they want you to build something with their ‘framework’ and expect you to follow the exact structure, it’s not wrong of them.

Similarly it’s not wrong of the liveview team to inject an extra html element (which you can pick whatever you want)

So obviously these 2 are in conflict, but none of them are wrong.

Alright, here’s what I did, and now the header displays consistently across all views. I moved the header and footer tags from app to root. This removed the div between body and header.

but as soon as you have something rendered by liveview that expects the > css relation with body, it might break again.

Honestly, I’d just fork/copy simple.css and change what’s necessary. Easiest change would probably be to give your container an idea:

live_render socket, MyLiveView, container: {:div, id: "my-body"}

And in simple.css do a search replace for body > to: #my-body >

petros

petros OP

Thank you! That makes sense. Indeed, one of their main values is to offer a classless framework. That’s why they approached it that way.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews