Achieving a similar behavior to a Node.TEXT_NODE with Node.ELEMENT_NODE in the context of flex-direction: column CSS

Below, you'll notice that the div._b5a is set as a flex container with flex-direction: column. Typically, its child is just a text sentence (nodeType == Node.TEXT_NODE):

新增個人簡介,讓大家更瞭解你
, which means the text sentence remains in one line horizontally. This is the usual behavior.

However, after installing a helpful Chrome extension aimed at learning Kanji by highlighting specific characters I want to learn (available here), things changed slightly. The extension achieves this by wrapping the text inside a

<mark style="background: green">
(similar to lines 2 & 4 in the HTML snippet below). While it works well for most cases, there's an issue when the parent element is a flex container with flex-direction: column, causing the sentence to break into three lines instead of one.

The question now becomes: How can this be fixed so that the highlighted text remains on a single line within the context of a flex container with flex-direction: column? Looking at the code of the extension might provide some insights (check it out here).

One potential solution involves adding the following CSS properties:

flex-direction: row;
justify-content: center;

This would apply directly to the owning div of the sentence but figuring out how to implement this fix within the existing extension code may not be straightforward, especially if you're not well-versed in jQuery.

._b5a {
    align-content: flex-start;
    align-items: stretch;
    -webkit-appearance: none;
    background-color: transparent;
    border: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    margin: 0;
    min-width: 0;
    padding: 0;
    position: relative;
    /* flex-direction: row;
    justify-content: center; */
}

div {
    display: block;
}
.fbTimelineUnit {
    color: #1c1e21;
    display: block;
    margin-bottom: 10px;
    position: relative;
}
<div class="_b5a" style="text-align: center; opacity: 0.7;">新增個人簡介,讓  
<mark class="wkh-hl" style="background-color: green; color: inherit;">  
大  
</mark>  
家更瞭解你。</div>

Answer №1

One workaround is to change the display property to contents, this will cause the mark element in your query to behave like a regular text node. However, the downside is that you won't be able to style the container, losing the ability to apply styles such as background-color, border, padding...

If your goal is simply to highlight specific text, you can still utilize properties like color or font-weight to make the text stand out. Here's an example:

._b6a {
    align-content: flex-start;
    align-items: stretch;
    -webkit-appearance: none;
    background-color: transparent;
    border: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    margin: 0;
    min-width: 0;
    padding: 0;
    position: relative;
}

div {
    display: block;
}
.fbTimelineUnit {
    color: #1c1e21;
    display: block;
    margin-bottom: 10px;
    position: relative;
}

mark {
    display: contents;
    color: red !important;
    font-weight: bold;
}
<div class="_b6a" style="text-align: center; opacity: 0.7;">Add a personal bio to help
<mark class="wkh-hl" style="background-color: green; color: inherit;">
others
</mark>
get to know you better.</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

Using jQuery with AJAX for retrieving data and returning a value

I've come across this script: function getUsername() { $.ajax("http://one2xs.com/index.php", { success: function(a) { console.log($(a).find("#left").html().match(/Je bent ingelogd als ([ ^A-z0-9]*)/)[1]); return $( ...

Modifying the small-dialog identifier in the Magnificent Popup

I recently encountered an issue while trying to change the ID name of the small-dialog in the Magnificent Popup JQuery Plugin. After making the necessary CSS adjustments to accommodate this change, the dialog box stopped functioning properly. I am now seek ...

Is the textarea functioning properly with the inclusion of mysterious character variables?

As per the documentation When using an unknown named character reference like &this, it results in an ambiguous ampersand error. This situation is confusing <textarea> &this </textarea> What am I misunderstanding here? Any re ...

Obtain Image in PNG Format using an AJAX Call

