整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

一篇文章带你了解CSS 文本样式

家好,我是IT共享者,人称皮皮。这篇文章我们来讲讲CSS的文本样式。

一、文本颜色Color

颜色属性被用来设置文字的颜色。

颜色是通过CSS最经常的指定:

  • 十六进制值 - 如"#FF0000"。
  • 一个RGB值 - "RGB(255,0,0)"。
  • 颜色的名称 - 如"红"。

一个网页的文本颜色是指在主体内的选择:

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=640, user-scalable=no">
        <title>项目</title>
        <style>
            body {
                color: blue;
            }


            h1 {
                color: #00ff00;
            }


            h2 {
                color: rgb(255, 0, 0);
            }
</style>
    </head>


    <body>
        <h2>hello world</h2>
        <h1>welcome to CaoZhou</h1>
    </body>


</html>

注:对于W3C标准的CSS:如果你定义了颜色属性,你还必须定义背景色属性。


二、属性

1. text-align 文本的对齐方式

文本排列属性是用来设置文本的水平对齐方式。

文本可居中或对齐到左或右,两端对齐。

当text-align设置为"justify",每一行被展开为宽度相等,左,右外边距是对齐(如杂志和报纸)。

<!doctype html>
<html lang="en">


    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            h1 {
                text-align: center;
            }


            p.date {
                text-align: right;
            }


            p.main {
                text-align: justify;
            }
</style>
    </head>


    <body>


        <p class="date">2015 年 3 月 14 号</p>
        <p class="main"> 从前有个书生,和未婚妻约好在某年某月某日结婚。到那一天,未婚妻却嫁给了别人。书生受此打击, 一病不起。  这时,路过一游方僧人,从怀里摸出一面镜子叫书生看。书生看到茫茫大海,一名遇害的女子一丝不挂地躺在海滩上。路过一人, 看一眼,摇摇头,走了。又路过一人,将衣服脱下,给女尸盖上,走了。再路过一人,过去,挖个坑,小心翼翼把尸体掩埋了。  僧人解释道, 那具海滩上的女尸,就是你未婚妻的前世。你是第二个路过的人,曾给过他一件衣服。她今生和你相恋,只为还你一个情。但是她最终要报答一生一世的人,是最后那个把她掩埋的人,那人就是他现在的丈夫。书生大悟,病愈。


        </p>
        <p><b>注意:</b> 重置浏览器窗口大小查看 "justify" 是如何工作的。</p>
    </body>


</html>

2. text-decoration文本修饰

text-decoration 属性用来设置或删除文本的装饰。

从设计的角度看 text-decoration属性主要是用来删除链接的下划线:

<!doctype html>
<html lang="en">


    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            .none {}


            .del {
                text-decoration: none;
            }
</style>
    </head>


    <body>
        <p>原来的样子</p>
        <a href="#" class="none">wwwwwwwwwwwwwwwwww</a>
        <p>去掉下划线</p>
        <a href="#" class="del">wwwwwwwwwwwwwwwwwwwww</a>
    </body>


</html>

也可以这样装饰文字:

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=640, user-scalable=no">
        <title>项目</title>
        <style>
            h1 {
                text-decoration: overline;
            }


            h2 {
                text-decoration: line-through;
            }


            h3 {
                text-decoration: underline;
            }
</style>
    </head>


    <body>
        <h1>This is heading 1</h1>
        <h2>This is heading 2</h2>
        <h3>This is heading 3</h3>
    </body>


</html>

注:不建议强调指出不是链接的文本,因为这常常混淆用户。


3. text-transform文本转换

text-transform文本转换属性是用来指定在一个文本中的大写和小写字母。

  • uppercase:转换为全部大写。
  • lowercase:转换为全部小写。
  • capitalize :每个单词的首字母大写。
<!DOCTYPE html>
<html>


    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=640, user-scalable=no">
        <title>项目</title>
        <style>
            p.uppercase {
                text-transform: uppercase;
            }


            p.lowercase {
                text-transform: lowercase;
            }


            p.capitalize {
                text-transform: capitalize;
            }
