html - 拉伸半张图像以适合 div 和移动中的一半溢出和桌面中 div 的一半部分中的一半图像显示?
解决方案
我想我得到了你需要的东西,尽管你可能应该向我们展示一些代码,看看你真正想要做什么。
你可以检查我在这里做的代码:https ://jsfiddle.net/joligoms/vx3de19L/
以及这里的完整视图:https ://jsfiddle.net/joligoms/vx3de19L/show
但是让我们去解释一下(我猜:P)
因此,对于我使用的 HTML 结构:
<div class-"container">
<div class="paragraph"> <!-- With some text here --> </div>
<div class="image"> <!-- Image goes here --> </div>
</div>
现在在 CSS 上,我已经display: flex
在容器上使用了。
.container {
display: flex;
}
为了使图像在图像 div 中只显示一半,您需要将位置设置为relative
和左侧设置为,50%
就像下面的代码一样:
.image img {
border: 3px solid blue;
position: relative;
left: 50%;
width: 100%; /*Make sure the image occupies whole parent div's width*/
height: 100%; /* Sets the height to parent div's size */
}
为了更改顺序并使容器内的内容更具响应性,我添加了一个媒体查询,如下所示:
@media only screen and (max-width: 768px) {
.container {
flex-wrap: wrap;
flex-direction: row;
}
.container div {
flex-grow: 1;
}
.image {
width: 100%; /* This is important to make the div occupy the whole container and have the image overflow you want */
order: 1; /* Image now goes first */
}
.paragraph {
order: 2; /* Paragraph now goes below*/
}
}
推荐阅读
- google-sheets - 有没有办法可以合并两张纸,同时保持或保留公式?
- javascript - 输入表格 - 步骤
- angular - Ngx-swiper-wrapper 已禁用
- c# - 使用 RestSharp ExecuteAsync 的 .NET Core 3.1 应用程序硬崩溃
- html - 网页中多个css文件的优先级
- python - 为什么语法错误(python)不起作用?
- css - 如何去除这个边距?
- tensorflow - keras.initializers.ones() 是风格吗?
- javascript - 在 Web 应用程序中单击按钮后刷新下拉列表
- scala - 带有替代方法的重载方法值 json: (jsonRDD: org.apache.spark.rdd.RDD[String]) 在 IntelliJ 中使用 Spark