html - 仅在小型设备上 Bootstrap 卡

标签 html css twitter-bootstrap

我正在使用 Bootstrap 3.3.7。我为一个新网站制作了一个网格。其代码可以是 seen here .

我想在 Bootstrap 卡中设置网格元素,所以它看起来像这样:

屏幕大于 767 像素: enter image description here 屏幕小于 767 像素: Screen  767px

我不知道如何开始做这件事。我应该尝试合并网格元素代码(链接到上面)和我的卡代码中的 2 个代码吗?我是否应该从头开始,因为如果我开始一起编写 2 个代码文档,代码会变得很困惑?

Bootstrap 卡代码:

 @media (max-width: 768px) {

	    .index-content .col-lg-4 {
	        margin-top: 20px;
	    }

	    .index-content a:hover{
	    color:black;
	    text-decoration:none;
		}
		.index-content{
		    margin-bottom:20px;
		    padding:50px 0px;
		    
		}
		.index-content .row{
		    margin-top:20px;
		}
		.index-content a{
		    color: black;
		}
		.index-content .card{
		    background-color: #FFFFFF;
		    padding:0;
		    -webkit-border-radius: 4px;
		    -moz-border-radius: 4px;
		    border-radius:4px;
		    box-shadow: 0 4px 5px 0 rgba(0,0,0,0.14), 0 1px 10px 0 rgba(0,0,0,0.12), 0 2px 4px -1px rgba(0,0,0,0.3);

		}
		.index-content .card:hover{
		    box-shadow: 0 16px 24px 2px rgba(0,0,0,0.14), 0 6px 30px 5px rgba(0,0,0,0.12), 0 8px 10px -5px rgba(0,0,0,0.3);
		    color:black;
		}
		.index-content .card img{
		    width:100%;
		    border-top-left-radius: 4px;
		    border-top-right-radius: 4px;
		}
		.index-content .card h4{
		    margin:20px;
		}
		.index-content .card p{
		    margin:20px;
		    opacity: 0.65;
		}
		.index-content .blue-button{
		    width: 100px;
		    -webkit-transition: background-color 1s , color 1s; /* For Safari 3.1 to 6.0 */
		    transition: background-color 1s , color 1s;
		    min-height: 20px;
		    background-color: #002E5B;
		    color: #ffffff;
		    border-radius: 4px;
		    text-align: center;
		    font-weight: lighter;
		    margin: 0px 20px 15px 20px;
		    padding: 5px 0px;
		    display: inline-block;
		}
		.index-content .blue-button:hover{
		    background-color: #dadada;
		    color: #002E5B;
		}
	}
<div class="index-content">
        <div class="container">
                <a href="blog-ici.html">
                    <div class="col-lg-12">
                        <div class="card">
                            <img src="https://image.ibb.co/nJ97Go/bmw.jpg"></img>
                            <h4>BMW NEW MODELS</h4>
                            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                            <a href="blog-ici.html" class="blue-button">Read More</a>
                        </div>
                    </div>
                </a>
        </div>
    </div

最佳答案

你想要这样的东西吗?我刚刚为这些内容添加了一个父 div 及其在 min-width: 768px

上的绝对位置

.index-content a:hover {
  color: black;
  text-decoration: none;
}

.index-content {
  margin-bottom: 20px;
  padding: 50px 0px;
}

.index-content .row {
  margin-top: 20px;
}

.index-content a {
  color: black;
}

.index-content .card {
  background-color: #FFFFFF;
  padding: 0;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
  box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}

.index-content .card:hover {
  box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
  color: black;
}

.index-content .card img {
  width: 100%;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

.index-content .card h4 {
  margin: 20px;
}

.index-content .card p {
  margin: 20px;
  opacity: 0.65;
}

.index-content .blue-button {
  width: 100px;
  -webkit-transition: background-color 1s, color 1s;
  /* For Safari 3.1 to 6.0 */
  transition: background-color 1s, color 1s;
  min-height: 20px;
  background-color: #002E5B;
  color: #ffffff;
  border-radius: 4px;
  text-align: center;
  font-weight: lighter;
  margin: 0px 20px 15px 20px;
  padding: 5px 0px;
  display: inline-block;
}

.index-content .blue-button:hover {
  background-color: #dadada;
  color: #002E5B;
}

@media (max-width: 768px) {
  .index-content .col-lg-4 {
    margin-top: 20px;
  }
}

@media (min-width: 768px) {
  .card {
    position: relative;
  }
  .card-content {
    position: absolute;
    bottom: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
  }
  .card-content h4,
  .card-content p {
    color: white;
    width: 100%;
    float: left;
    margin: 0 0 5px;
  }
  .card-content a {
    float: right;
  }
  .index-content .card h4,
  .index-content .card p {
    padding: 15px 20px;
    margin: 0;
  }
  .index-content .card p {
    padding: 0 20px 15px;
    margin: 0;
  }
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="index-content">
  <div class="container">
    <a href="blog-ici.html">
      <div class="col-lg-12">
        <div class="card">
          <img src="https://image.ibb.co/nJ97Go/bmw.jpg">


          <div class="card-content">
            <h4>BMW NEW MODELS</h4>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            <a href="blog-ici.html" class="blue-button">Read More</a>
          </div>



        </div>
      </div>
    </a>
  </div>
</div>

关于html - 仅在小型设备上 Bootstrap 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51301597/

相关文章:

javascript - 解析html页面后触发点击事件

javascript - 仅使用 CSS 关闭模式

css - 无法覆盖 Twitter Bootstrap btn 类默认字体大小

javascript - 如何让模态框在 x 秒内关闭?

html - 让 Bootstrap 行中的最后一列占据视口(viewport)宽度的其余部分

javascript - 调整图像大小以完美适应可变尺寸的 div

html - 在 Bootstrap 按钮上放置 H 标签

css - 960 网格的 clearfix 与 HTML5 Boilerplate 的 clearfix - 有什么区别?

responsive-design - 带有子显示的子内联 block 的 CSS div 没有保持高度

javascript - 我们可以在 `<tr></tr>` 之后使用嵌套表吗?