Does setting white-space:nowrap enlarge the div?

My CSS code for div .name sets the width to 75% to truncate text if it doesn't fit. However, resizing the window causes the text to remain the same size and my entire website structure falls apart.

This is the HTML code snippet:

<tr>
    <td class="check_td"><input type="checkbox" name="products" value="<?php echo $row['id']; ?>"</td>
    <td class="product_td">
        <div class="product">
            <div class="thumbnail">
                <img class="img" src="<?php echo $row['img_path'].'/'.$row['img_name']; ?>">
            </div>
        <div class="name">
            <?php echo $row['product_name']; ?> // this is problem
        </div>                          
        <div class="list">
            <ul>
                <li>Seller: <a href="" style="color:black;"><strong><?php echo $data['username']; ?></strong></a>
                (<a href="">98% <img src="img/stars/star.png" width="18px" style="margin-bottom:-3px;"/></a>)
                </li>
                <li><?php echo $address['city']; ?></li>
            </ul>
            </div>
            <div class="comm">
              <img src="icons/comment.png" width="23px"/>(6)
            </div>
        <div class="id"><?php echo $row['id']; ?></div>
                        </div>
                    </td>
                    <td class="price_td">
                        <ul>
                            <li style="font-size:23px;">
                                <strong><?php echo $row['price']; ?> kn</strong>
                            </li>
                            <li>
                                <ul class="ship">
                                    <li>
                                        <?php echo $row['ship']; ?>
                                    </li>
                                    <li>
                                        <strong><?php echo $row['ship_price']; ?> kn</strong>
                                    </li>                                           
                                </ul>
                            </li>
                        </ul>
                    </td>
                    <td class="button_td"><button class="menu_buttons1">Promote Listing &raquo;</button></td>
                </tr>   

I also realized that setting the width to percentages does not work properly when I include white-space: nowrap;

.name{
  display:block;
  float:left;
  margin:6px 0 10px 0;
  width:75%;
  font-size:20px;
  color:black;
  font-weight: 900;
  white-space: nowrap;
  overflow:hidden;
    text-overflow: ellipsis;
}

Changing the width from percentage to pixels resolves the issue. Why can't I set the width of the div with the class name in percentages?

EDIT: I have added a JSFiddle link here: https://jsfiddle.net/nwqoh931/

Answer №1

"

Using <span style="font-style: italic;">white-space: nowrap;</span> will not cause a div to expand."

This CSS property simply instructs the <div> element to prevent text from wrapping inside it.

Here is an illustration:

div{
 width: 100px; 
 background: yellow;
}

.whitespace-normal{
  white-space: normal;
}

.whitespace-nowrap{
  white-space: nowrap;
}
<div class="whitespace-normal">
  TESTING OF WHITESPACE
</div>
<i><b>Default White-Space:</b> The text inside the div is wrapped (creates new lines) based on div width.</i>
<br/><br/>
<div class="whitespace-nowrap">
  TESTING OF WHITESPACE
</div>
<i><b>No Wrap White-Space:</b> Disregard the width of div, Even it overflows. It prints the text exactly what it is. (no new lines)</i>

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

Styling Input elements with a unified border in Bootstrap

[Issue Resolved] I have been working on setting a single border between multiple inputs inside a form-group in Bootstrap. Currently, the border is only visible when the input is not focused and it is the last one. However, my expectation is for the bo ...

Using jQuery to apply a CSS border to an image within a textarea

