Implementing curved edges with multiple lines and border radius

Trying to give a span with a background a border radius poses a challenge when word-wrap is involved. The desired outcome is rounded edges, except for the top left edge, but achieving this with the border-radius property seems tricky.

If anyone has an innovative idea on how to accomplish this, please share! Thank you.

edit: Here are the codes I've been working with:

.messageTextCont {
  margin-left: 5px;
  word-break: break-word;
}
.messageText {
  font-size: 17px;
  font-weight: 300;
  color: #FBFDFE;
  background-color: #402060;
  padding: 0px;
  box-shadow: 5px 0 0 #402060, -5px 0 0 #402060;
  line-height: 23px;
  -moz-border-bottom-left-radius: 5px;
  -webkit-border-bottom-left-radius: 5px;
  border-bottom-left-radius: 5px;
  -moz-border-bottom-right-radius: 5px;
  -webkit-border-bottom-right-radius: 5px;
  border-bottom-right-radius: 5px;
  -moz-border-top-right-radius: 5px;
  -webkit-border-top-right-radius: 5px;
  border-top-right-radius: 5px;
}

edit2: Open to solutions involving JavaScript as well

edit3: A step closer to the desired design by using the following styling:

-webkit-box-decoration-break: clone;
-o-box-decoration-break: clone;
box-decoration-break: clone;

However, this method applies rounded corners where not intended. Despite partially resolving the issue by overlapping lines slightly, now facing letter overlap. Would appreciate any suggestions to tackle this problem directly without compromising the design.

edit4: Employed box shadows to mask unwanted gaps in the layout:

box-shadow: 5px 0 0 #402060, -5px 0 0 #402061, -5px -3px 0 orange, 5px -3px red;

The current result showcases progress; however, the lower line still overlaps the upper one. If there's a technique to reverse this overlap while maintaining the aesthetic, all input is welcome.

Answer №1

[RESOLVED] : Check out my solution below:

.messageText {
  font-size: 17px;
  font-weight: 300;
  color: #FBFDFE;
  background-color: #402060;
  padding: 0px;
  box-shadow: 5px 0 0 #402060, -5px 0 0 #402061, 5px 5px 0 #402060, -5px 5px #402060;
  line-height: 23px;
  -moz-border-bottom-left-radius: 5px;
  -webkit-border-bottom-left-radius: 5px;
  border-bottom-left-radius: 5px;
  -moz-border-bottom-right-radius: 5px;
  -webkit-border-bottom-right-radius: 5px;
  border-bottom-right-radius: 5px;
  -moz-border-top-right-radius: 5px;
  -webkit-border-top-right-radius: 5px;
  border-top-right-radius: 5px;
  -webkit-box-decoration-break: clone;
  -o-box-decoration-break: clone;
  box-decoration-break: clone;
}

You can view the working example on jsFiddle:

http://jsfiddle.net/vpo2x84s/3/

Answer №3

Completing this task requires a significant amount of effort for such a simple effect. However, in order to address your question, here is one approach:

The process involves detecting line breaks and inserting a new <span> element. Essentially, you are creating additional spans for each subsequent line.

To detect line breaks, the text needs to be split at all spaces, words removed, re-added word by word while monitoring the height of the container parent. If the height increases, a line break has occurred.

Below is a JavaScript solution using jQuery that is quick but effective:

var textContainer = $('span');

textContainer.each(function(){
    var current = $(this);
    var text = current.text();

    var words = text.split(' ');

    current.text(words[0]);
    var height = current.height();

    // iterate through text
    for(var i = 1; i < words.length; i++){
        // save current text
        var origText = current.text();
        // insert new word
        current.text(current.text() + ' ' + words[i]);

        // check for increased height
        if(current.height() > height){
            // remove recently inserted word to avoid line break
            current.text(origText);
            // insert line break and new span
            var linebreak = $('<br />').insertAfter(current);
            current = $('<span>').insertAfter(linebreak);
            // place the removed word into the new span
            current.text(current.text() + ' ' + words[i]);
        }
    }
});

Some parts of the code were adapted from this Source, tailored to suit your requirements.

View it in action on JSFiddle

It's important to note that this code is a basic implementation. For frequent use, consider optimizing it for better performance.

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

Is it possible to obtain the vertex coordinates of an aframe box?

Is there a way to extract the vertex from an object (specifically a box) in AFRAME, or calculate the intersection between a raycaster and an entity's face? Any assistance would be greatly appreciated. Thank you! EDIT: I have included the code snippet ...

Tips for using the $each() function within a jquery append to retrieve object-based conditions for parameters

I encountered an issue while trying to include a condition in my endpoint, and I have recently started using jQuery for this purpose. Here is the code snippet from my Laravel view: <tbody id="tbody"> @foreach ($modul as $m) <tr> ...