</style>
    </head>


    <body>
        <p class="uppercase">This is some text.</p>
        <p class="lowercase">This is some text.</p>
        <p class="capitalize">This is some text.</p>
    </body>


</html>

4. text-indent文本缩进

text-indent文本缩进属性是用来指定文本的第一行的缩进。

p {text-indent:50px;}

5. letter-spacing 设置字符间距

增加或减少字符之间的空间。

<style>
     h1 {
       letter-spacing:2px;
}
      h2 {
        letter-spacing:-3px;
}
</style>

6. line-height设置行高

指定在一个段落中行之间的空间。

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=640, user-scalable=no">
        <title>项目</title>
        <style>
            p.small {
                line-height: 70%;
            }


            p.big {
                line-height: 200%;
            }
</style>
    </head>


    <body>
        <p>
            This is a paragraph with a standard line-height.<br> This is a paragraph with a standard line-height.<br> The default line height in most browsers is about 110% to 120%.<br>
        </p>


        <p class="small">
            This is a paragraph with a smaller line-height.<br> This is a paragraph with a smaller line-height.<br> This is a paragraph with a smaller line-height.<br> This is a paragraph with a smaller line-height.<br>
        </p>


        <p class="big">
            This is a paragraph with a bigger line-height.<br> This is a paragraph with a bigger line-height.<br> This is a paragraph with a bigger line-height.<br> This is a paragraph with a bigger line-height.<br>
        </p>


    </body>


</html>

7. word-spacing 设置字间距

增加一个段落中的单词之间的空白空间。

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=640, user-scalable=no">
        <title>项目</title>
        <style type="text/css">
            p {
                word-spacing: 30px;
            }
</style>
    </head>


    <body>


        <p>
            This is some text. This is some text.
        </p>


    </body>


</html>

8. vertical-align 设置元垂直居中

设置文本的垂直对齐图像。

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=640, user-scalable=no">
        <title>项目</title>
        <style>
            img{
                width: 200px;
                height: 100px;
            }
            img.top {
                vertical-align: text-top;


            }


            img.bottom {
                vertical-align: text-bottom;


            }
</style>
    </head>


    <body>
        <p>An <img src="img/logo.png"  /> image with a default alignment.</p>
        <p>An <img class="top" src="img/logo.png" /> image with a text-top alignment.</p>
        <p>An <img class="bottom" src="img/logo.png" /> image with a text-bottom alignment.</p>
    </body>


</html>

9. text-shadow 设置文本阴影

设置文本阴影。

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=640, user-scalable=no">
        <title>项目</title>
        <style>
         h1{
            text-shadow: 2px 2px #FF0000;
     }
</style>
    </head>


    <body>
    <h1>Text-shadow effect</h1>
    </body>


</html>

三、总结

本文主要介绍了CSS文本样式实际应用中应该如何去操作,通过讲解文本中对应的属性去改变文本的表现形式。使用丰富的效果图的展示,能够更直观的看到运行的效果,能够更好的理解。使用Html语言,代码结构更佳的清晰,能够帮助你更好的学习。

、前言

本控件主要用来作为一个简单的图片浏览器使用,可以上下翻页显示图片,图片还可以开启过度效果比如透明度渐变,应用场景有查看报警图片运行图片等。此控件非本人原创,来源于网络,我只是修正了好多处BUG,并完善了各种操作方式。比如增加鼠标右键清空、增加背景色、增加键盘翻页、增加移动到第一张/末一张/上一张/下一张 等,

控件没有什么难度,主要就是打开文件夹,自动计算文件夹下的所有文件存储到队列中,队列中可以是图片的完整路径,也可以是图片,可以切换,如果选择内存加载模式则会自动将路径转为图片,这样的话有个好处,就是在翻页查看图片的时候速度会非常的快,因为直接显示的是内存中的图片,而不需要重新加载路径,毕竟路径加载图片又需要重新读取硬盘。

