Welcome!

Machine Learning Authors: Pat Romanski, Liz McMillan, Yeshim Deniz, Elizabeth White, Zakia Bouachraoui

Related Topics: Machine Learning

Machine Learning : Article

Adding Rounded Corners to HTML with CSS

Using the Border Radius Setting in CSS 3

As the name implies, a Cascading Style Sheet, or CSS, is a document that describes the visual style of your content. Web designers have been leveraging Cascading Styles Sheets as a tool to control content placement and text presentation in web pages for over ten years.

With the advent of Web 2.0 applications, it is even more important to add control to your designs. The Webkit open source project, used in Apple’s Safari and Google’s Chrome, and Mozilla’s FireFox, recognize that CSS must be flexible enough to meet your design needs. To this end, there is now included in the latest versions advanced CSS styles. One of these new features is the ability to add rounded corners to objects.

Adding rounded corners is not a new technique for the web. The effect, however, is created through using images and tables to create the illusion of rounded corners. Adding images to the pages ensures that the page takes longer to load and makes modifying the page later more complex.

A simpler approach is to use the proposed Corner-Radius CSS definition that is currently supported in FireFox 3.0, Safari 3.0, Mobile Safari on your iPhone/iPod Touch and Google’s Chrome. The Corner-Radius definition is line you can add to your CSS style. The following HTML code has a style embedded that changes the presentation of the block of text to have rounded corners with a heavy, black outline:

<p style="-moz-border-radius: 10px;-webkit-border-radius: 10px;border: 4px solid #FF0000;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porta, lacus in cursus cursus, justo purus fringilla nisi, quis cursus urna velit vel felis. Nulla ac mi. Phasellus sodales dui vel tortor. Praesent dignissim. Vestibulum vulputate nibh rutrum purus. Nulla ante. Sed porta. Vestibulum commodo, mi nec tincidunt laoreet, urna risus ornare libero, in imperdiet sapien enim vel nisi.</p>

The style description has been highlighted in bold. Your content will now look like this on your Web page:

As you can see, the block of text now has a solid red line with rounded corners. It is this style description that controls the size of the radius, not an image. You can then easily modify the description as shown below:

-moz-border-radius: 10px

-webkit-border-radius: 10px

The standard is currently only in proposal stage and has not been adopted by all Web browsers. For this reason, you need to add two border-radius style descriptions: One, for FireFox (-moz-border-radius); and one for Safari/Chrome (-webkit-border-radius). Changing the value of the border-radius will change the size of the border. For instance:

Border-radius: 15 px

Border-radius:25 px

Border-radius:45 px

As you increase the border radius, you will also have to add additional styles, such as padding, to ensure that your border does not cut through your text as is shown in the example of border-radius:45 px. Here is how you can add padding to manage your style.

<p style="-moz-border-radius: 45px;-webkit-border-radius: 45px;border: 4px solid #FF0000;padding: 12px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porta, lacus in cursus cursus, justo purus fringilla nisi, quis cursus urna velit vel felis. Nulla ac mi. Phasellus sodales dui vel tortor. Praesent dignissim. Vestibulum vulputate nibh rutrum purus. Nulla ante. Sed porta. Vestibulum commodo, mi nec tincidunt laoreet, urna risus ornare libero, in imperdiet sapien enim vel nisi.</p>

The content now looks like this:

Creating interactive tabs

The new border-radius style also has the option of allowing you to control which corner you want the border to appear on. This can be useful when you want to create tabs for you web page. For instance, the following style will add tabs to the top left and top right corners:

.standardTabEffect{

font-family: Arial, Helvetica, sans-serif;

font-size: 15px;

background-color: #FFFF00;

-moz-border-radius-topleft: 15px;

-moz-border-radius-topright: 15px;

-webkit-border-radius-topleft: 15px;

-webkit-border-radius-topright: 15px;

border: 4px solid #FF0000;

padding: 10px;

color: #FF0000;

text-decoration: none;

font-weight: bold;

}

This style can now be added to a central style sheet link to content on your page. The content on your page can now reference the style. You can add the following HTML to see this effect:

<a class="standardTabEffect" href="#">This is Tab 1</a><a class="standardTabEffect" href="#">This is Tab 2</a><a class="standardTabEffect" href="#">This is Tab 3</a>

When you view the page, the HTML above will look like this:

As you might imagine, you can inherit existing CSS formatting into your border-radius designs. For instance, you can add a simple roll over effect when you include the following style description. The important part is to add the “:hover” parameter. This instructs the Web browser to only use this style when a user is rolling over the link with their mouse:

.standardTabEffect:hover{

background-color: #FF0000;

border: 4px solid #FFFF00;

color: #FFFF00;

}

The action looks like this:

Without using complex images or tables, you have created a series of tabs that can be easily managed through your CSS and HTML.

The Caveat
Applying rounded corners to your design is a must for almost any Web site. There are some caveats, however, to using rounded corners in CSS. The first one is a biggie: NO VERSION OF MICROSOFT’S INTERNET EXPLORER SUPPORTS CSS CORNERS. Microsoft does a good job of talking up their support for CSS, but what they fail to mention is their lack of support for advanced CSS3 standards. Unfortunately, this is a big caveat for many designers at 70% of all Internet users are coming to your site using Internet Explorer.

More Stories By Matthew David

Matthew has written books for Friends of Ed, Pearson Press, New Riders, Wiley, Focal Press and Peach Pit. He is also experience at leading teams top deliver bestselling titles books that come with accompanying video training and media. An example is Flash MX Magic, a book written by 7 authors, with an accompanying web site and CD. The book sold over 45,000 copies in 12 languages. Matthew is also the author of 400+ articles.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


CloudEXPO Stories
On-premise or off, you have powerful tools available to maximize the value of your infrastructure and you demand more visibility and operational control. Fortunately, data center management tools keep a vigil on memory contestation, power, thermal consumption, server health, and utilization, allowing better control no matter your cloud's shape. In this session, learn how Intel software tools enable real-time monitoring and precise management to lower operational costs and optimize infrastructure for today even as you're forecasting for tomorrow.
Isomorphic Software is the global leader in high-end, web-based business applications. We develop, market, and support the SmartClient & Smart GWT HTML5/Ajax platform, combining the productivity and performance of traditional desktop software with the simplicity and reach of the open web. With staff in 10 timezones, Isomorphic provides a global network of services related to our technology, with offerings ranging from turnkey application development to SLA-backed enterprise support. Leading global enterprises use Isomorphic technology to reduce costs and improve productivity, developing & deploying sophisticated business applications with unprecedented ease and simplicity.
While a hybrid cloud can ease that transition, designing and deploy that hybrid cloud still offers challenges for organizations concerned about lack of available cloud skillsets within their organization. Managed service providers offer a unique opportunity to fill those gaps and get organizations of all sizes on a hybrid cloud that meets their comfort level, while delivering enhanced benefits for cost, efficiency, agility, mobility, and elasticity.
DevOps has long focused on reinventing the SDLC (e.g. with CI/CD, ARA, pipeline automation etc.), while reinvention of IT Ops has lagged. However, new approaches like Site Reliability Engineering, Observability, Containerization, Operations Analytics, and ML/AI are driving a resurgence of IT Ops. In this session our expert panel will focus on how these new ideas are [putting the Ops back in DevOps orbringing modern IT Ops to DevOps].
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understanding as the environment changes.