Enclose a text line within a flexible div container

I've encountered an issue with my CSS: I have a dynamic div containing a single line of text that needs to wrap every time the width of the div resizes to a smaller size.

The challenge lies in having the text inside a table, serving as a directory for contacts and similar to paging functionality.

For a clearer view of the problem, refer to the attached images. Additionally, a snippet of the code has been provided below for reference.

Since I lack expertise in CSS, I'm seeking suggestions for a more suitable layout for this particular scenario.

Your assistance would be greatly appreciated. Thank you! :)

<div id="divSearch" style="width:350px">
<p style="word-wrap:break-word;white-space:pre-wrap;">
    <table id="tblGlossary">
        <tr>
            // Table content here
        </tr>
    </table>
</p>
</div>

Answer №1

I made some updates by removing the <table> and using a <div> tag instead:

Check out the live demo here

Here's the updated HTML code:

<div id="divSearch" style="width:350px">
<p style="word-wrap:break-word;white-space:pre-wrap;">
    <div id="tblGlossary">
            <a href="#">#</a>
            <a href="www.abc.com?tag=A'">A</a>
            <a href="www.abc.com?tag=B'">B</a>
            <a href="www.abc.com?tag=C'">C</a>
            <a href="www.abc.com?tag=D'">D</a>
            <a href="www.abc.com?tag=E'">E</a>
            <a href="www.abc.com?tag=F'">F</a>
            <a href="www.abc.com?tag=G'">G</a>
            <a href="www.abc.com?tag=H'">H</a>
            <a href="www.abc.com?tag=I'">I</a>
            <a href="www.abc.com?tag=J'">J</a>
            <a href="www.abc.com?tag=K'">K</a>
            <a href="www.abc.com?tag=L'">L</a>
            <a href="www.abc.com?tag=M'">M</a>
            <a href="www.abc.com?tag=N'">N</a>
            <a href="www.abc.com?tag=O'">O</a>
            <a href="www.abc.com?tag=P'">P</a>
            <a href="www.abc.com?tag=Q'">Q</a>
            <a href="www.abc.com?tag=R'">R</a>
            <a href="www.abc.com?tag=S'">S</a>
            <a href="www.abc.com?tag=T'">T</a>
            <a href="www.abc.com?tag=U'">U</a>
            <a href="www.abc.com?tag=V'">V</a>
            <a href="www.abc.com?tag=W'">W</a>
            <a href="www.abc.com?tag=X'">X</a>
            <a href="www.abc.com?tag=Y'">Y</a>
            <a href="www.abc.com?tag=Z'">Z</a>
    </div>
</p>
</div>

And here's the corresponding CSS:

#tblGlossary a {
    padding: 0 2px
}

Answer №2

Swap out your complete table for a div without a set width:

<div id="divGlossary">
    <a href="#" >#</a>
    &nbsp;
    <a href="www.abc.com?tag=A'">A</a>
    &nbsp;
    <a href="www.abc.com?tag=B'">B</a>
    &nbsp;
    <a href="www.abc.com?tag=C'">C</a>
    &nbsp;
...

If you already have the table within a div, just utilize that existing one.

The word-wrap feature doesn't function on table cells in the manner you desire.

Answer №3

Attempting to wrap a table can be tricky. Have you thought about using the CSS property display: inline on all elements as a possible solution?

Answer №4

If you're okay with incorporating a scrollbar, you can implement the following style:

#longlines {
clip : auto;
overflow : scroll;
}

Hopefully, this will resolve your issue. Please inform me if it does not.

<div width="10%" style="position: absolute; left: 2%; word-wrap:break-word;"> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb </div> <div width="86%" style="position: absolute; left: 14%;word-wrap:break-word;"> bbbb </div>

Alternatively,

Wrap your text within <span> </span>

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

Increasing the height of child elements beyond the boundaries of their parent container

Is there a way to make three divs with fixed heights expand outside a full-width parent div, but only in terms of height, not width? Imagine the scenario depicted in the image below: What approach would be most effective in achieving this design? Check ...

Retrieve data from a different div, perform a subtraction operation, and dynamically update yet another div using jQuery

Looking to extract a specific div class value, subtract 500 from it, and display the result in another div. Unclear about the steps needed to show the subtraction outcome on the other div. Consider this scenario: <div class="main-value">6000</d ...

Tips for effectively applying an image as a border

Just starting out with HTML and CSS here, and I'm trying to figure out how to use an image as a border for a div element. Can someone help point out my mistake? div { width: 240px; height: 510px; background-color: lightblue; border-image ...