二、实现的功能

* 1:增加鼠标右键清空

* 2:增加设置背景色

* 3:增加设置间距和翻页图标大小

* 4:增加设置是否拉伸填充显示

* 5:增加设置是否渐变显示图像

* 6:增加设置键盘翻页

* 7:增加移动到第一张/末一张/上一张/下一张

* 8:修正内存泄露BUG及其他BUG

三、效果图

四、核心代码

ImageView::ImageView(QWidget *parent) :	QWidget(parent)
{
 setStyleSheet(".QToolButton{background-color:rgba(0,0,0,0);border-style:none;}");
 bgColorStart = QColor(100, 100, 100);
 bgColorEnd = QColor(60, 60, 60);
 bottomSpace = 10;
 buttonSpace = 10;
 icoSize = QSize(65, 65);
 fade = false;
 fill = false;
 keyMove = false;
 totalNum = 0;
 currentIndex = -1;
 num = new ImageNum(this);
 connect(this, SIGNAL(totalNumChanged(int)), num, SLOT(setTotalNum(int)));
 connect(this, SIGNAL(currentIndexChanged(int)), num, SLOT(setCurrentIndex(int)));
 preButton = new QToolButton(this);
 nextButton = new QToolButton(this);
 preButton->setIconSize(icoSize);
 nextButton->setIconSize(icoSize);
 preButton->setIcon(QIcon(":/image/btn_pre_normal.png"));
 nextButton->setIcon(QIcon(":/image/btn_next_normal.png"));
 connect(preButton, SIGNAL(clicked()), this, SLOT(movePrevious()));
 connect(nextButton, SIGNAL(clicked()), this, SLOT(moveNext()));
 opacity = 1.0;
 timer = new QTimer(this);
 timer->setInterval(50);
 connect(timer, SIGNAL(timeout()), this, SLOT(doFading()));
 QAction *action_load = new QAction("载入", this);
 connect(action_load, SIGNAL(triggered(bool)), this, SLOT(load()));
 this->addAction(action_load);
 QAction *action_clear = new QAction("清空", this);
 connect(action_clear, SIGNAL(triggered(bool)), this, SLOT(clear()));
 this->addAction(action_clear);
 this->setContextMenuPolicy(Qt::ActionsContextMenu);
 calcGeo();
}
ImageView::~ImageView()
{
 if (timer->isActive()) {
 timer->stop();
 }
}
void ImageView::paintEvent(QPaintEvent *)
{
 QPainter painter(this);
 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
 drawBg(&painter);
 if (totalNum > 0) {
 drawImage(&painter);
 }
}
void ImageView::drawBg(QPainter *painter)
{
 painter->save();
 painter->setPen(Qt::NoPen);
 QLinearGradient bgGradient(QPoint(0, 0), QPoint(0, height()));
 bgGradient.setColorAt(0.0, bgColorStart);
 bgGradient.setColorAt(1.0, bgColorEnd);
 painter->setBrush(bgGradient);
 painter->drawRect(rect());
 painter->restore();
}
void ImageView::drawImage(QPainter *painter)
{
 painter->save();
 painter->setOpacity(opacity);
 if (fill) {
 painter->drawImage(rect(), currentImage);
 painter->restore();
 } else {
 //按照比例自动居中绘制
 int imageWidth = currentImage.width();
 int imageHeight = currentImage.height();
 int imageX = rect().center().x() - imageWidth / 2;
 int imageY = rect().center().y() - imageHeight / 2;
 QPoint point(imageX, imageY);
 painter->drawImage(point, currentImage);
 painter->restore();
 }
}
void ImageView::keyPressEvent(QKeyEvent *keyEvent)
{
 if (keyEvent->key() == Qt::Key_Left || keyEvent->key() == Qt::Key_Up) {
 movePrevious();
 } else if (keyEvent->key() == Qt::Key_Right || keyEvent->key() == Qt::Key_Down) {
 moveNext();
 }
}
void ImageView::resizeEvent(QResizeEvent *)
{
 calcGeo();
}
void ImageView::showEvent(QShowEvent *)
{
 calcGeo();
}
void ImageView::calcGeo()
{
 QPoint prePoint(buttonSpace, (height() - preButton->height()) / 2);
 preButton->move(prePoint);
 QPoint nextPoint(width() - buttonSpace - preButton->width(), (height() - preButton->height()) / 2);
 nextButton->move(nextPoint);
 QPoint numPoint(width() / 2 - num->width() / 2, height() - bottomSpace - preButton->height() / 2 - num->height() / 2);
 num->move(numPoint);
}
void ImageView::doFading()
{
 opacity += 0.05;
 if (opacity > 1.0) {
 opacity = 1.0;
 timer->stop();
 }
 update();
}

