What are some ways to have text seamlessly overflow into additional divs?

I am currently utilizing flexbox and facing an issue with aligning the text 'healthy meals' with food delivery as they are in two separate divs. I aim to achieve a layout similar to this.

https://i.sstatic.net/g0a80.jpg

My current setup looks like this:

https://i.sstatic.net/2H5gk.png

Therefore, my assumption is that I need to extend the text into the next div. Can anyone guide me on how to accomplish this?

Below is my code snippet:

.mainheader {
  display: flex;
  justify-content: space-around;
  border: 2px solid green;
  width: 100%;
  background-image: url(./img/hero.jpg);
  height: 100vh;
}

.menu {
  display: inline-flex;
  border: 1px solid red;
  width: 70%;
  justify-content: space-around;
  margin-top: 25px;
}

.mainheader>div:first-child {
  border: 1px solid red;
  width: 40%;
  margin-left: 50px;
  align-items: flex-start;
  justify-content: flex-start;
  display: flex;
  flex-direction: column;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="stylesheet" type="text/css" href="vendors/css/normalize.css">
  <link rel="stylesheet" type="text/css" href="resources/css/style.css">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>omnifoods</title>
</head>

<body>

  <div class="mainheader">
    <div class="slogan">
      <h1>GoodBye Junk Food. <br> Hello Super Healthy Meals.</h1>
      <div class="butt">
        <button style="margin-right: 20px;">I'm hungry</button>
        <button>Show me more</button>
      </div>
    </div>
    <div class="menu">
      <div>Food Delivery</div>
      <div>How it works</div>
      <div>Our cities</div>
      <div>Sign up</div>
    </div>
  </div>
</body>

</html>

Answer №1

To prevent word break in the h1 tag, simply add white-space: nowrap.

.mainheader {
  display: flex;
  justify-content: space-around;
  border: 2px solid green;
  width: 100%;
  background-image: url(./img/hero.jpg);
  height: 100vh;
}

.menu {
  display: inline-flex;
  border: 1px solid red;
  width: 70%;
  justify-content: space-around;
  margin-top: 25px;
}

.mainheader>div:first-child {
  border: 1px solid red;
  width: 40%;
  margin-left: 50px;
  align-items: flex-start;
  justify-content: flex-start;
  display: flex;
  flex-direction: column;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="stylesheet" type="text/css" href="vendors/css/normalize.css">
  <link rel="stylesheet" type="text/css" href="resources/css/style.css">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>omnifoods</title>
</head>

<body>

  <div class="mainheader">
    <div class="slogan">
      <h1 style="white-space: nowrap;">GoodBye Junk Food. <br> Hello Super Healthy Meals.</h1>
      <div class="butt">
        <button style="margin-right: 20px;">I'm hungry</button>
        <button>Show me more</button>
      </div>
    </div>
    <div class="menu">
      <div>Food Delivery</div>
      <div>How it works</div>
      <div>Our cities</div>
      <div>Sign up</div>
    </div>
  </div>
</body>

</html>

Answer №2

Ensure your text doesn't wrap;

Consider incorporating this into your tagline or header wherever it fits best. It could possibly benefit you :)

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

Can the color of text be adjusted (to either white or black) based on the background color (in any color and format)?

To achieve a text color that contrasts well with any background, I need to make sure it's either black or white. The background in my app can vary in color and format, so finding the perfect solution has been challenging. Using mix-blend-mode doesn&a ...

The CSS counter fails to increment

In this unique example: h3 { font-size: .9em; counter-reset: section; } h4 { font-size: .7em; counter-reset: subsection; } h3:before { counter-increment: section; content: counter(section)" "; } h4:before { counter-increment: subsection 2; ...

What is the best way to ensure that my drop down select menu consistently displays the same data even after performing a query with the menu?

Hey there! I'm facing a little hiccup with a drop-down selection box. Here's what I'm trying to do - get someone to log into a database, and then display all available tables in the selection box. Once they choose a table, they hit select an ...

Swap out the traditional submit button on your form with a stylish Font Awesome

Can anyone assist with replacing the submit button with a Font Awesome icon? I've tried it myself, but the icon is not displaying on the button. Here is what I have attempted so far: <form action="{{route('destroycourse', $course->id) ...

I decided to uninstall Bootstrap, but now I find myself unable to make any CSS changes

After attempting to uninstall Bootstrap, my application.css no longer seems to have any effect on my app. Any suggestions on how to resolve this issue? Here is a breakdown of the steps I took that led to this problem: - Removed require bootstrap from app ...

How to center an image within a div without it moving

I have set up a JSFiddle for reference: http://jsfiddle.net/AsHW6/ My task involves centering the down_arrow.png images within their respective div containers. I have successfully centered the up_arrow.png images using auto margins. These images are posit ...

Combining jQuery form validation with a PHP script on a single webpage

After implementing jQuery form validation and redirecting using the function btn_onclick() { window.location.href = "http://localhost/loginprivate.php";} from index.php to loginprivate.php, my web app's PHP script is not being executed. The user is re ...

Issue with flickering scroll-snap in React component with useState

I've encountered an unusual flickering glitch that only occurs when using the combination of: css scroll-snap useState Sub-Components But it's strange because the issue only arises when these three are combined! https://i.sstatic.net/TvwyW.gif ...

Adjusting the background color of an HTML element with CSS through the power of Javascript

I am looking to dynamically change the background color of an element in CSS using JavaScript when a button is clicked. Currently, my CSS code looks like this: div.box { width:100px; height:100px; background-color:#FF2400; } I want the backg ...

Tips for eliminating the default margin without using a float

Exploring the world of divs and buttons led me to an interesting discovery: removing a float creates a natural margin. Upon entering this styling: body { background: gray; } button { font-size: 17px; color: white; margin-l ...

Adapting content based on various media queries

After spending more time on this question, I hope to clarify my thoughts better this time around. I am currently designing a responsive layout for my upcoming landing page. The main header in the body changes based on the browser size and device. <h1& ...

ObtainComputedStyle yields surprising CSS properties

Can anyone help me figure out why I'm not able to access a CSS rule's value correctly using getComputedStyle? Here's what I'm dealing with: background: linear-gradient(to right, red , yellow); However, the result I'm getting is d ...

PHP struggling to retrieve information from an HTML form

My PHP page is having trouble retrieving values from the HTML form. It keeps sending empty strings to the database. Below are my HTML and PHP code snippets. I am new to PHP and struggling to identify the issue. Please assist in finding the error. HTML s ...

Utilize alternate SCSS file depending on the direction of the text property

I have a dilemma with two SCSS files in my project - one named app.scss and the other app-rtl.scss. The main distinction between them is that the latter includes SCSS files for handling right-to-left layouts. My goal is to switch to the app-rtl.scss file ...

Can PHP be used to dynamically load a different stylesheet on a webpage?

Currently in the process of developing a mobile version of my website, I have determined that implementing an alternate stylesheet would be the most effective method to ensure compatibility with mobile devices. I am considering using a PHP script for use ...

methods for retrieving an array of input values from HTML into JavaScript

I posted a question on salesforce.stackexchange.com and you can find the link below: Link to question After receiving feedback that my question is more related to JavaScript than Salesforce, I am reposting it here. Please review from an HTML and JS stand ...

Animating range tick movements as the range thumb moves

My custom range input includes a span that displays the range's value and a div with multiple p elements acting as ticks. To create these ticks, I had to use a custom div because using "appearance: none" on the range hides the ticks by default. The ti ...

Struggling to fetch a basic form field input using node.js and express

Currently, I am delving into Node.js with express and web development. For my inaugural project, I aim to craft a directory listing application. In my quest, I stumbled upon a captivating HTML form. Here's a snippet of the form's code: <form a ...

"Addressing the issue of white space between the status bar and header in Cordova

I have tried numerous solutions but I am still unable to remove the white space between the header and status bar, as shown in the attached image. https://i.sstatic.net/a9xTG.jpg My current setup involves using Intel XDK version 3987 with Cordova plugin ...

Is it possible to utilize the element tags from a different custom directive as the template for a new custom directive?

Recently started using angularjs and working on a web application that incorporates custom directives. I want users to have the ability to choose which directives they see upon logging in. To achieve this, I am storing the selected custom directive tags in ...