gpt4 book ai didi

html - 尝试将宽度继承到 css 中的 img 标签

转载 作者:行者123 更新时间:2023-11-28 01:42:32 25 4
gpt4 key购买 nike

我正在尝试将 id 的宽度继承到 img 标签,以便图像永远不会大于它周围的 id。但是不知何故,继承不起作用,但是当我使用绝对值如 580px 的宽度时,它起作用了。我想知道为什么它不起作用。

这是它在 chrome 检查器中的样子。

dev tools

这是我的 CSS 代码的重要部分。

#content {
position: absolute;
font: 16px/1.5 'PT Serif', Times, Cambria, serif;
width: 580px;
left: 50%;
margin-left: -100px;
}

#content p,
#content ul {
margin-bottom: 25px;
}

#content ul {
padding-left: 20px;
}

#content li {
margin-bottom: 5px;
}

#content div.actions {
margin-top: 25px;
font-size: 14px;
font-family: 'Open Sans Condensed', sans-serif;
}

#content div.actions .readmore {
text-decoration: none !important;
padding: 0 2px;
}

#content div.actions .readmore:hover {
background-color: #389dc1;
color: #fff;
}

#content div.actions .comments {
color: #ccc;
margin-left: 10px;
text-decoration: none;
}

.post {
padding: 50px 0 15px 0;
border-bottom: 1px solid #dfdfdf;
}

.post .date {
font: bold 12px 'Open Sans Condensed', sans-serif;
text-transform: uppercase;
color: #a7a7a7;
margin: 24px 0 30px 20px;
position: relative;
}

.post .date:before {
width: 18px;
height: 18px;
position: absolute;
content: '';
left: -22px;
top: -1px;
}

.post img {
width: inherit;
}

最佳答案

在这里查看:Width inherit on fixed div doesn't work

inherit 关键字指定属性应从其父元素继承其值。

在这里,父级中有一个 p 标签。

关于html - 尝试将宽度继承到 css 中的 img 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50365849/

25 4 0