Working with TinyIMCE, I am looking to incorporate a border around all images within the textarea whenever a user submits the form. $("form").submit(function() { var content = $("#edit-message1-value").val(); // Afterwards, I want to manipulate the cont ...

Select from multiple levels in a dropdown menu HTML

I have encountered an issue while developing a website. I am trying to create a hierarchical list with multiple levels, but it seems that such feature does not exist (unless you know otherwise). As a workaround, I have implemented a system using invisible ...

Searching in TypeScript tables with Angular's search bar

I've successfully completed a basic CRUD application, but now I need to incorporate a Search Bar that can filter my table and display rows with matching letters. I'm unsure how to approach this in my component. I've seen examples using pipe ...

Implementing pagination within an Angular 11 Mat-table with grouping feature

Encountering an interesting issue with MatTable pagination and grouping simultaneously. I have two components each with a Mat-table featuring Pagination+Grouping. ComponentOne functions smoothly without any issues. When choosing to display 5 elements pe ...

Is it possible for you to simulate the shift key being pressed prior to the event execution?

Is there a way to allow the user to scroll left and right horizontally without having to hold the shift key down? I want to achieve this effect by setting the "shiftKey" variable to true even when it is not physically pressed. Any suggestions on how to ...

Creating a reference to a hyperlink or button in a variable

I am currently working on creating a login form for a school project website. The section that is posing a challenge for me is determining if I can assign a variable to a href or button. For instance, imagine that the href has the variable 'A' ...

Steps for developing a floating image transition using CSS and React

Looking to achieve a floating image transition using CSS and React, similar to the Divi theme header images. Check out the example below: enter image description here For more information, visit: ...

To style the input box, apply the CSS properties "filter: alpha(opacity=70);" and "background-image: url(image.png);"

Individual functionality for both the form and css has been achieved, but when trying to implement them together, they do not work as intended. This integration is specifically for a windows sidebar gadget. Here is the structure of the form: <form nam ...

"Hidden panels in Sencha Touch only respond to show() and hide() methods after a resize event

Check out this demonstration of a Sencha Touch app by visiting this link. The button located in the bottom-left corner is supposed to show or hide the menu panel on top of the "Location info goes here" bar, but it seems to be functioning in an unexpected m ...

a guide on combining values for identical dates in a JSON file

I'm currently working on an Android app that involves displaying graph values, and I could use some help. The server is returning a JSON object in the following format: [{ "date": "01-03-2018", "value": "12", }, { "id": "01-03-201 ...

Show a specific form field based on the chosen option in a dropdown menu using Angular and TypeScript

I am looking to dynamically display a form field based on the selected value from a dropdown list. For instance, if 'first' is chosen in the dropdown list, I want the form to remain unchanged. However, if 'two' is selected in the drop ...

The execution of jQuery was hindered due to the implementation of PHP include

Having an issue with jQuery not working in index.php when including the file header.php. The nav sidebar is included, but clicking the chevron does not trigger anything. It only works when I directly include header_user.php without checking the UserType in ...

Resizing SVG to specify width in pixels and automatically adjust height

I'm having trouble understanding how SVG works. Can someone explain where my mistake is? Here's an example of my inline SVG code: <div style="width:1000px; height:auto; background-color:blue;"> <svg class="_image"><use xlink ...

What is the best way to align sections side by side using Bootstrap?

Hello, I'm currently trying to customize the layout of this Bootstrap webpage to resemble the design shown in this image https://i.sstatic.net/w7i6Z.png. Specifically, I want to display the blog section and the team section side by side. As a beginne ...

Access the content of each cell in a table using JavaScript

I need help with a scenario involving a table that has 4 rows, where the 4th row contains a textbox. When the "onchange" event of the textbox is activated, I want to retrieve the data from the cells in that specific row and transfer it to another table. It ...

Struggling with making a rest API request to render HTML

I am trying to retrieve the holders value from a REST API and display it on my website using HTML code. I've attempted the following code, but I'm having trouble actually printing the value. <!DOCTYPE html> <html> <body> <p& ...

Balanced Columns with Background Extending Beyond Half of the Page

If you're looking for the final code, it can be found here: http://jsfiddle.net/asaxdq6p/6/ I am attempting to create an effect similar to this image: To achieve this, I am using the Equal Height Columns with Cross-Browser CSS trick as described in ...

The animations in fontawesome 6.2 are completely ineffective

I've been struggling to make a spinner icon spin on my webpage. I made sure to download the latest version of font awesome and created a simple HTML file to troubleshoot the issue. Take a look at the HTML code below: <!doctype html> <html la ...

How to retrieve video duration in Angular 2 before uploading the file

Is there a way to retrieve the video duration before uploading it in Angular2? I am looking for a solution without using jQuery. Here is the code snippet I have so far: <input type="file" class="form-control" ng2FileSelect [uploader]="uploader" accept= ...