Hovering over a container will display the text in a single line

<div class="flex-container">
  <div class="red hover flex">
    <h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </h1>
  </div>
  <div class="blue hover flex">
    <h1>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </h1>
  </div>
  <div class="green hover flex">
    <h1>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </h1>
  </div>
</div>
.flex-container {
  width: 100%;
  height: 300px;
  /* create the flex container */
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}
.flex {
  flex: 1;
}
.hover:hover {
  flex: 4;
}
/* colours */
.red {
  background-color: red;
}
.blue {
  background-color: blue;
}
.green {
  background-color: green;
}
.orange {
  background-color: orange;
}

Greetings! I am seeking assistance in maintaining the text width within a container regardless of its size. The content should stay on a single line similar to the format demonstrated in the provided link below. Can anyone provide guidance or support? Thank you in advance. https://www.example.com

Answer №1

Ensure your flex item remains at a fixed size when hovered, preventing text from breaking into multiple lines.

To clarify, the desired outcome is:

  • Show multiple flex items with text aligned side by side
  • When hovering over an item, it expands until all text fits on one line
  • The expansion of the hovered item should be animated, similar to the provided example

Typically, flex items aim to reach their maximum content size unless instructed otherwise. To maintain a stable size on hover, we must prevent them from shrinking further when space is limited. This adjustment will be made within :hover.

Please be cautious that forcing text onto a single line while other items can't shrink could result in overflow beyond the screen width.

Follow this solution for the above scenario:

.flex-container {
  height: 300px;
  display: flex;
}
.flex-item {
  flex: 1 1 auto;
  /* transition: flex 500ms cubic-bezier(0.09, 0.76, 0.52, 1); */
  transition: flex 300ms;
}
.flex-item:hover {
  flex: 1 0 auto;
}
/* colours */
.red {
  background-color: lightcoral;
}
.blue {
  background-color: lightblue;
}
.green {
  background-color: lightseagreen;
}
<div class="flex-container">
  <div class="red flex-item">
    <h1>It is a long established fact that a reader will be distracted</h1>
  </div>
  <div class="blue flex-item">
    <h1>It is a long established fact that a reader will be distracted</h1>
  </div>
  <div class="green flex-item">
    <h1>It is a long established fact that a reader will be distracted</h1>
  </div>
</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

How does margin:auto differ from using justify-content and align-items center together?

If you want to center both horizontally and vertically at the same time, there are two easy methods available: Option One .outer { display:flex; } .inner { margin:auto; } Option Two .outer { display: flex; justify-content: center; align-items ...

I am encountering issues with an HTML table that is in need of fixing, and I must find a solution without relying on

Can someone help me troubleshoot the structure of this table in the given image? It seems like my rowspan and colspan attributes are not working as expected. I've only used CSS to specify the width and height of the cells. td { width: 60px; ...

Display a snippet of each employee's biography along with a "Read More" button that will expand the content using Bootstrap, allowing users to learn more about each team

I have successfully developed a Google App Script that links to a Google Sheet serving as a database. The application iterates through each row, and I showcase each column as part of an employee bio page entry. ex. Picture | Name | Title | Phone | Email ...

The "hover" effect is not activating on a carousel

I'm having trouble with the hover effect inside the orbit slider. It's not working at all. What am I missing here? Check out the code and fiddle: http://jsfiddle.net/Bonomi/KgndE/ This is the HTML: <div class="row"> <div class="la ...

Resizing the Vue page to fit the viewport and using Flexbox to anchor the footer to the bottom

My Vue.js page structure consists of a navigation bar, main body content, and a footer: <template> <div class="flex_container"> <div class="container_navigation"> <nav-bar /> </div> < ...

Struggling to align content vertically within an article and in need of some guidance

Still struggling with vertical alignment of content within an article. I've tried using tables and the vertical-align property but can't seem to make it work. Any suggestions for centering the content responsively on the right-hand side? The lef ...

Combining DataTables with multiple tables sourced from various JSON arrays

I am trying to display data from two different arrays within the same JSON source in two separate tables, but my code seems to be malfunctioning. JSON Information: { "Policies": [ { "name": "A", "id": "1", "score": "0" } ], ...

Adjusting image sizes in WordPress using CSS and HTML

I am currently working on a blog using the Marlene theme on Wordpress. For my posts, the default image resolution is 835x577, which suits my needs perfectly (see example post). However, I also have a "News" page where I want to display a list of all news ...

The layout of the table is not formatted in a single continuous line

I recently implemented the material-ui table and noticed that the header has a multiline break space. I am looking for a way to make it display in a single line instead. Is there any solution for achieving this using material UI or CSS? Feel free to chec ...

Unfortunately, Rem fails to honor the preferences of users on their smartphones

Trying to incorporate rem units to respect user-defined font-size: Initially, I included the following line in my CSS file: html { font-size: 62.5%; } Subsequently, I applied font-size using rem units to my element. For example: .header{ font-size: 1.5 ...

Transforming the pen into a creative assortment of animated social media icons for top-notch production

My goal is to incorporate animated social media icons on my website using only CSS without any JavaScript. I came across a pen called "Yet Another Set of Animated Social Icons" that I'm attempting to modify. The issue at hand is that instead of the c ...

Develop a circular carousel using React JS from scratch, without relying on any third-party library

I am looking to replicate the carousel feature seen on this website. I want to mimic the same functionality without relying on any external libraries. I have found several resources explaining how to achieve this. Most suggest creating duplicate copies o ...

What is the code to create a forward slash on a webpage using HTML/CSS?

I want to create a unique parallelogram/slash design on my website. While it's simple to place two rectangles side by side, achieving the slash effect is proving to be quite challenging. Can this be done using only CSS or HTML, or does it require SVGs ...

ScriptManager is not accessible in the current ASP.Net Core Razor Page context

I'm facing an issue where I have a view (such as Index.cshtml) and a page model (like Index.cshtml.cs). In the view, there's a JavaScript function that I want to call from the OnPost() method in the page model. I tried using ScriptManager for thi ...

Issue with the <authorization> node in the Web.config file

Whenever I include <authorization>, the page is displayed without the CSS. Does anyone have any thoughts on why this might be happening? Below is my web.config: <?xml version="1.0"?> <configuration> <connectionStrings> <a ...

The MUI makeStyles() class has been implemented, yet the styles are not being displayed when using classList.add('class-name')

Currently, I am utilizing MUI makeStyles() to create a series of CSS classes. Within these classes, I am dynamically including and excluding one specific class to my Box element during file drag-and-drop events. The class is successfully added, as I can o ...

Redirecting script upon successful connection detection

I have created a script that checks for internet connectivity using an image, and redirects if internet is available. However, the issue is that it caches the images, leading to attempts to load them even when offline. Is there a different approach I can ...

The functionality of Ng-Show is acting up

$scope.stay = function() { alert("Inside Keep me In") $scope.timed = false; $scope.isLogStatus = true; } $scope.displayAlert = function() { $scope.timed = true; alert("inside display") } function idleTimer() { var t; $window.o ...

Is there a way to align a single button to the right in a flex column using Material UI?

After diving into Material UI and flex, I've spent some time poring over the documentation but I'm still struggling to figure out how to align only the <CancelIcon /> in a <Drawer /> to the right. I know that to prevent the <Drawer ...

Establishing the focal point and emphasis within a textarea input field

I am presenting a textarea input through PHP with the following command : print " '<textarea rows='16' cols='30'>$flist'</textarea><BR>"; I want the textarea to receive focus and automatically select the co ...