Fixing alignment issues in HTML and CSS using AngularJS bug-fixing

I'm attempting to create an element with inner elements that need to be justified.

The issue I'm facing is that when I generate the elements with AngularJS, text-align justify doesn't work anymore.

Here's an example that demonstrates the problem:

http://jsfiddle.net/2AaWf/1/

.container {
   text-align: justify;
}
span, a {
   display: inline-block;
}

Is there a way to make this work using AngularJS or CSS modifications?

Any suggestions on how to achieve this?

AngularJS code:

<a ng-repeat="tag in tags" href="#">{{tag.name}}</a>

"tags" is simply a javascript array:

[{"id":"1","name":"Tag name","count":"1","weight":2}]

Answer №1

Exploration

Upon first glance, I was perplexed by this issue. However, with a bit of investigation, I uncovered the reason behind it. This particular question shares similarities with another topic discussed in this thread. To quote a relevant segment:

Typically, in HTML, a line break is treated as a space. Although there are exceptions, and based on strict line break guidelines, certain breaks should be disregarded if they occur right after an opening tag and just before a closing tag. Yet, due to browsers not consistently implementing such rules, your markup gets interpreted as ...

The issue at hand is that in the second example provided, each item is placed immediately next to the following item without any whitespace. Consequently, without any whitespace present, the browser interprets it as one continual word.

He<b>llo, Wo</b>rld!

This code snippet would be displayed inline as:

Hello, World

In this scenario, the code:

<a href="#">Lorem ipsum</a><a href="#">Lorem ipsum</a><a href="#">Lorem ipsum</a><a href="#">Lorem ipsum</a><a href="#">Lorem ipsum</a><a href="#">Lorem ipsum</a>

Gets rendered inline like this:

Lorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsum

Therefore, it treats the entire sequence as a single inline block.

Resolution

Here is a proposed solution, although the reason behind its effectiveness remains unclear to me. Essentially, you need to wrap your anchors and introduce a whitespace character into your template. Curiously, replacing <b> with <span> causes the problem to resurface. This paradox confounds me since both <b> and <span> are inline elements. For further details, refer to this jsfiddle.

If anyone can elucidate why the use of <b> versus <span> yields different outcomes, kindly share your insights. I have experimented with the css for <span>, yet the results remain consistent.

Angular Template:

<div ng-app="app" ng-controller="ctrl" class="container">
    <b ng-repeat="tag in tags">
        <a href="#">{{tag.name}}</a>
    </b>
    <span class="last-child"></span>
</div>

CSS

.container {
    width: 100%;
    text-align: justify;
}

.container b {
    font-weight: normal;
}

.container a, .container span {
    display: inline-block;
}

.last-child {
    width: 100%;
}

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

I need to securely store HTML formatted strings in a database

Currently, I am using a react quill component that outputs HTML content like this: EXAMPLE: <p><br></p><p>fsdafsd</p><p>fsdfsda</p><p>fsdafsad</p I want to store this content in a database. However, I ...

What is the impact of hash urls on SEO?

Looking for back button support options? Check out some recommended plugins here. However, considering that the page loads via JavaScript based on hash tags, can this impact search indexing by Yahoo/Google/Bing? I am contemplating using HTML5 state push fo ...

Utilize JavaScript to compute and implement a deeper shade of background color