六、控件介绍

1. 超过149个精美控件,涵盖了各种仪表盘、进度条、进度球、指南针、曲线图、标尺、温度计、导航条、导航栏,flatui、高亮按钮、滑动选择器、农历等。远超qwt集成的控件数量。

2. 每个类都可以独立成一个单独的控件,零耦合,每个控件一个头文件和一个实现文件,不依赖其他文件,方便单个控件以源码形式集成到项目中,较少代码量。qwt的控件类环环相扣,高度耦合,想要使用其中一个控件,必须包含所有的代码。

3. 全部纯Qt编写,QWidget+QPainter绘制,支持Qt4.6到Qt5.12的任何Qt版本,支持mingw、msvc、gcc等编译器,支持任意操作系统比如windows+linux+mac+嵌入式linux等,不乱码,可直接集成到Qt Creator中,和自带的控件一样使用,大部分效果只要设置几个属性即可,极为方便。

4. 每个控件都有一个对应的单独的包含该控件源码的DEMO,方便参考使用。同时还提供一个所有控件使用的集成的DEMO。

5. 每个控件的源代码都有详细中文注释,都按照统一设计规范编写,方便学习自定义控件的编写。

6. 每个控件默认配色和demo对应的配色都非常精美。

7. 超过130个可见控件,6个不可见控件。

8. 部分控件提供多种样式风格选择,多种指示器样式选择。

9. 所有控件自适应窗体拉伸变化。

10. 集成自定义控件属性设计器,支持拖曳设计,所见即所得,支持导入导出xml格式。

11. 自带activex控件demo,所有控件可以直接运行在ie浏览器中。

12. 集成fontawesome图形字体+阿里巴巴iconfont收藏的几百个图形字体,享受图形字体带来的乐趣。

13. 所有控件最后生成一个dll动态库文件,可以直接集成到qtcreator中拖曳设计使用。

14. 目前已经有qml版本,后期会考虑出pyqt版本,如果用户需求量很大的话。

先准备一个适合做背景图片的图片,可以百度网站背景图片,选取一张背景图片,下载到桌面,背景图片命名为:bj.jpg。然后登陆dedecms后台,点击模模块-点击文件管理器,选取文件管理器中的templets文件夹。

点击进入templets文件夹,点击defalut后进入images文件夹,上传背景图片bj.jpg文件。

打开网站首页,按F12调试(1箭头),找到控制首页背景的css样式表,注意找一下控制首页的css样式表的地址。

找到之后是可以查到是样式html{ }在控制首页背景(2箭头),并找到控制首页样式html{ }(3箭头)所在的地址是http://临时域名/dede58/defalut/css/style.css,将鼠标箭头放在箭头3上面就可以显示出控制背景div的css样式。找到这个路径的地址,去找这个控制的文件style.css,在这个文件中找到html{ } 将html{ }中的内容删除,将以下代码加入其中,第一个是背景图片地址 第二个是图片位置居中显示 第三个是图片不重复 第四个图片设置固定 background-image:URL(../images/bj.jpg); background-position:center; background-repeat:no-repeat; background-attachment:fixed; 截图所示

保存一下,各种生成,即可完成dedecms的背景图片的设置。