gpt4 book ai didi

html - 浏览器调整大小时文本溢出

转载 作者:行者123 更新时间:2023-11-28 14:15:41 25 4
gpt4 key购买 nike

1) 知道如何在浏览器调整大小时阻止该文本溢出吗?我在较宽的屏幕上有一张照片,但当宽度变小时,我给 div 一个背景颜色,并设置浏览器不显示图片。

enter image description here

2) 此外,出于某种原因,当我对 section.welcome h1,p 元素进行更改时,此更改也应用于 .content 部分的 p 元素,该部分位于 .welcome 下方。

我认为问题在于在图像上显示文本的代码。当我将其注释掉时,文本根本不会溢出,但即使屏幕尺寸更大,我也必须完全删除图像。

HTML代码:

html,
body {
background-color: rgb(250, 250, 250);
font-family: 'Open Sans', sans-serif;
margin: 0px;
min-height: 100%;
}

body {
display: flex;
flex-direction: column;
height: 100vh;
}

.navbar {
background-color: #1A212B;
display: flex;
padding: 15px;
color: white;
z-index: 1;
}

.navlink-brand {
font-size: 1.5em;
margin-right: auto;
}

.navlink {
padding-right: 8px;
}

.navlink a {
font-size: 1.1em;
color: rgb(255, 255, 255);
text-decoration: none;
transition: 0.2s;
font-weight: 500;
cursor: pointer;
font-weight: lighter;
}

.navlink a:hover {
color: #707A85;
}

.navItems {
display: flex;
align-items: center;
}

.navlink-Toggle {
display: none;
}

@media only screen and (max-width: 768px) {
.navItems,
.navbar {
flex-direction: column;
}
.navItems {
display: none;
}
.navToggleShow {
display: flex;
}
.navlink-Toggle {
align-self: flex-end;
display: initial;
position: absolute;
cursor: pointer;
}
.navlink {
margin: 10px;
}
.navlink-brand {
margin-left: 0;
}
}

.welcome {
text-align: center;
width: 100%;
min-height: 100%;
height: auto;
position: relative;
background-size: cover;
background-position: center;
}

@media only screen and (max-width: 800px) {
.welcome {
min-height: 25vh;
background-color: #707A85;
}
.welcome img {
display: none;
}
}


/*center welcome text,above img*/

.welcome>.welcIn {
top: 50%;
left: 50%;
margin: 0;
position: absolute;
transform: translate(-50%, -50%);
}

.welcome img {
opacity: 0.8;
max-width: 100%;
width: auto;
height: auto;
}

.welcome h1 {
text-shadow: 6px 6px px #1A212B;
font-weight: 900;
font-size: 2em;
}

.welcome p {
text-shadow: 6px 6px 6px #1A212B;
font-weight: 900;
font-size: 1.1em;
}

.welcome h1,
p {
font-size: 3em;
color: rgb(255, 255, 255);
margin: 15px 0;
line-height: 1;
}


/*for sticky footer*/

.all-wrapper {
flex: 1 0 auto;
}

.content {
width: 60%;
margin: auto;
}

.content h2 {
color: black;
text-align: center;
}

.content p {
color: black;
font-size: 18px;
line-height: 20px;
word-wrap: break-word;
text-align: left;
}

footer {
flex-shrink: 0;
border: solid 1px #1A212B;
width: 100%;
height: 50px;
background-color: #1A212B;
}


/*footer p*/

.last {
text-align: right;
color: rgb(255, 255, 255);
margin: 0 10px;
line-height: 50px;
}
<!DOCTYPE html>

<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<div class="all-wrapper">
<div class="navbar"> //nav here
</div>

<main>
<section class="welcome">
<img src="header.png">
<div class="welcIn">
<h1>Welcome to </h1>
<p class="descr">A website where you can .</p>
</div>
</section>

<section class="content">
<h2>Text text text text text</h2>
<p>Text text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text text</p>
<p>Text text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text text</p>
<p>Text text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text texte</p>
</section>

</main>
</div>
<footer>
<div class="last"></div>
</footer>
<script src="script.js"></script>
</body>

</html>

最佳答案

问题来了,因为您要添加带有绝对位置的 .welcIn,然后对其进行翻译。 parent 无法从 child 那里得到高度。

您可以尝试删除 position: absolutetransform: translate(-50%, -50%);。然后添加一点填充,这会有所帮助。

html,
body {
background-color: rgb(250, 250, 250);
font-family: 'Open Sans', sans-serif;
margin: 0px;
min-height: 100%;
}

body {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
height: 100vh;
}

.navbar {
background-color: #1A212B;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
padding: 15px;
color: white;
z-index: 1;
}

.navlink-brand {
font-size: 1.5em;
margin-right: auto;
}

.navlink {
padding-right: 8px;
}

.navlink a {
font-size: 1.1em;
color: rgb(255, 255, 255);
text-decoration: none;
transition: 0.2s;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-ms-transition: 0.2s;
font-weight: 500;
cursor: pointer;
font-weight: lighter;
}
.navlink a:hover {
color: #707A85;
}
.navItems {
display: flex;
align-items: center;
}
.navlink-Toggle {
display: none;
}
@media only screen and (max-width: 768px) {
.navItems,
.navbar {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
.navItems {
display: none;
}
.navToggleShow {
display: flex;
}
.navlink-Toggle {
-ms-flex-item-align: end;
align-self: flex-end;
align-self: flex-end;
display: initial;
position: absolute;
cursor: pointer;
}
.navlink {
margin: 10px;
}
.navlink-brand {
margin-left: 0;
}
}

.welcome {
text-align: center;
width: 100%;
min-height: 100%;
height: auto;
position: relative;
background-size: cover;
background-position: center;
}

@media only screen and (max-width: 800px) {
.welcome {
background-color: #707A85;
}
.welcome img {
display: none;
}
}


/*center welcome text,above img*/

.welcome>.welcIn {
padding: 20px 0;
}

.welcome img {
opacity: 0.8;
max-width: 100%;
width: auto;
height: auto;
}

.welcome h1 {
text-shadow: 6px 6px px #1A212B;
font-weight: 900;
font-size: 2em;
}

.welcome p {
text-shadow: 6px 6px 6px #1A212B;
font-weight: 900;
font-size: 1.1em;
}

.welcome h1,
p {
font-size: 3em;
color: rgb(255, 255, 255);
margin: 15px 0;
line-height: 1;
}


/*for sticky footer*/

.all-wrapper {
flex: 1 0 auto;
}

.content {
width: 60%;
margin: auto;
}

.content h2 {
color: black;
text-align: center;
}

.content p {
color: black;
font-size: 18px;
line-height: 20px;
word-wrap: break-word;
text-align: left;
}

footer {
flex-shrink: 0;
border: solid 1px #1A212B;
width: 100%;
height: 50px;
background-color: #1A212B;
}


/*footer p*/

.last {
text-align: right;
color: rgb(255, 255, 255);
margin: 0 10px;
line-height: 50px;
}
<!DOCTYPE html>

<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="all-wrapper">
<div class="navbar"> //nav here
</div>
<main>
<section class="welcome">
<img src="header.png">
<div class="welcIn">
<h1>Welcome to </h1>
<p class="descr">A website where you can .</p>
</div>
</section>
<section class="content">
<h2>Text text text text text</h2>
<p>Text text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text text</p>
<p>Text text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text text</p>
<p>Text text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text texte</p>
</section>
</main>
</div>
<footer>
<div class="last"></div>
</footer>
<script src="script.js"></script>
</body>
</html>

关于html - 浏览器调整大小时文本溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55950247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com