How to Make Text Flow Around Rounded Divs?

Barbara Streisand
Release: 2024-11-15 01:50:02
Original
369 people have browsed it

How to Make Text Flow Around Rounded Divs?

Enhancing Text Placement within Rounded Divs

Creating rounded divs that seamlessly accommodate text can be achieved using CSS techniques. However, by default, rounded divs often display text in a squared format.

Current Situation:

As demonstrated in the provided JSFiddle (http://jsfiddle.net/kUJq8/), the following CSS produces a round div with squared text:

div {
    width: 320px;
    height: 320px;
    border-radius: 50%;
    background: #333;
    color: #FFF;
}
Copy after login

Solution 1: Shape-Outside

Modern browsers support the shape-outside property, offering a direct solution for wrapping text around complex shapes. For a circular shape, the syntax would be:

div {
    width: 320px;
    height: 320px;
    shape-outside: circle(50%);
    background: #333;
    color: #FFF;
}
Copy after login

Note: Browser support for shape-outside should be considered.

Solution 2: Pseudo Element Gradients

Alternative methods involve using images or gradients to define the circular shape. With the latter approach, four pseudo elements are employed:

div:not([class]) {
  width: 10em;
  height: 10em;
  border-radius: 50%;
  background: #333;
}

div[class]:before {
  /* ... */
}

div[class][id]:before {
  /* ... */
}

div[class]:after {
  /* ... */
}

div[class][id]:after {
  /* ... */
}
Copy after login

By using carefully positioned radial gradients, these pseudo elements effectively create the illusion of a circular shape. When combined with the main div's rounded corners, the text wraps around the circle as desired.

The above is the detailed content of How to Make Text Flow Around Rounded Divs?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template