DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. CSS Twitter Bootstrap Alert Boxes

CSS Twitter Bootstrap Alert Boxes

Paul Underwood user avatar by
Paul Underwood
·
Aug. 23, 12 · Interview
Like (0)
Save
Tweet
Share
48.72K Views

Join the DZone community and get the full member experience.

Join For Free

Twitter Bootstrap

Twitter bootstrap is a front-end framework designed to allow you to have a framework to start all your web projects on. The framework comes with so many features from grids, responsive design, typography, forms, tables, buttons, navigation, labels, alerts and progress bars just to name a few.

Twitter bootstrap is a github projects and is design for the web community by the web community. If you have something to add to it or want to download it you can see the project on github.

Twitter Bootstrap

In this post we are going to look at one of my favourite features of the bootstrap...alert boxes. These are perfect to display a small message on the screen for different scenarios.

There are a few alert boxes that come with the framework these are:

  • Messages
  • Error
  • Success
  • Information

Alert Message

All of the alert boxes in the Twitter bootstrap will use the alert class. This sets the styling which all the alert boxes will use but for the other boxes we will just change the colours to match the scenario.

.alert {
padding: 8px 35px 8px 14px;
margin-bottom: 18px;
color: #c09853;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
background-color: #fcf8e3;
border: 1px solid #fbeed5;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.alert-heading {
color: inherit;
}
.alert .close {
position: relative;
top: -2px;
right: -21px;
line-height: 18px;
}

The HTML to call these are very simple just add the CSS class to a outer div or paragraph tag.

<div class="alert">Example of an alert box.</div>

Success

The success alert box will be used when the user successfully completes a task all the CSS will do is override the colours of the standard alert box.

.alert-success {
color: #468847;
background-color: #dff0d8;
border-color: #d6e9c6;
}

When you use this CSS class you need to use both the alert CSS and the alert-success CSS.

<div class="alert alert-success">Example of the successful alert box</div>

Danger or Error

The error alert box works the same as the success box it is just used to change the colour of the background and text.

.alert-danger,
.alert-error {
color: #b94a48;
background-color: #f2dede;
border-color: #eed3d7;
}

Again you need to use both the alert CSS and the alert-error CSS.

<div class="alert alert-error">Example of the error alert box</div>

Information

The last style is the information style, used to highlight a message to the user by just using the CSS class alert-info.

.alert-info {
color: #3a87ad;
background-color: #d9edf7;
border-color: #bce8f1;
}
<div class="alert alert-info">Example of the information alert box</div>

Styling Blocks

Along with the different scenario styling Twitter bootstrap also gives you additional CSS classes to further style the alert boxes.

Adding a class of alert-block you increase the padding of the box.
.alert-block {
padding-top: 14px;
padding-bottom: 14px;
}

The next styling will reduce the margins on the paragraph tags inside the alert-block.

.alert-block > p,
.alert-block > ul {
margin-bottom: 0;
}
.alert-block p + p {
margin-top: 5px;
}

The HTML to add additional padding can be used by adding the alert-block CSS class to one of the alert boxes.

<div class="alert alert-information alert-block">
Example of the information alert box
</div>

That's all the alert boxes you currently get with the Twitter bootstrap, of course there are loads of other alert box types you would want to add so why not contribute to the project and add new ones.

Curator's note: This is a prepublished article.  Due to technical difficulties, there are some examples that could not be included.  The examples can be found by clicking the source link below.

CSS Bootstrap (front-end framework) twitter

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Continuous Development: Building the Thing Right, to Build the Right Thing
  • Using the PostgreSQL Pager With MariaDB Xpand
  • What Is Policy-as-Code? An Introduction to Open Policy Agent
  • Express Hibernate Queries as Type-Safe Java Streams

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: