Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 带IMG的自举方形瓷砖_Html_Css_Image_Twitter Bootstrap_Tiles - Fatal编程技术网

Html 带IMG的自举方形瓷砖

Html 带IMG的自举方形瓷砖,html,css,image,twitter-bootstrap,tiles,Html,Css,Image,Twitter Bootstrap,Tiles,我想创建带有引导col-*-*类的方形平铺(大小合适),里面有背景图像和一些文本 现在我使用虚拟块和 margin-top: 100% 然后是包含内容的块: position: absolute; top: 15px; left: 15px; right: 15px; bottom: 15px; 但当我为那个块设置背景图像时,它会变得非常难看,所以我想我应该使用标签来正确调整图像的大小 所以我试着让课堂像bgimage一样: width: 100%; object-fit: cover;

我想创建带有引导col-*-*类的方形平铺(大小合适),里面有背景图像和一些文本

现在我使用虚拟块和

margin-top: 100%
然后是包含内容的块:

position: absolute;
top: 15px;
left: 15px;
right: 15px;
bottom: 15px;
但当我为那个块设置背景图像时,它会变得非常难看,所以我想我应该使用标签来正确调整图像的大小

所以我试着让课堂像bgimage一样:

width: 100%;
object-fit: cover;
我还将overflow:hidden设置为父块,但这并没有帮助,图像变得很好,但现在它从我的块中消失了

现在我有两个问题:

  • 是否有更好的方法将图像设置为方形块中的背景以覆盖它

  • 如何对这些块进行适当的填充和边距(顶部、左侧、底部、右侧设置,没有其他方式?需要在小型设备上调整大小)


  • 如果你举个例子,就很容易给出问题的解决方案

    为了适合图像,您可以使用
    img responsive
    引导类。或者使用以下命令:

    body {
        background-color: black;
        background: url(img/bg.jpg) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
    

    如果您对引导网格有正确的想法,那么您将能够根据自己的意愿设计自己的块。您可以从中获得帮助。

    如果您举个例子,就很容易给出问题的解决方案

    为了适合图像,您可以使用
    img responsive
    引导类。或者使用以下命令:

    body {
        background-color: black;
        background: url(img/bg.jpg) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
    

    如果您对引导网格有正确的想法,那么您将能够根据自己的意愿设计自己的块。您可以从获得帮助。

    设置背景图像,并在方形缩略图中添加文本。您需要再添加一个div,位置:绝对,背景大小:cover

    检查

    HTML:

    希望对你有帮助
    享受:)

    在方形缩略图中设置背景图像和文本。您需要再添加一个div,位置:绝对,背景大小:cover

    检查

    HTML:

    希望对你有帮助
    享受:)

    正如我所说,使用背景会给我糟糕的图像,那么如何将它们变成正方形(高度=宽度)?@sindbag请检查上面的代码笔链接,因为我已经修改了答案。我希望这能解决这个问题。正如我所说的,使用背景会给我糟糕的图像,那么让它们变成正方形(高度=宽度)怎么样?@sindbag请检查上面的代码笔链接,因为我已经修改了答案。我希望这能解决问题。
    .margin-top {
      margin-top: 100%;
    }
    
    .square-text {
      position: absolute;
      top: 15px;
      bottom: 0;
      left: 15px;
      right: 0;
      text-align: center;
      padding-top: calc(50% - 30px);
      z-index: 9;
      background: transparent;
      color: #fff;
    }
    
    .square-img {
      background: url('http://www.themdfactor.com/wp-content/uploads/2015/11/image7.jpg') no-repeat;
      position: absolute;
      top: 15px;
      bottom: 20px;
      left: 15px;
      right: 0;
      background-size: cover;
    }