Creating a sticky popup feature for your Chrome extension

Just starting out with chrome extensions and looking to create one that appends an external class to a selected tag. For example, let's say we have the following tag: <h1>extension</h1> When the user clicks on this element, I want to ad ...

Concerns with the adaptability of CSS grid rows

I'm struggling to find a solution for the issue I am facing. Is there a way to adjust each column's row height based on its content in a way that differs from the other column rows? The code snippet below demonstrates the current setup, which is ...

An unusual 1px variance appears in the background-image on Internet Explorer

Having trouble with a sprite of two images showing a 1px difference in ALL versions of Internet Explorer, yet working perfectly in Firefox. Check out the demonstration here: http://jsfiddle.net/bHUs3/6/ I'm feeling frustrated. What could be causing ...

Place one div element with a float property set to AUTO, followed by another div element that expands to

I am trying to place two divs inside another. The inner divs are floated, with one having a "width: auto;" and the other needing to fill the remaining space. I have searched for examples, but they all involve at least one fixed width element, which is not ...

Show a web address inside a div element upon the page loading

I've been trying to figure out how to make a URL load on a specific section of my page, but so far, none of the methods I've tried have worked for me. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></scri ...

Having trouble with $.post request to a different domain in a node.js/express app running on port 8081

Whenever I try to use $.post, I keep getting the error message POST https://thewebsite.com 400 (Bad Request). Here is the code snippet that's causing the issue: $.post("https://website.com/blabla", { domain: "infoinfo.com", room: "someInfo", ap ...

Strategies for handling divisions while resizing the browser界面 manipulating divisions during

Here's the HTML/CSS code I'm working with: .container { max-width: 900px; margin: 0 auto; margin-top: 30px; } .divisions { border: 1px solid Black; } .Fisrt-Line { height: 180px; } .First { background-color: Green; width: 32.2% ...

Encountered an Unrecognized Procedure Error - Reference Number: -99 when attempting to access Mandrill account users

Here is the code snippet I am working with: var temp = { 'key': '***.....zWw' }; $.ajax({ url: 'https://mandrillapp.com/api/1.0/users/ping.json.', type: 'POST', data: temp, success: function(result) { console. ...

The footer is failing to appear in its correct position on the homepage of the Rails application

My footer looks great throughout my Rails app except for the Home page. Here is the content of my application.html file: <!DOCTYPE html> <html> <head> <title><%= yield(:title) || "Wagon Rails" %></title> <meta n ...

Avoid the issue of a fixed position navigation bar overlapping with a sticky footer

I need help with making a navigation bar stick to the bottom of the viewport without overlapping the fixed-height sticky footer. Here is the basic markup for reference: <div id="wrap"> <div id="main"></div> </div> <div id="fo ...

What is causing my DropDown List filter to reset when using Pagination?

I am currently working in ASP.NET MVC and I have set up a system to display data from my database on the screen. The interface includes a dropdown list at the top of the page which allows users to filter the data based on two options (option 1 and option 2 ...

JavaScript validation malfunctioning

Whenever I click on the submit button, nothing happens. An error is displayed as follows: Form.js:102 Uncaught TypeError: Cannot set property 'onsubmit' of null. I am having trouble understanding why this error occurs... // JavaScript Document ...

Are there any unauthorized symbols in the path?

Below are the scripts I have: function PostChartValues(meter_id, range_type_id, start_date, end_date) { $.ajax({ url: '@Url.Action("GetMeterReadingsTimeSeries", "Widget")', type: 'POST', data: { MeterType: m ...

I am eager to create a vibrant striped table using React.js, making use of the map function

Using the map function to display fetched device data, but struggling to create a striped color table. I want to alternate the background color of the tbody tag in stripes, using Bootstrap. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX ...

Generating a dropdown menu using JavaScript from a JSON data source

I'm having trouble figuring out how to approach this task. What I want to do is generate multiple select inputs dynamically, each with different options but sharing a common set of choices. Let's say I have the following data in a JSON file: da ...

What is the procedure for removing all cells from the table?

<table class="Table"> <thead class="thead"> <tr class="tr"> <th class="th header">Done</th> <th class="th header">None</th> <th class="th header">None</th> ...

What might be the reason my jquery counter function is not functioning properly?

Hi there, I'm currently working on creating a counter for my website. However, I'm not very proficient in JavaScript and seem to be encountering some errors in my code. Would anyone be able to assist me in writing a piece of code that functions c ...

How can I retrieve the second letter in Materialize CSS FormSelect by using the keyboard?

On my website that utilizes materializeCSS and Jquery, I have encountered an issue with a select box containing numerous options. Typically, when using a select box, I can press a letter multiple times to cycle through options starting with that letter. ...