I received an Image/PNG from my python service, and it looks like the following: PNG IHDRX,(ã=¤tEXtSoftwareAdobe ImageReadyqÉe< iTXtXML:com.adobe.xmp<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:met ...

Instead of relying on a button click to trigger a script, set up the script to load automatically when inputs are detected

Recently, I created a simple calculator web-app using Angular. In my app.component.html file, I have the following code: <div style="text-align:center"> <h1>Calculator</h1> <input type="text" id="firstNumber" placeholder="Firs ...

Eliminate or conceal styling for this element

Is there a way to remove the last right border in a row of links? #mainMenu a { display: block; float: left; height: 20px; padding: 0px 10px 2px 10px; border-right: 1px solid #cfcfcf; font-size: 16px; font-weight: bold; font-family: arial, verdana, ' ...

New button attribute incorporated in AJAX response automatically

data-original-text is automatically added in ajax success. Here is my code before: <button type="submit" disabled class="btn btn-primary btn-lg btn-block loader" id="idBtn">Verify</button> $(document).on("sub ...

Ways to conceal various components while showcasing just a single element from every individual container

I am looking to only display specific span elements within their parent container (coin) while hiding the rest. The desired output should show only "1" and "first" while the other spans are hidden. <div class="types"> <div class=" ...

What is the best way to change a byte array into an image using JavaScript?

I need assistance converting a byte array to an image using Javascript for frontend display. I have saved an image into a MySQL database as a blob, and it was first converted to a byte array before storage. When retrieving all table values using a JSON ar ...

Avoid data from being reloaded using the select2 plugin version 4

I'm utilizing the select2 plugin(v4) and using ajax to load its options. When I initially open the select input, the data is loaded. However, when I reopen the select, the same data is reloaded. Is there a way to prevent this constant "reloading" ...

extract the following hidden field using the tag <a>

The structure below shows the HTML markup that I am currently dealing with: <td> <a id="lbtnDelete" onclick="deleteFile(this); return false;" runat="server" class="silverbutton smallbutton normal"> <span class="left"> ...

Selenium: Error - The selector provided is not valid: The selector you have specified is invalid or illegal

My attempt at web scraping with selenium on the NFT website Magic Eden is encountering issues. While my code works without errors when scraping normal data like text from the page, it fails when I try to select an NFT category. Error Message: invalid sel ...

Is there a way to customize the default error message for file extensions in the jQuery validation plugin?

Is there a way to customize the error message displayed by the jQuery validation plugin? Below is the HTML form I am using: <form id="form_detail_file3" action="{$form_action}" method="POST" enctype='multipart/form-da ...

Alter the color of textbox text using JavaScript

I have a text input field. When clicked, I want to change the text color style using JavaScript. Previously, I successfully achieved clearing the inner content of the textbox when clicked and reverting to the default version on blur. This code is currently ...

Error encountered while attempting to save process using ajax - 500 Internal Server Error

I am facing an issue with my CodeIgniter code where I encounter a 500 internal server error when trying to save data. I am not sure why this problem is happening and would appreciate any help. Below is the AJAX code in the view: function save() { $(& ...

Is it possible for me to add a div that consistently hovers above other divs on the page

Beginner in the world of CSS. Currently, I am developing a Safari extension where clicking its toolbar button will display a 'dialog banner' (comprising text and a few buttons) on the web page. This banner, in the form of a div, is dynamically a ...

Is it still beneficial to incorporate image sprites in the design of a mobile web app?

As I work on developing a mobile web app, I find myself debating whether to use individual images or stick with image sprites similar to what I do for my desktop site. My main concern is the potential increase in file size from consolidating all the images ...

The border-radius property in CSS selectively rounds only one corner of the modal div window

There seems to be an issue with the border-radius property on modal divs in my project. When I apply the property, only one or two corners of the div round while the other corners remain unchanged. For a visual reference, please check out this image linke ...

Executing a JavaScript command to execute a PHP script and subsequently inserting HTML content into the appropriate row

Here is an easy-to-follow guide... Essentially, I have created an order form that initially consists of one row. <form id="orderform" name"orderForm" action="/secure/delivery-details.html" method="post"> <a id="add">+</a> <table id ...

Image Switching Hover Bug

HTML: <div id="logo"></div> <div id="coming-soon"></div> JavaScript: $(document).ready(function(){ $("#logo").hover( function(){ $("#logo").fadeTo(300, 0); $("#coming-soon").fadeTo(300, 1.0 ...