html - 如何使文本流到其他div?
问题描述
我正在使用弹性盒。我正在尝试使“健康膳食”这一文字与送餐保持一致。然而唯一的问题是它在两个单独的 div 中。
我希望我的代码看起来像这样。
我目前有这个:
所以我的猜测是我需要让文本溢出到下一个 div。有人知道怎么做吗?
这是我的代码。
.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>
解决方案
只需按如下方式添加white-space: nowrap
到h1
标签,它将防止断字。
.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>
推荐阅读
- kendo-ui - Kendo UI 组件是否可免费用于 Excel 导入/导出?
- c# - 创建对象的唯一 HashSet
- java - 如何在 Spock Groovy 的 THEN 阶段中的预期模拟方法调用之后设置变量?
- python - 从 MODIS HDFEOS 数据生成网格信息文件
- r - R - 具有 3 个解释变量的线性混合效应模型的回归平面
- c++ - C++ 模板特化中的声明范围
- r - 监听动态创建的闪亮模块
- kubernetes - 如何在 Kubernetes 中等待部署完成
- android - 在 Android 项目中对生成的 grpc 代码进行单元测试时,使用未实现的方法 StatusRuntimeException 命中
- python - 我需要在熊猫数据框中的列表中打印不包括 Nan 的 True 值