使用转换后删除空格
所以我正在研究HTML水疗中心。我创建了部分,并希望每个部分以40:60的比例水平划分。问题在于,当我想在列中垂直中心内容时,它在列的末尾留下了许多空白。这不是一个大问题,但是在最后一列之后,剩下很多白空间,这绝对没有吸引力。
我的代码片段:
*,
::after,
::before {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vw;
margin: 0;
padding: 0;
background-color: #23272e;
color: whitesmoke;
}
section {
width: 100%;
height: 100vh;
float: left;
}
section:nth-child(2) {
background-color: green;
}
.section-content {
height: calc(100vh - 1.5rem);
}
.row {
height: 100%;
}
.row:after {
content: "";
display: table;
clear: both;
}
.column {
float: left;
height: 100%;
padding: 1.5rem;
margin: 0;
}
.col-left {
width: 40%;
height: 100%;
text-align: center;
}
.col-right {
width: 60%;
height: fit-content;
text-align: start;
}
.col-content {
display: inline-block;
height: 100%;
transform: translateY(50%);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<section id="qualifications">
<div class="section-content">
<div class="row">
<div class="column col-left">
<div class="col-content">
<h3 class="caps">Qualifications</h3>
</div>
</div>
<div class="column col-right">
Officia sunt et et eiusmod ipsum qui reprehenderit. Esse sunt amet
cillum deserunt excepteur voluptate laboris nostrud excepteur
deserunt et eu laborum veniam. Tempor veniam laboris pariatur non
magna laborum do nulla ullamco ullamco laboris. Reprehenderit
nostrud officia commodo ullamco voluptate mollit culpa est duis sunt
consectetur sunt. Elit elit culpa cillum commodo irure labore non
sint ut voluptate proident.
</div>
</div>
</div>
</section>
<section id="contact">
<div class="section-content">
<div class="row">
<div class="column col-left">
<div class="col-content">
<h3 class="caps">Contact</h3>
</div>
</div>
<div class="column col-right">
Officia sunt et et eiusmod ipsum qui reprehenderit. Esse sunt amet
cillum deserunt excepteur voluptate laboris nostrud excepteur
deserunt et eu laborum veniam. Tempor veniam laboris pariatur non
magna laborum do nulla ullamco ullamco laboris. Reprehenderit
nostrud officia commodo ullamco voluptate mollit culpa est duis sunt
consectetur sunt. Elit elit culpa cillum commodo irure labore non
sint ut voluptate proident.
</div>
</div>
</div>
</section>
</body>
</html>
编辑:CSS在代码中也无法正常工作,也发布了我的代码。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style type="text/css">
*,
::after,
::before {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vw;
margin: 0;
padding: 0;
background-color: #23272e;
color: whitesmoke;
}
section {
width: 100%;
height: 100vh;
float: left;
}
section:nth-child(2) {
background-color: green;
}
.section-content {
height: calc(100vh - 1.5rem);
}
.row {
height: 100%;
}
.row:after {
content: "";
display: table;
clear: both;
}
.column {
float: left;
height: 100%;
padding: 1.5rem;
margin: 0;
}
.col-left {
width: 40%;
height: 100%;
text-align: center;
}
.col-right {
width: 60%;
height: fit-content;
text-align: start;
}
.col-content {
display: inline-block;
height: 100%;
transform: translateY(50%);
}
</style>
<title>Document</title>
</head>
<body>
<section id="qualifications">
<div class="section-content">
<div class="row">
<div class="column col-left">
<div class="col-content">
<h3 class="caps">Qualifications</h3>
</div>
</div>
<div class="column col-right">
Officia sunt et et eiusmod ipsum qui reprehenderit. Esse sunt amet
cillum deserunt excepteur voluptate laboris nostrud excepteur
deserunt et eu laborum veniam. Tempor veniam laboris pariatur non
magna laborum do nulla ullamco ullamco laboris. Reprehenderit
nostrud officia commodo ullamco voluptate mollit culpa est duis sunt
consectetur sunt. Elit elit culpa cillum commodo irure labore non
sint ut voluptate proident.
</div>
</div>
</div>
</section>
<section id="contact">
<div class="section-content">
<div class="row">
<div class="column col-left">
<div class="col-content">
<h3 class="caps">Contact</h3>
</div>
</div>
<div class="column col-right">
Officia sunt et et eiusmod ipsum qui reprehenderit. Esse sunt amet
cillum deserunt excepteur voluptate laboris nostrud excepteur
deserunt et eu laborum veniam. Tempor veniam laboris pariatur non
magna laborum do nulla ullamco ullamco laboris. Reprehenderit
nostrud officia commodo ullamco voluptate mollit culpa est duis sunt
consectetur sunt. Elit elit culpa cillum commodo irure labore non
sint ut voluptate proident.
</div>
</div>
</div>
</section>
</body>
</html>
So I was working on an HTML SPA. I created sections and wanted each section to be horizontally split in 40:60 ratio. The problem is that when I want to vertically center content in the columns, it is leaving a lot of white space at the end of the column. This is not a big problem but after the last column a lot of white space is left which is definitely unappealing.
A snippet of my code:
*,
::after,
::before {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vw;
margin: 0;
padding: 0;
background-color: #23272e;
color: whitesmoke;
}
section {
width: 100%;
height: 100vh;
float: left;
}
section:nth-child(2) {
background-color: green;
}
.section-content {
height: calc(100vh - 1.5rem);
}
.row {
height: 100%;
}
.row:after {
content: "";
display: table;
clear: both;
}
.column {
float: left;
height: 100%;
padding: 1.5rem;
margin: 0;
}
.col-left {
width: 40%;
height: 100%;
text-align: center;
}
.col-right {
width: 60%;
height: fit-content;
text-align: start;
}
.col-content {
display: inline-block;
height: 100%;
transform: translateY(50%);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<section id="qualifications">
<div class="section-content">
<div class="row">
<div class="column col-left">
<div class="col-content">
<h3 class="caps">Qualifications</h3>
</div>
</div>
<div class="column col-right">
Officia sunt et et eiusmod ipsum qui reprehenderit. Esse sunt amet
cillum deserunt excepteur voluptate laboris nostrud excepteur
deserunt et eu laborum veniam. Tempor veniam laboris pariatur non
magna laborum do nulla ullamco ullamco laboris. Reprehenderit
nostrud officia commodo ullamco voluptate mollit culpa est duis sunt
consectetur sunt. Elit elit culpa cillum commodo irure labore non
sint ut voluptate proident.
</div>
</div>
</div>
</section>
<section id="contact">
<div class="section-content">
<div class="row">
<div class="column col-left">
<div class="col-content">
<h3 class="caps">Contact</h3>
</div>
</div>
<div class="column col-right">
Officia sunt et et eiusmod ipsum qui reprehenderit. Esse sunt amet
cillum deserunt excepteur voluptate laboris nostrud excepteur
deserunt et eu laborum veniam. Tempor veniam laboris pariatur non
magna laborum do nulla ullamco ullamco laboris. Reprehenderit
nostrud officia commodo ullamco voluptate mollit culpa est duis sunt
consectetur sunt. Elit elit culpa cillum commodo irure labore non
sint ut voluptate proident.
</div>
</div>
</div>
</section>
</body>
</html>
EDIT: The CSS isn't working properly in the snippet, posting my code too.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style type="text/css">
*,
::after,
::before {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vw;
margin: 0;
padding: 0;
background-color: #23272e;
color: whitesmoke;
}
section {
width: 100%;
height: 100vh;
float: left;
}
section:nth-child(2) {
background-color: green;
}
.section-content {
height: calc(100vh - 1.5rem);
}
.row {
height: 100%;
}
.row:after {
content: "";
display: table;
clear: both;
}
.column {
float: left;
height: 100%;
padding: 1.5rem;
margin: 0;
}
.col-left {
width: 40%;
height: 100%;
text-align: center;
}
.col-right {
width: 60%;
height: fit-content;
text-align: start;
}
.col-content {
display: inline-block;
height: 100%;
transform: translateY(50%);
}
</style>
<title>Document</title>
</head>
<body>
<section id="qualifications">
<div class="section-content">
<div class="row">
<div class="column col-left">
<div class="col-content">
<h3 class="caps">Qualifications</h3>
</div>
</div>
<div class="column col-right">
Officia sunt et et eiusmod ipsum qui reprehenderit. Esse sunt amet
cillum deserunt excepteur voluptate laboris nostrud excepteur
deserunt et eu laborum veniam. Tempor veniam laboris pariatur non
magna laborum do nulla ullamco ullamco laboris. Reprehenderit
nostrud officia commodo ullamco voluptate mollit culpa est duis sunt
consectetur sunt. Elit elit culpa cillum commodo irure labore non
sint ut voluptate proident.
</div>
</div>
</div>
</section>
<section id="contact">
<div class="section-content">
<div class="row">
<div class="column col-left">
<div class="col-content">
<h3 class="caps">Contact</h3>
</div>
</div>
<div class="column col-right">
Officia sunt et et eiusmod ipsum qui reprehenderit. Esse sunt amet
cillum deserunt excepteur voluptate laboris nostrud excepteur
deserunt et eu laborum veniam. Tempor veniam laboris pariatur non
magna laborum do nulla ullamco ullamco laboris. Reprehenderit
nostrud officia commodo ullamco voluptate mollit culpa est duis sunt
consectetur sunt. Elit elit culpa cillum commodo irure labore non
sint ut voluptate proident.
</div>
</div>
</div>
</section>
</body>
</html>
The problem:
as you can see there is and undesirable blank space at the end of the page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想垂直将内容集中在DIV中,则有许多解决方案: /a>,
但由于这种情况是因为翻译(移动)div的高度溢出了其包含的div,您只需添加它即可。 (但这只是一个快速修复
If you want to center content vertically inside a div, there are many solutions: https://stackoverflow.com/a/2939979/3807365
But since this happens because the height of the translated (moved) div overflows its containing div you can just add this. (but it's just a quick fix because half of the content would be lost if it takes all the height)
这是您要实现的目标?我已经使用了
flexbox
。 (请参阅全页上的摘要结果)使用
网格
This is what you are trying to achieve? I have used
flexbox
. (see snippet result in full page)With
grid