gpt4 book ai didi

html - 在 Ghost 主题中居中 img

转载 作者:行者123 更新时间:2023-12-05 05:22:07 39 4
gpt4 key购买 nike

我在 Ghost 上使用免费的 Starter 主题,我试图使图像居中但比段落和主要元素 (60rem) 更宽。

这是将图像固定到位的主要 CSS 元素,当我将 img 中的最大宽度更改为 150 时,我可以使图像达到全宽(我使用 1100 像素宽的图像) % 但它没有那样居中,它有点向右浮动。

我为此模拟了粗糙的 jsfiddle - https://jsfiddle.net/zbsa7ech/

img {
display: inline-block;
max-width: 100%;
min-height: 0;
height: auto;
vertical-align: middle;
border-radius: 5px;
}

我设法获得所需结果的唯一方法是将 max-width 设置为 200% 和 margin-left: -254px

有什么解决方案可以简单地将图像放在容器的中心而不求助于负边距吗?

最佳答案

您可以只从“main”元素中移除宽度约束,并将其应用于段落,而 img 不受约束。

CSS:

body {
margin: 0;
color: #283037;
font-family: "Source Sans Pro", sans-serif;
font-size: 1.8rem;
font-weight: 400;
line-height: 1.6;
}


.container {
box-sizing: border-box;
position: relative;
width: 100%;
max-width: 112rem;
margin: 0 auto;
padding: 0 2rem;
}


.site-main {
width: 100%;

margin: 0 auto;
}
.wrapper {
max-width: 60rem;
margin: 0 auto;
}


img {
display: block;
max-width: 100%;
min-height: 0;
height: auto;
vertical-align: middle;
border-radius: 5px;
margin: 0 auto;
}

HTML:

<body>
<div class="container">

<header class="site-header"></header>

<main class="site-main wow fadeIn">

<p class='wrapper'>The Southern Railway (SR) gave the designation Sub to the wide variety of electric multiple units that were used on inner-suburban workings in the South London area. Originally these units were formed as three-car units, but in the 1940s, all surviving units were increased to four cars by the addition of an 'Augmentation' trailer. New four-car units were also built at this time, and these survived in passenger use until late 1983, by which time British Rail had allocated to them TOPS Class 405.</p>

<p><img src="https://i.sli.mg/DZAkY8.jpg" alt=""></p>

<p class='wrapper'>The Southern Railway (SR) gave the designation Sub to the wide variety of electric multiple units that were used on inner-suburban workings in the South London area. Originally these units were formed as three-car units, but in the 1940s, all surviving units were increased to four cars by the addition of an 'Augmentation' trailer. New four-car units were also built at this time, and these survived in passenger use until late 1983, by which time British Rail had allocated to them TOPS Class 405.</p>

</main>
</div>
</body>

代码笔:http://codepen.io/mwilkins91/pen/vyoeGg?editors=1100

关于html - 在 Ghost 主题中居中 img,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41380099/

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