gpt4 book ai didi

html - 位置 :absolute h1 element overflowing right

转载 作者:太空宇宙 更新时间:2023-11-03 20:11:38 24 4
gpt4 key购买 nike

我有一个包含以下所有 CSS 规则的容器(取自 Chrome 开发者工具栏):

border-bottom-color: rgb(85, 85, 85);
border-bottom-style: none;
border-bottom-width: 0px;
border-image-outset: 0px;
border-image-repeat: stretch;
border-image-slice: 100%;
border-image-source: none;
border-image-width: 1;
border-left-color: rgb(85, 85, 85);
border-left-style: none;
border-left-width: 0px;
border-right-color: rgb(85, 85, 85);
border-right-style: none;
border-right-width: 0px;
border-top-color: rgb(85, 85, 85);
border-top-style: none;
border-top-width: 0px;
box-shadow: none;
box-sizing: border-box;
color: rgb(85, 85, 85);
display: block;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
font-size: 16px;
font-stretch: normal;
font-style: normal;
font-variant: normal;
font-weight: 100;
height: 680px;
line-height: 25.9200000762939px;
margin-bottom: 0px;
margin-left: 411.5px;
margin-right: 411.5px;
margin-top: 0px;
max-width: 1080px;
padding-bottom: 40px;
padding-left: 60px;
padding-right: 60px;
padding-top: 40px;
position: relative;
text-shadow: none;
vertical-align: baseline;
width: 1080px;

有一个带有这些 CSS 规则的子 h1 元素:

h1 {
font-size: 42px;
line-height: 42px;
position: absolute;
top: 50%;
top: calc(50% - 21px);
right: 0;
text-align: right;
margin: 0;
padding: 0;
}

但是,文本溢出到容器的右侧:

screenshot 1

screenshot 2

如何确保 h1 元素紧贴父元素的右侧,而不会溢出?

编辑:另一个带有 iPad 图像的元素具有以下 CSS 代码:

.ipad {
width: 251px;
height: 600px;
background-image: url(../img/ipad.png);
background-repeat: no-repeat;
background-size: contain;
display: absolute;
left: 0; top: 0;
}

HTML如下:

<div class="canvas">

<div class="wrapper normal referrals">

<div style="position: relative;">

<div class="referrals fade ipad" data-order="1"></div>

<h1>Referrals</h1>

</div>

</div>

</div>

h1 元素如何忽略父元素的填充,而另一个元素却没有?

最佳答案

h1 元素有 position: absolute; 所以它不关心父元素是否有填充。你可以这样解决。

right: 60px; 其中 60px 是容器 padding-right

关于html - 位置 :absolute h1 element overflowing right,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31401075/

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