gpt4 book ai didi

html - 宽度样式属性在 html 中没有得到正确的尊重?

转载 作者:太空宇宙 更新时间:2023-11-04 05:43:38 26 4
gpt4 key购买 nike

我正在使用 Gatsby 的 Img 组件,但我不知道如何正确设置宽度。它似乎忽略了宽度而只是选择自己的宽度。图像应与宽度属性中指定的完全一样,为 276 像素,如果需要,文本容器应缩小。

为什么像显式宽度这样简单的东西不能用于 html?我错过了什么?

可以在这里找到 WIP 站点 https://lucid-noether-af1c61.netlify.com/

卡片的HTML输出(图片和srcset剥离)

<a class="card blog-card" href="/Code coverage for your repo/">
<div class="card-img-container gatsby-image-wrapper"
style="position: relative; overflow: hidden; display: inline-block; width: 276px;"><img
src="data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAANABQDASIAAhEBAxEB/8QAGAAAAgMAAAAAAAAAAAAAAAAAAAUCAwT/xAAVAQEBAAAAAAAAAAAAAAAAAAABAP/aAAwDAQACEAMQAAABWW5Iw9EwP//EABoQAAICAwAAAAAAAAAAAAAAAAABAxECEiH/2gAIAQEAAQUC41GYyUmy2bM//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFREBAQAAAAAAAAAAAAAAAAAAABH/2gAIAQIBAT8BR//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEABj8CX//EABsQAAMAAgMAAAAAAAAAAAAAAAABESExYXGB/9oACAEBAAE/IXJiekLTnbMe2MTiOYUNn//aAAwDAQACAAMAAAAQDz//xAAVEQEBAAAAAAAAAAAAAAAAAAAAEf/aAAgBAwEBPxBX/8QAFREBAQAAAAAAAAAAAAAAAAAAEBH/2gAIAQIBAT8Qg//EAB0QAAICAgMBAAAAAAAAAAAAAAERACFBYTFRcZH/2gAIAQEAAT8QdELgq5PimJlqlZWDgwqQt3LAWC6qZh9n/9k="
alt=""
style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; object-fit: cover; object-position: center center; opacity: 0; transition-delay: 500ms;">
<picture>
<source media="/static/47e1d99f504ee308027e0b7670c909dc/731d3/reinterpretcode.jpg" srcset="/static/47e1d99f504ee308027e0b7670c909dc/731d3/reinterpretcode.jpg 1x,
/static/47e1d99f504ee308027e0b7670c909dc/2055f/reinterpretcode.jpg 1.5x,
/static/47e1d99f504ee308027e0b7670c909dc/b8c04/reinterpretcode.jpg 2x"><img srcset="/static/47e1d99f504ee308027e0b7670c909dc/731d3/reinterpretcode.jpg 1x,
/static/47e1d99f504ee308027e0b7670c909dc/2055f/reinterpretcode.jpg 1.5x,
/static/47e1d99f504ee308027e0b7670c909dc/b8c04/reinterpretcode.jpg 2x"
src="/static/47e1d99f504ee308027e0b7670c909dc/731d3/reinterpretcode.jpg" alt="" width="276" loading="lazy"
style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; object-fit: cover; object-position: center center; opacity: 1; transition: opacity 500ms ease 0s;">
</picture><noscript>
<picture>
<source media="/static/47e1d99f504ee308027e0b7670c909dc/731d3/reinterpretcode.jpg" srcset="/static/47e1d99f504ee308027e0b7670c909dc/731d3/reinterpretcode.jpg 1x,
/static/47e1d99f504ee308027e0b7670c909dc/2055f/reinterpretcode.jpg 1.5x,
/static/47e1d99f504ee308027e0b7670c909dc/b8c04/reinterpretcode.jpg 2x" /><img loading="lazy" width="276" srcset="/static/47e1d99f504ee308027e0b7670c909dc/731d3/reinterpretcode.jpg 1x,
/static/47e1d99f504ee308027e0b7670c909dc/2055f/reinterpretcode.jpg 1.5x,
/static/47e1d99f504ee308027e0b7670c909dc/b8c04/reinterpretcode.jpg 2x"
src="/static/47e1d99f504ee308027e0b7670c909dc/731d3/reinterpretcode.jpg" alt=""
style="position:absolute;top:0;left:0;opacity:1;width:100%;height:100%;object-fit:cover;object-position:center" />
</picture>
</noscript>
</div>
<article class="card-body">
<h2 class="card-title">Code coverage for your repo</h2>
<p class="card-text">Which unit tests am I missing? This was the question I was facing when writing unit tests for
Singularity. Since Singularity is a dependency…</p>
<div class="card-subtext muted-text">
<p>Posted:<time datetime="2018-11-07T18:48:51.000Z"></time></p>
<p>devopsunittest</p>
</div>
</article>
</a>

enter image description here

最佳答案

首先我建议不要使用那么多的内联样式,因为它很难处理。请改用 CSS 类。

你可以试试:

.card-img-container {
flex-basis: 276px;
}

.card-body {
flex-grow: 0;
flex-basis: calc(100% - 276px);
}

或者

.card-img-container {
min-width: 276px;
}

我不知道您想在移动设备上做什么。您可以根据需要更改这些样式。

关于html - 宽度样式属性在 html 中没有得到正确的尊重?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58919198/

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