【发布时间】:2022-02-11 05:37:57
【问题描述】:
我到处都看到过这个帖子,没有真正的帮助,或者它被无缘无故关闭,除了版主觉得它在未来会“无用”,即使谷歌得到了一个很好的结果,总结了大约 55,000 多个相关结果.
那么,为什么 padding-right 不能与父级一起使用,而 text-align 右子级不能呢?
.rightcbar {
display: block;
font-family: 'Roboto', sans-serif;
text-shadow: 0px 0px 20px #dbd69d;
padding-right: 50px;
height: 152px;
width: 592px;
line-height: 152px;
background: url(rightcbar.png) no-repeat;
}
.rightcbar .rightctext {
display: inline-block;
width: 100%;
text-align: right;
font-size: 25px;
color: #f3f1de;
font-size: 25px;
font-family: 'Roboto', sans-serif;
text-shadow: 0px 0px 10px #aaa;
-webkit-font-smoothing: subpixel-antialiased;
}
HTML
<div id="rightc">
<div class="rightcbar">
<div class="rightctext">Test</div>
</div>
<div class="rightcbar">
<div class="rightctext">Test</div>
</div>
<div class="rightcbar">
<div class="rightctext">Test</div>
</div>
</div>
Smeegs 帮助解释了为什么事情没有按照我在下面的意图进行;如果你感兴趣。这是修改后的工作代码。
.rightcbar {
display: block;
font-family: 'Roboto', sans-serif;
text-shadow: 0px 0px 20px #dbd69d;
padding-right: 50px;
height: 152px;
width: 592px;
line-height: 152px;
background: url(rightcbar.png) no-repeat;
background-position: center right;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box;
}
.rightcbar .rightctext {
display: inline-block;
width: 100%;
text-align: right;
font-size: 25px;
color: #f3f1de;
font-size: 25px;
font-family: 'Roboto', sans-serif;
text-shadow: 0px 0px 10px #aaa;
-webkit-font-smoothing: subpixel-antialiased;
cursor: pointer;
}
【问题讨论】:
-
什么没有按预期工作?
-
你能提供一个jsfiddle吗?
-
它工作正常,如果你的意思是容器 div 应该扩大整个页面宽度,你应该删除它的
width声明。 -
像@Callidior 一样,我很想知道这里到底有什么问题。
-
s30.postimg.org/x8tzg3xrl/Untitled_1.jpg 注意没有填充。 CSS 上没有重置。
标签: html css padding text-align