To dynamically apply darker shades of background using JavaScript, I have devised the following code. .event-list .bg{ background:#eee; padding:5px; } .grid .event-list:first-child .bg{ background: #2aac97 } .grid .event-list:nth-child(2) .bg{ backgrou ...

Utilizing CSS3 Columns to control the flow of elements and enforce breaks

Struggling to articulate my question, but I'll give it a shot :D Let's talk about the images: I'm having trouble explaining, I want to align the elements like in the first image, but all I'm getting is the second and third pictures. C ...

PHP - Unable to store the input content

I've encountered an issue with my website where I need to create a form for users to submit new information or news. Below is the code snippet that I have: <?php include "0begin.php"; $title=$_POST["title"]; isset($title) or $title=$_GET["tit ...

The value of request.url in NodeJS is consistently set to "/"

As a beginner in learning NodeJS, I am curious about how to determine the URL of a request in order to execute different functions. However, every time I use request.url, it seems to only return "/". My approach involves using NodeJS without additional m ...

The abbreviation for the <select> element is used in iPhone and Android web browsers

I've encountered a dilemma with my HTML <select> dropdowns when viewed in iPhone or Android browsers. The issue arises when I have to display lengthy <option> labels, like this example: [AccountType] [EUR] - [Customer] - CH12 3456 7890 ...

Twitter Bootstrap 3 Carousel now showcasing a pair of images simultaneously instead of three

Can this carousel be configured to show just 2 pictures at a time instead of 3? Check out the live demo here. I've attempted adjusting the columns to col-md-6 and the CSS to 50%, but haven't had any success... ...

Unable to assign a value to a property within an object using AngularJS

const objectData = {}; objectData[key]["digits"] = `${set.first},${set.second},${set.third},${set.fourth}`; When key is a numeric value, an error occurs: TypeError: Cannot set property 'digits' of undefined ...

Unable to send parameters in Ionic Framework JWT POST request

I've been working on making a POST webservice call within the ionic framework. Although the server can recognize the token, it is not reading the parameters I am passing. Below is my code snippet: .controller('HomeCtrl', function ($scope, $ ...

The server mistakenly sent the resource as a Stylesheet even though it was interpreted differently

Dear Fellow Coders, Could anyone lend a hand? I encountered this issue on my website after uploading it to my FTP: "Resource interpreted as Stylesheet but transferred with MIME type text/plain" </head> <body> <div class= "navbar navbar ...

Which domain do I need to use: Google or my own, in order to bypass the Access Denied issue in JQuery

I'm currently experiencing a puzzling issue with my website while using Internet Explorer. Despite loading fine in other browsers, I keep encountering a permission denied error within my JQuery code. What's even more perplexing is that this error ...

A guide to programmatically downloading a file with JavaScript on Internet Explorer

I'm currently facing a challenge with my web page. There is a button that, when clicked, should generate a CSV file (by converting from JSON) for the user to download. I've implemented the logic based on this jsfiddle, and it works perfectly in C ...

Updating HTML using Angular JS with a nested dictionary is a breeze

As a newcomer to AngularJS, I am facing an issue with my code. I have created a dictionary in the controller scope and populated it after an HTTP request (key, value pair). The dictionary is being created successfully and there are no errors, but the HTML ...

Utilizing identical ID values multiple times to link to the identical location

I am currently working on a horizontal grid project with 3 image squares. My goal is to create an action where clicking on any grid section will anchor the user down to a slideshow box displayed below the grid. Below is an example of one grid section and ...

What could be causing the overlap of my input box with its parent container?

Here is the code snippet I am working with: <section className="createTodo-box"> // parent <div className="createTodo-inside"> // child <Input value={this.state.text} style={{ width: '200px' }} ...

Achieve full height in Grid component of material UI by eliminating margins

In this codesandbox example, I have successfully set the grid container height to full using 100vh. However, there is an issue with a margin of 8px being added by the user agent to the body element, and I'm struggling to find a solution to remove it. ...

What is the best way to retrieve the current CSS width of a Vue component within a flexbox layout grid after it has been modified?

There's something about this Vue lifecycle that has me scratching my head. Let me simplify it as best I can. I've got a custom button component whose size is controlled by a flex grid container setup like this: <template> < ...

What is the reason for background images not loading when using `display: none`?

I'm really struggling to understand this puzzle: When the page loads, will mypic.jpg be downloaded by the browser? #test1 { display: none; } #test2 { background-image: url('http://www.dumpaday.com/wp-content/uploads/2017/01/random-pic ...

Text overlaps when li element is nested inside another element

Seeking assistance in creating a CSS/HTML menu bar that triggers list elements on hover. Facing difficulty arranging the list in two columns. Code Sample:http://jsfiddle.net/Km922/1/ <!DOCTYPE html> <html lang="en"> <head> <meta ...