Bootstrap中元素的padding重写(以超大屏幕Jumbotron为例)

Bootstrap可以说是前端第一框架,丰富的插件、跨移动和PC平台等优势使得Bootstrap很受前端开发者的青睐。笔者也是刚接触Bootstrap不久,对Bootstrap简单的代码实现强大的功能很是喜爱。但自己在写Bootstrap代码的过程中发现Bootstrap的组件插件很多都是需要重写的,否则在页面布局显示方面是达不到自己想要的效果的。其中Bootstrap的组件插件的样式经常要重写的莫过于pading、margin等了,这篇文章以重写Jumbotron的padding(其他的类似都是用覆盖的方法改变样式)为例,说说如何用覆盖的方法重写Bootstrap的一些组件的属性值。

先看一段代码:

<!DOCTYPE html>
<html>
<head>
   <title>Bootstrap超大屏幕(Jumbotron)</title>
   <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet">
   <script src="/scripts/jquery.min.js"></script>
   <script src="/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
   <div class="jumbotron">
      <h1>Show</h1>
      <p>This is a Jumbotron</p>
      <p><a class="btn btn-primary btn-lg" role="button">
         learn more</a>
      </p>
   </div>
</div>

</body>
</html>
运行后结果是这样的:

可以看到,文字的四周存在很多的“空白处”,有时这样的效果是我们不想要的。如何减少或去除这些所谓的“空白处”,其实很简单,我们只要修改一下Jumbotron的padding(填充)就行。问题是在哪修改和如何修改padding?

Just follow me……

我们在jumbotron的<div>的class里jumbotron的前面(因为这样级别能高于“jumbotron“)随便加上一个类名,如这里写个h,这样就能实现第一步了。然后我们再在<style></style>里写上自己想要的padding值,即可完成覆盖操作。代码如下:

<!DOCTYPE html>
<html>
<head>
    <title>bootstrap</title>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
   <script src="bootstrap/jq/jquery-2.1.4.min.js"></script>
   <script src="bootstrap/js/bootstrap.min.js"></script>
   <style type="text/css">
     .h.jumbotron{
         padding: 4px;
     }
   </style>
</head>
<body>
<div class="container">
   <div class="h jumbotron">
      <h1>show</h1>
      <p>This is a Jumbotron</p>
      <p><a class="btn btn-primary btn-lg" role="button">
         learn more</a>
      </p>
   </div>
</div>
</body>
</html>

运行,Bingo!

我们效果出来了


“空白处”减少了,你可以根据自己的需要修改属性值(margin等同样用类似方法可实现修改)。

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Bootstrap提供了一个Jumbotron组件,可以用于在页面上显示重要的信息或者是引导用户注意。 Jumbotron组件可以让文本容易阅读,同时可以在背景上添加一张大图或者一段视频。下面是一个Jumbotron的基本模板代码: ```html <div class="jumbotron"> <h1>Hello, world!</h1> <p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p> <p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a></p> </div> ``` 使用Jumbotron组件,可以通过添加`.jumbotron`类来创建一个Jumbotron。在这个例子,我们添加了一个大标题、一些文本和一个按钮。按钮使用了Bootstrap的`.btn`和`.btn-primary`类来样式化。 如果你想要让Jumbotron更适合大屏幕的显示,可以在外层容器上添加`.container-fluid`类。这将使Jumbotron组件扩展到整个屏幕宽度。下面是一个示例代码: ```html <div class="container-fluid"> <div class="jumbotron"> <h1>Hello, world!</h1> <p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p> <p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a></p> </div> </div> ``` 这样,Jumbotron组件就可以在超大屏幕上显示了。注意:由于Jumbotron组件会扩展到整个屏幕宽度,因此在使用时需要注意页面排版和响应式设计的问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值