Unusual occurrences with Closure commands paired with the "text-align:justify" attribute

Within a Soy template, I have some divs that need to be evenly spaced horizontally.

Working Solution:

CSS (simplified for example):

.list-of-things {
  position: relative;
  text-align: justify;
}

.list-of-things::after {
  display: inline-block;
  width: 100%;
  content: '';
}

.list-of-things div {
  display: inline-block;
  height: 25px;
  weight: 25px;
}

The ::after rule adds a faux last line to enable justification.

HTML (in the soy template):

<div class="list-of-things">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

Here is what it looks like with added border solidity:

https://i.sstatic.net/PosAt.png

JSFiddle demonstrating this: http://jsfiddle.net/ULQwf/1257/

Issue Encountered:

If I place the divs inside Closure commands, like below:

{if true}
  <div>a</div>
  <div>b</div>
  <div>c</div>
{/if}

The div behavior defaults to left alignment as shown here:

https://i.sstatic.net/V76Ma.png

Furthermore, when combining all div types inside the same parent div:

<div class="list-of-things">
  {if true}
    <div>a</div>
    <div>b</div>
    <div>c</div>
  {/if}
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

The closure divs remain unaligned while others are justified:

https://i.sstatic.net/hqJDy.png

Inspecting in Chrome's Developer Tools shows no discernible differences between the div elements involved.

Changing align properties to other values works fine. Only justifying fails in accordance with closure blocks. Is there a hidden enclosing div produced by closures?

Answer №1

Realizations:

  • text-align:justify is sensitive to whitespace
  • Soy templates may not pay attention to whitespace during compilation

In essence, the following code snippet does not function as expected:

<div>
  {if true}
    <div>a</div>
    <div>b</div>
    <div>c</div>
  {/if}
</div>

However, this revised version works perfectly:

<div>
  {if true}
    <div>a</div>{sp}
    <div>b</div>{sp}
    <div>c</div>{sp}
  {/if}
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Discover the power of Jade template engine: A guide to effortlessly setting a stunning background image

Is there a way to add a background-image to my HTML page when using Jade? I would really appreciate any guidance on how to do this. Thank you in advance! ...

Position the image before the unordered list item to align with the text

I'm looking to align the image and text horizontally using CSS. Check out my code below: <div class="latest-tweets"> <ul> <li> <p class="tweet-text">This is tweet Text</p> </li> </ul> </ ...

Use jQuery to display the user input value in real-time

I am in the process of developing a dynamic calculation program to sharpen my jQuery skills, but unfortunately, I'm facing some challenges. I have managed to store values in variables as shown in the code snippet below. <form> Table of: ...

What is the default margin for Autocomplete in Material UI?

Having just started with material-ui, I'm having trouble figuring out the margins of the Autocomplete. My form includes both Autocomplete and TextInput elements, but their positioning seems off to me. Is there some predefined margin box around Autocom ...

Is it possible to move a directive within a limited parent element?

Is there a way to limit the movement of an angular.js drag directive within the confines of its parent element? You can see the problem I'm facing in this jsbin: http://jsbin.com/maxife/3/edit?html,css,js,output ...

There was an issue while trying to import troika-three-text using the importmap

My goal is to incorporate the troika-three-text into my Three.js script by importing it through HTML, as demonstrated below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name=&q ...

Issues with navigation menu functionality in IE8

When I click on the navigation menu in IE8, the menus overlap with each other. This issue does not occur in other browsers. Here is the link to my site: Below is the code for the navigation menu: li id="<?php echo ($epage =='ehome') ? ' ...

What is the best way to position four responsive divs within a container?

Currently working on a responsive website and encountering challenges with the floating container. The goal is to have four divs positioned directly next to each other without any gaps, while also ensuring they stay in place on smaller screens or windows ...

Traditional alignment challenges arise when trying to position two elements in a row using HTML and CSS

Greetings to the community of stack overflow! I am facing a mundane issue with two elements (refer to code snippet below) that requires my attention. Any help or advice would be greatly appreciated. I am aiming for the final output to resemble this: With ...

Is the click count feature malfunctioning?

My goal is to track every mouse click made by the user, so I created a function for this purpose. However, it seems that the function is only counting the first click. To store the count values, I have created a variable. <!DOCTYPE html PUBLIC "-//W3 ...

Change the background color to be visible when there is text overflow with CSS

When I set my <P> tag with a fixed height and overflow:hidden, the text is displayed. However, when I apply a hover effect to it, I set overflow:visible; The issue I am facing is that the text is displayed, but I would like to adjust the z-index and ...

The button works properly in JSFiddle, however, it is not able to clear the ordered list in the

DEMO Creating a script that captures mouse click coordinates and appends them to a list. The functionality works, except for an issue with the clear button not working properly. After making corrections in jsfiddle, the script functions correctly. Howeve ...

JavaScript code for styling changes is not functioning as expected

Check out this code snippet: var moving_nav = document.getElementById("moving_nav"); var logo = document.getElementById("logo"); setInterval(function(){ var scrolled = window.pageYOffset || document.documentElement.scrollTop; if (scrolled >= ...

Error Handling in PHP Form with HTML and Image Upload

Let me give you some context first. Recently, I've delved into the world of php and have been at it for a few days now. My code might be a bit messy, but I've done my best to markup as much as possible. I have a form where three things are expec ...

What is the best way to eliminate #name from a URL?

On my website, there is an internal link that currently reads as http://www.example.com/#name. I am looking to modify this link to simply be http://www.example.com. ...

Modifying the data attribute within the div does not result in a different image for the 360-degree spin view

My current project involves utilizing js-cloudimage-360-view.min.js to create a 360-degree view of images. I have successfully retrieved the images, but I am encountering difficulty in updating the images by clicking a button. index.html <!DOCTYPE html ...

Is it possible to optimize javascript & css bundling for a static website using webpack?

I have been working on organizing my javascript files for a static HTML website. Currently, they are scattered across different HTML files using the script tag. To streamline this, I have created a main.js file that requires all the other files. This main ...

Ensure all columns have the same height as the shortest column

While many solutions exist on Stack Overflow for making columns equal height based on the largest content, I am specifically interested in making all columns equal height based on the smallest column. https://i.sstatic.net/Xlcyh.png In this scenario, my ...

Trouble with setting the width of a fixed element within a parent div

My goal is to make an element's position fixed and have it take up the full width of its parent div. Below is the HTML I am working with: <div class="col-md-3"> <div class="player-avatar-card"> <div class="card-b ...

Customizing the css for a certain category

On my homepage, I display categories with unique labels and icons. Each category is assigned a specific color for its label/icon. Typically, setting unique colors in HTML is straightforward: <!-- ngRepeat: category in categories | orderBy:'displ ...