Home >Web Front-end >CSS Tutorial >How Can I Create Rounded Outlines for Divs?

How Can I Create Rounded Outlines for Divs?

Barbara Streisand
Barbara StreisandOriginal
2024-11-30 15:31:18386browse

How Can I Create Rounded Outlines for Divs?

Can You Outline a Div with Rounded Corners?

Similar to the border-radius property, it's possible to give div elements rounded outlines. While you might think the border-radius property could do the trick, there's an alternative that offers more control: box-shadow.

For instance, if you have an input field with rounded borders and want to adjust the focus outline color, box-shadow can be employed. It provides a smooth look while also allowing for the simulation of a rounded outline. Here's how you can achieve this effect:

input, input:focus {
    border: none;
    border-radius: 2pt;
    box-shadow: 0 0 0 1pt grey;
    outline-color: transparent; /* for high contrast modes */
    transition: .1s;
}

/* Smooth outline with box-shadow: */
.text1:focus {
    box-shadow: 0 0 3pt 2pt cornflowerblue;
}

/* Hard "outline" with box-shadow: */
.text2:focus {
    box-shadow: 0 0 0 2pt red;
}

The above is the detailed content of How Can I Create Rounded Outlines for Divs?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn