recherche
  • Se connecter
  • S'inscrire
Réinitialisation du mot de passe réussie

Suivez les projets qui vous intéressent et découvrez les dernières actualités les concernant.

Effets de texte CSS3

Effets de texte CSS3

CSS3 contient plusieurs nouvelles fonctionnalités de texte.

Dans ce chapitre, vous découvrirez les propriétés de texte suivantes :

  • text-shadow

  • box-shadow

  • débordement de texte

  • retour à la ligne

  • saut de mot


Ombre de texte CSS3

En CSS3, la propriété text-shadow s'applique à l'ombre de texte.

Vous spécifiez l'ombre horizontale, l'ombre verticale, la distance de flou et la couleur de l'ombre :

Instance

Ajoutez une ombre au titre :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>php中文网(php.cn)</title>
    <style>
        h1
        {
            text-shadow: 5px 5px 5px #FF0000;
        }
    </style>
</head>
<body>
<h1>文本阴影效果!</h1>
</body>
</html>

Exécutez le programme et essayez-le


Propriété CSS3 box-shadow

La propriété CSS3 box-shadow en CSS3 convient aux ombres de boîte

Instance

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>php中文网(php.cn)</title>
    <style>
        div
        {
            width:300px;
            height:100px;
            background-color:yellow;
            box-shadow: 10px 10px 5px #ff2332;
        }
    </style>
</head>
<body>
<div>盒子阴影</div>
</body>
</html>

Exécutez le programme pour essayer il


L'ombre ajoute un effet de flou

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>php中文网(php.cn)</title>
    <style>
        div {
            width: 300px;
            height: 100px;
            padding: 15px;
            background-color: yellow;
            box-shadow: 10px 10px 5px #d93bb3;
        }
    </style>
</head>
<body>
<div>这是一个带有模糊效果的阴影</div>
</body>
</html>

Exécutez le programme pour l'essayer


Propriété Débordement de texte CSS3

La propriété de débordement de texte CSS3 spécifie comment le contenu de débordement doit être affiché à l'utilisateur

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
<style> 
div.test
{
white-space:nowrap; 
width:12em; 
overflow:hidden; 
border:1px solid #000000;
}
</style>
</head>
<body>
<p>以下 div 容器内的文本无法完全显示,可以看到它被裁剪了。</p>
<p>div 使用 &quot;text-overflow:ellipsis&quot;:</p>
<div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box</div>
<p>div 使用 &quot;text-overflow:clip&quot;:</p>
<div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div>
<p>div 使用自定义字符串 &quot;text-overflow: >>&quot;(只在 Firefox 浏览器下有效):</p>
<div class="test" style="text-overflow:'>>';">This is some long text that will not fit in the box</div>
</body>
</html>

Exécutez le programme pour l'essayer


retour à la ligne CSS3

Si un le mot est trop long, ne rentre pas dans une zone, il s'étend à l'extérieur :

En CSS3, la propriété wrap vous permet de forcer le retour à la ligne du texte - même si cela signifie le diviser en un mot au milieu :

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title>
<style> 
p.test
{
width:11em; 
border:1px solid #000000;
word-wrap:break-word;
}
</style>
</head>
<body>
<p class="test"> This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p>
</body>
</html>

Exécuter Essayez le programme


CSS3 Word Breaking

La propriété CSS3 Word Breaking spécifie la règle de saut de ligne :

Le code CSS est le suivant :

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title>
<style> 
p.test1
{
width:9em; 
border:1px solid #000000;
word-break:keep-all;
}
p.test2
{
width:9em; 
border:1px solid #000000;
word-break:break-all;
}
</style>
</head>
<body>
<p class="test1"> This paragraph contains some text. This line will-break-at-hyphenates.</p>
<p class="test2"> This paragraph contains some text: The lines will break at any character.</p>
<p><b>注意:</b>  word-break 属性不兼容 Opera.</p>
</body>
</html>

Exécutez le programme et essayez-le



nouveau fichier
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <style> div { width: 300px; height: 100px; padding: 15px; background-color: yellow; box-shadow: 10px 10px 5px #d93bb3; } </style> </head> <body> <div>这是一个带有模糊效果的阴影</div> </body> </html>
Réinitialiser le code
Opération automatique
soumettre
Aperçu Clear
  • Recommandations de cours
  • Téléchargement du didacticiel