Link clicking does not trigger URL routing properly

I've been tasked with updating our web application, and I'm facing a challenge that I need help with. My boss wants users to be able to click on a link in an email and have the internal company web app directly navigate to a specific page indicat ...

Exploring the elimination of box shadow on elements that overlap

view image hereI'm experiencing an issue with my HTML code where a box shadow appears in the mobile view. Despite my efforts, I cannot seem to remove it. This problem only arises in the mobile view, leading me to believe that it may be related to how ...

What is the best way to toggle the visibility of a div when a button is clicked?

I have a container with a registration wizard, and I want to toggle the visibility of this container when a button is clicked. How can I achieve this? Check out the code snippet below. Thank you :) <div id="wizard" class="swMain"> <ul> ...

Issue with alignment on the printed version of an HTML document

While attempting to print an auto-generated HTML page through my Thermal POS printer, I encountered a large left margin issue. The application is developed using PyQt5, and I had to resort to a python script to generate the HTML code. Unfortunately, in the ...

Position the background of the container in the center and keep it

I am trying to create a fixed background header using the following CSS properties: header { margin: 0; padding: 0; width: 100%; height: 300px; display: block; background-image: url('...'); background-repeat: no-repea ...

Is there a way to include multiple div elements on a single page using React?

I am currently in the process of developing an e-commerce website and I am looking to display multiple items on the front end using React.js with Bootstrap as the CSS library. Below is the code snippet for my return div. How can I go about showcasing mul ...

Open Chrome in fullscreen mode directly from your Android home screen without the statusbar displayed

One of my clients is looking to have a specific website launched from an icon on an Android tablet. Since he is leasing the tablets, we have full control over the hardware. The goal is for these tablets to exclusively display his site (which is a slideshow ...

Wrapping is disabled for all elements within the container div that contains three additional div elements

I am trying to prevent one of the three divs inside a fixed top navbar container from sliding underneath another, causing the navbar to become taller. The code below is using Bootstrap and the issue is with the navbar-header div sliding underneath the he ...

Clickable tab to collapse a section containing an image and aligned text

When using Bootstrap 3, I have a button that collapses a div containing an image and text. The button alternates between showing a '+ More' and a '- Less' message. However, the alignment of the image is off with the text. Is there a way ...

CSS dropdown menu - overlapping elements an issue?

Discover our test server here: Check out the box labeled "Organizers" on the top right corner... I've been struggling to bring the drop-down menu to the front layer. I've experimented with positioning and z-index, but so far, no success... Any ...

Run a JavaScript code to show a hidden element

My latest project involves automating tasks on a website using Selenium. I encountered an issue where I cannot click on a hidden button defined this way: <body> <div class="smenu" id="smenu4"> <input tabIndex="-1" type="button" ...

I attempted to implement a CSS and Typescript animation for a sliding effect, but unfortunately, it isn't functioning

So I'm encountering an issue with this unique ts code: {/* Mobile Menu */} <div className="lg:hidden"> <button className="flex items-center w-8" onClick={toggleMenu}> {isMobileMenuOpen ? ( ...

switch out asterisk on innerhtml using javascript

Is there a way to replace the asterisks with a blank ("") in the innerHTML using JavaScript? I've attempted this method: document.getElementById("lab").innerHTML = document.getElementById("lab").innerHTML.replace(/&#42;/g, ''); I also ...

Optimize Your Website for Various Screen Sizes

Can anyone assist with centering my webpage on small screen sizes? Everything looks good at the normal width of 989px, but once it shrinks, it shifts to the left and leaves excess white space on the right. I've tried various methods to correct this is ...

Is it possible for me to send JSON data using a form to HTTP_RAW_POST_DATA?

Currently, I am in the process of creating a web interface for code that is typically designed to run on Android devices. I transmit JSON data and retrieve the data by using the following method: $json = json_decode($HTTP_RAW_POST_DATA,true); Is there a ...

Tips for implementing an HTML modal with AngularJS binding for a pop up effect

As a beginner in AngularJS, I am facing a challenge. I have an HTML page that I want to display as a pop-up in another HTML page (both pages have content loaded from controllers). Using the router works fine for moving between pages, but now I want the s ...

CSS: The button appears to be slightly lower than the label

For more information, check out this GitHub link Here is the HTML code snippet: <div class="col-md-12"> <div class="col-md-2"> Processing </div> <div class="col-md-4"> <button class="btn btn-primary">Hello</ ...