Vovchikan

Vovchikan

Hello, I’m trying to create my first page on Phoenix-Liveview. But TailWind classes doesn’t worked properly in my LiveView module. I’m trying to stretch <div> from my LiveView module, but LiveView adding nested div, and i don’t understand how to work with this.

<main> with @inner_content in my layout

  <main id="inner_content" class="bg-stone-300 h-full w-full flex flex-col">
    <%= @inner_content %>
  </main>

HTML in my LiveView module

    ~H"""
      <div class="flex-1 bg-lime-500 border-2 rounded-xl p-2">
        123
      </div>
      <div class="flex-1 bg-cinc-500 border-2 rounded-xl p-2">
        123
      </div>
    """

When i replacing @inner_conntent by this html from my LiveView module, all work fine, both divs shrink on all page’s width.


I’ve found “solution” from same question on this forum, but don’t understand it - Styling auto-injected phoenix div between layout and @inner_content?

I’ve tried this


  def my_live_view do
    quote do
      use Phoenix.LiveView,
        layout: {PayLaterWeb.Layouts, :app},
        container: {:tr, class: "colorized h-full w-full flex flex-row bg-black"}

      unquote(html_helpers())
    end
  end

Showing Posts 1 to 6

GazeIntoTheAbyss

GazeIntoTheAbyss

Not sure if its related, but as you are new to Liveview its worth noting that core_components.ex has a bunch of components that all have Tailwind classes and can often mess with your layout if you are not aware of them and use the components.

Also you have app.html.heex and root.html.heex which both have <%= @inner_content %> tags, so not sure which one your code is from, but you mave have decided to work in one and not realise the other has divs and classes that effect your layout?

Easiest way to fix it from my experience is to inspect the page, find out which div is being created that you don’t want then search for it in your code editor. Ctrl + Shift + f in VScode is the solution for me whenever Liveview seems to be creating phantom divs/classes.

Vovchikan

Vovchikan OP

i’m using root.html.heex. My code with <%= @inner_content %> is from root.html.heex.

I didn’t change app.html.heex after creating Phoenix app with phx.new:

<main class="px-4 py-20 sm:px-6 lg:px-8">
  <div class="mx-auto max-w-2xl">
    <.flash_group flash={@flash} />
    <%= @inner_content %>
  </div>
</main>
<footer class="px-4 sm:px-6 lg:px-8">
  <div class="flex items-center justify-between border-b border-zinc-900 py-3 text-sm">
    <div class="flex items-center gap-4 font-semibold leading-6 text-zinc-900">
      <a href="https://twitter.com/elixirphoenix" class="hover:text-zinc-700">
        @elixirphoenix
      </a>
      <a href="https://github.com/phoenixframework/phoenix" class="hover:text-zinc-700">
        GitHub
      </a>
      <a
        href="https://hexdocs.pm/phoenix/overview.html"
        class="rounded-lg bg-zinc-100 px-2 py-1 hover:bg-zinc-200/80"
      >
        Get Started <span aria-hidden="true">&rarr;</span>
      </a>
    </div>
  </div>
</footer>

I have readed in docs about app.html.heex and root.html.heex layouts, but didn’t understand, why i need app.html.heex in Phoenix 1.7. So i decided not touch app.html.heex.

Vovchikan

Vovchikan OP

root.html.heex:

<!DOCTYPE html>
<html lang="en" style="scrollbar-gutter: stable;">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="csrf-token" content={get_csrf_token()} />
    <.live_title suffix=" · Phoenix Framework">
      <%= assigns[:page_title] || "PayLater" %>
    </.live_title>
    <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>
  </head>
  <body class="flex h-screen antialiased">

      <div class="flex-1 w-64 bg-white divide-y-2 divide-zinc-500">
        <div id="topbar-right" class="relative z-10 flex items-center px-4 sm:px-6 lg:px-8 justify-end">
          <ul class="gap-4 flex">
            <%= if @current_user do %>
              <li>
                <.link
                  href={~p"/administration/users/settings"}
                  class="text-[0.8125rem] leading-6 text-zinc-900 font-semibold hover:text-zinc-700"
                >
                  <%= @current_user.login %>
                </.link>
              </li>
              <li>
                <.link
                  href={~p"/administration/users/log_out"}
                  method="delete"
                  class="text-[0.8125rem] leading-6 text-zinc-900 font-semibold hover:text-zinc-700"
                >
                  Log out
                </.link>
              </li>
            <% end %>
          </ul>
        </div>
        <div>Tut budet path</div>
        <main id="inner_content" class="bg-stone-300 h-full w-full flex flex-col">
          <%= @inner_content %>
        </main>
      </div>

  </body>
</html>

I deleted some code, which was for sidebar. At this code I have used my own and others components from core_components.ex, but the problem in still there.

Vovchikan

Vovchikan OP

I will try, ty

Elixir_begginer

Elixir_begginer

I think when the div is injected like that, the tailwind compiler runs before the div is injected, and doesnt add the css classes to the css file.

Try to add:

container: {:div, class: "my-class"}

and in the app.css:

.my-class {
@apply colorized h-full w-full flex flex-row bg-black;
}

I hope that works, however im not able to check it now myself.

GazeIntoTheAbyss

GazeIntoTheAbyss

I believe this is default generated in app.html.heex

<main class="px-4 py-20 sm:px-6 lg:px-8">
  <div class="mx-auto max-w-2xl">
    <.flash_group flash={@flash} />
    <%= @inner_content %>
  </div>
</main>

If you haven’t changed this code, you will get a load of Tailwind from the flash_group core component that might be effecting your layout, as well as the main and div elements.

Try deleting the default code in app.html.heex and just leaving this to see if it fixes anything:

<%= @inner_content %>
— All posts loaded —

Where Next? Top

Trending in Questions Top

Hellowman
Hello everyone! I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++. Does anyone ...
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
mandar1045
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
charlenopires
Hi everyone :waving_hand: I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews