作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试向水平滚动条添加右侧边距,以确保滚动条中的最后一项位于屏幕中央。
以下是我正在尝试的!尽管左填充效果很好,但我不明白为什么没有应用右填充
.option-widget {
display: flex !important;
overflow: auto;
padding-left: 40% !important;
padding-right: 40% !important;
}
HTML:
<div className="option-widget">
<IconButton id={selected} className="icon-font" ><img style={{ width: '70px' }} src={image.selected} alt="name" /> </IconButton>
<IconButton id={selected} className="icon-font" ><img style={{ width: '70px' }} src={image.selected} alt="name" /> </IconButton>
<IconButton id={selected} className="icon-font" ><img style={{ width: '70px' }} src={image.selected} alt="name" /> </IconButton>
<IconButton id={selected} className="icon-font" ><img style={{ width: '70px' }} src={image.selected} alt="name" /> </IconButton>
<IconButton id={selected} className="icon-font" ><img style={{ width: '70px' }} src={image.selected} alt="name" /> </IconButton>
<IconButton id={selected} className="icon-font" ><img style={{ width: '70px' }} src={image.selected} alt="name" /> </IconButton>
</div>
如有任何帮助,我们将不胜感激。
最佳答案
TL;DR
Addpadding-right
to last child element usingelement:last-child
(Example below)
.option-widget {
display: flex !important;
overflow: auto;
}
.icon-font {
margin: 0 1rem;
}
.icon-font:last-child {
padding-right: 50%;
}
<div class="option-widget">
<div class="icon-font">
<img style="width: 70px" src="https://via.placeholder.com/150" alt="name" />
</div>
<div class="icon-font">
<img style="width: 70px" src="https://via.placeholder.com/150" alt="name" />
</div>
<div class="icon-font">
<img style="width: 70px" src="https://via.placeholder.com/150" alt="name" />
</div>
<div class="icon-font">
<img style="width: 70px" src="https://via.placeholder.com/150" alt="name" />
</div>
<div class="icon-font">
<img style="width: 70px" src="https://via.placeholder.com/150" alt="name" />
</div>
<div class="icon-font">
<img style="width: 70px" src="https://via.placeholder.com/150" alt="name" />
</div>
<div class="icon-font">
<img style="width: 70px" src="https://via.placeholder.com/150" alt="name" />
</div>
</div>
我认为您正在使用一些框架来动态添加图像,所以我用纯 html
创建了一个简单的示例。
我将 padding-right
添加为 50%
因为 50%
是全宽的一半/中心,它位于总计 100%
。
关于html - 如何将右侧填充添加到水平滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60446131/
我是一名优秀的程序员,十分优秀!