Troubleshooting problem with overflowing content or text within a div using CSS

My code block looks like this:

<?php
if(strpos($page_info[0]['page_title'], 'Service')!==false)
{?>
        <img src="<?php echo base_url();?>assets/front_assets/images/service.png" width="450px" height="400px"/>
        <br/>
        <div style="width:480px; height: auto; border: 1px solid #000; border-radius: 5px; overflow: visible; display: inline-block;">
        <?php
        foreach($service as $srv)
        {?>
        <div style="float:left;width:100px;">
        <img src="<?php echo base_url().$srv['service_image'];?>" width="100px"/>
        </div>
        <div style="float:left;width:300px">
            <strong><?php echo $srv['service_title'];?></strong>
            <br/>
            <strong><?php echo $srv['service_content'];?></strong>
        </div>
            <div style="clear:both;"></div>
        <?php
        }?>
        </div>

        <?php
}

The line

<strong><?php echo $srv['service_content'];?></strong>
contains dynamic text from a database, added through ckeditor.

Now, take a look at this image:

As you can see, the text overflows the div. Setting the div's overflow: hidden will hide the text next to "contact us."

I want the text to break after "contact us" and continue from "We are just a phone call away."

I know this issue can be fixed with a simple attribute, but I'm unsure of what that is.

Answer №1

To resolve the issue, adjust the style for .column p by changing the width of the parent p from 460px to 100%.

In your style.css file, there is a rule that sets the width for all p elements in .column1 (file ):

.column1 p{
display:block;
width:460px;
padding:20px 0 25px 3px
}

The current setting of width:460% allows the content to exceed the dimensions of its parent element.

To correct this, update the code to:

.column1 p{
display:block;
width:100%;
padding:20px 0 25px 3px
}

Answer №2

Implement the following CSS code to effectively resolve your problem.

.column1 span {
    display: inline-block;
    width: 94%;
}

Alternatively

Try setting the width to auto for the .column1 p class.

For example,

.column1 p{width:auto;}

I hope this solution proves helpful in addressing your issue.

Answer №3

Consider making a modification to this specific line

<strong><?php echo $srv['service_content'];?></strong>

and replace it with

<span style="width:250px;">
   <strong><?php echo $srv['service_content'];?></strong>
</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

The empty area at the top of a personalized WordPress theme

My current project is facing a strange issue - there seems to be an unwanted 16px whitespace or margin at the top of the theme I'm developing, right between the header and admin bar. Even after checking with Firebug, no margin or padding is being show ...

Proper Alignment of Div Elements

Just starting out with coding and currently practicing display and positioning. I've created a webpage with multiple divs containing the same content, displayed in a vertical scroll order. Now, I'm looking to position these divs side by side in r ...

Ensuring that columns stay at a fixed width without wrapping in Bootstrap 4

I'm currently working on a layout where I want the columns to maintain a constant width when resizing the browser, without wrapping. Instead, I'd like a horizontal scroll bar to appear once it reaches the minimum width. Here's my code: < ...

The side navigation panel transition is stuck and failing to slide out as intended

My element is able to slide in smoothly, but encounters trouble when attempting to slide back out. I suspect the issue lies within the syntax for "display: none". Any assistance or recommendations would be greatly appreciated, and feel free to request more ...

series of lines including <ListItemText>

https://i.sstatic.net/L8FUC.png I have been using Material-ui with react. Currently, I am working on creating a list in React that contains long text. However, when the text is too long, it is displayed as a single line which is not what I want. I would ...

Invoke data-id when the ajax call is successful

Initially, there was a smoothly working "like button" with the following appearance: <a href="javascript:void();" class="like" id="<?php echo $row['id']; ?>">Like <span><?php echo likes($row['id']); ?></span ...

Hero Sticky Transition with 100vhDivElement

My code is giving me some trouble. I want the div with text to stay at the bottom of the hero section with a transparent background. When that div reaches the top, it should stick with a black background. The issue is that I have set it in the javascript v ...

The absence of stylesheets being loaded is a common occurrence in a modular JavaFX Application that has been published in

My JavaFX application is modular and functions perfectly in loading all stylesheets when running through IntelliJ IDE. However, upon publishing the application as a PKG file for Mac platform and attempting to run it, no CSS styling is applied. While the P ...

What is preventing me from directly taking from Codepen?

Looking to experiment with a different landing page? Take inspiration from this example. Here's the HTML snippet, for more details check out the full code on Codepen. <link href='http://fonts.googleapis.com/css?family=Lobster' rel=&apos ...

Cover the whole page in darkness and emphasize the division element

I attempted to implement a solution I found on stackoverflow without success. The issue is that the blackout feature does not seem to activate - nothing happens. Within my JavaScript code (all enclosed in the $(document).ready(function () tag), it appears ...

Make sure all of the inner tags are properly contained within their respective containers

In my explanatory bubble, I aim to include text within the explain-header div as a container for my explanations: /*Explain Bubble*/ .explain-container { position: relative; overflow: hidden; max-width: 70vw; max-height: 50vh; background-c ...

Relative Vs Absolute Positioning: Which One to Choose?

Can you explain the distinction between position: relative and position: absolute in CSS? Additionally, when is it appropriate to utilize each one? ...

Enforcing Height Constraints on Images in HTML/CSS

I'm currently working on a design project and encountering a minor issue. Feel free to take a look at the final design example linked here: In the menu on both sides, you'll notice a small border that runs from top to bottom, matching the heigh ...

What is the correct way to call upon Bootstrap's CSS that was obtained through a Gradle dependency?

I'm having trouble referencing the Bootstrap library from the 'External Libraries' section in my project. In my build.gradle file, I included: compile group: 'org.webjars', name: 'bootstrap', version: '3.3.7' ...

What is the best way to enclose a div that holds spans with the text that needs to be

Considering the following HTML structure: <div> <span>foo</span> <span>bar</span> <span>some really long text with word breaks</span> <span>baz</span> </div> Upon rendering, it c ...

Is there a way to utilize JQuery to swap out a CSS background image while preserving the gradient effect?

Currently, I am facing a challenge in dynamically updating the background-image property of a div while preserving other background-related properties (such as color and gradient) using jQuery's .css() function. Although I can successfully replace the ...

Add a unique class to the <li> element in Angular 2 when it is clicked

Here is an example of a component I am working on: <li > <a (click)="status='today'" class="search-dropdown-tabs-active">Today</a> </li> <li> <a (click)="status='tomorrow'">Tomorrow</a> ...

Resetting initial values with Velocity.js post-animation

After animating elements into view on a page, I want to defer further animation through CSS classes. However, Velocity keeps all animated properties in the style= tag, hindering CSS transitions. My solution involves resetting the CSS upon completion, but ...

What is the best way to create transparency within an icon's background without affecting the surrounding box?

Is there a way to set the background color of the icon inside the circle without affecting the transparent box around it? Currently, when I use background:white, it changes both the circle and the surrounding box. https://i.sstatic.net/mlV1I.png ...

Placing divs in rows and columns at specific breakpoints

I have a footer with two divs that I need to be centered and side by side. When the screen size reaches 960px, I want the second div to move below the first one while still staying centered. Does anyone know how to achieve this? Below is my code snippet: ...