图片居中

思路

借助div的background-size 的 cover这个属性等比例缩放图片
配合center就可以实现居中覆盖,裁剪多余
最终实现:等比例缩放+居中+完全覆盖+边界裁剪

div.full-img{
            background-size: cover;
            background: url("http://img4.duitang.com/uploads/item/201310/14/20131014172031_4sUms.jpeg") no-repeat center center;
            width: 80vw;
            height: 80vw;
        }
示例代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <style>
        @keyframes rainbow {
            0% {
                background: steelblue;
            }
            100% {
                background: yellowgreen;
            }
        }

        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        .full-screen {
            width: 100%;
            height: 100%;
            background: grey;
        }

        .center {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        div.center:hover {
            animation: 1s cubic-bezier(0.215, 0.610, 0.355, 1) rainbow infinite alternate-reverse forwards;
          }

        .large {
            height: 10rem;
            width: 10rem;
            background: ghostwhite;
        }

        a,
        a:link,
        a:visited {
            color: #444;
            text-decoration: none;
            transition: all 800ms cubic-bezier(0.215, 0.610, 0.355, 1)
        }

        .center:hover {
            color: blanchedalmond;
        }

        .center::before {
            position: absolute;
            content: "\5B";
            left: 0rem;
            opacity: 0;
        }

        .center:hover::before {
            position: absolute;
            content: "\5B";
            left: -1rem;
            opacity: 1;
            transition: all 800ms cubic-bezier(0.215, 0.610, 0.355, 1)
        }

        .center::after {
            position: absolute;
            content: "\5d";
            right: 0rem;
            opacity: 0;
        }

        .center:hover::after {
            position: absolute;
            content: "\5D";
            right: -1rem;
            opacity: 1;
            transition: all 800ms cubic-bezier(0.215, 0.610, 0.355, 1)
        }

        div.full-img{
            background-size: cover;
            background: url("http://img4.duitang.com/uploads/item/201310/14/20131014172031_4sUms.jpeg") no-repeat center center;
            width: 80vw;
            height: 80vw;
        }
    </style>
    <div class="full-screen">
        <div class="center full-img">
        </div>
    </div>
</body>

</html>

转载于:https://www.cnblogs.com/Lulus/p/8252828.html

在 LaTeX 中实现图片居中显示通常涉及两个方面:图片本身的居中以及图片标题(caption)的对齐方式。以下是一些常见的方法来实现图片居中显示: ### 图片居中显示 为了确保图片在页面上居中显示,可以在 `figure` 环境中使用 `\centering` 命令。这是一个基本的例子: ```latex \begin{figure}[!h] \centering \includegraphics[width=15cm]{100.eps} \caption{Franka manipulator.} \label{fig100} \end{figure} ``` 这段代码中的 `\centering` 命令确保了图片在其所在环境中水平居中[^1]。 ### 图片标题居中 如果希望图片的标题也居中显示,则需要额外加载 `caption` 宏包,并使用 `justification=centering` 选项。这可以通过在文档的导言区添加以下命令来实现: ```latex \usepackage[justification=centering]{caption} ``` 这样设置之后,所有图片的标题都会居中显示。然而,如果你还希望修改标题标签(如 "Figure 4:")后面的符号为句号而不是冒号,可以进一步调整 `caption` 宏包的选项,如下所示: ```latex \usepackage[justification=centering,labelsep=period]{caption} ``` 此设置不仅使标题居中,还将标签与标题文本之间的分隔符更改为句号[^1]。 ### 特定图片标题居中 如果你只想对某些特定的图片应用居中的标题,而不是全局设置,可以在这些图片所在的环境中局部地应用上述设置。例如: ```latex \usepackage{caption}% 用于支持局部设置 ... \begin{figure}[!h] \centering \includegraphics[width=15cm]{100.eps} \captionsetup{justification=centering,labelsep=period} \caption{Franka manipulator.} \label{fig100} \end{figure} ``` 在这个例子中,`\captionsetup` 命令用于局部配置特定图片的标题样式[^2]。 ### 多图并排居中 对于需要并排显示的多张图片,如果希望它们整体居中并且每张图片的标题也居中,可以这样做: ```latex \begin{figure}[!h] \centering \begin{minipage}{.5\textwidth} \centering \includegraphics[width=.8\linewidth]{image1.eps} \caption{First image.} \label{fig:image1} \end{minipage}% \begin{minipage}{.5\textwidth} \centering \includegraphics[width=.8\linewidth]{image2.eps} \caption{Second image.} \label{fig:image2} \end{minipage} \end{figure} ``` 这里使用了 `minipage` 环境来创建两个并列的小页面,每个小页面中包含一张图片及其标题。通过适当调整 `minipage` 的宽度和图片尺寸,可以保证两张图片并排且整体居中[^2]。 ### 整行图片居中 对于希望图片占据整个文本宽度的情况,可以使用 `figure*` 环境结合 `\centering` 和适当的宽度设置来实现: ```latex \begin{figure*} \centering \includegraphics[width=.95\linewidth]{./Figures/xxxx.eps} \caption{State transitions in the model.} \label{fg:state} \end{figure*} ``` 这里的 `figure*` 环境使得图片能够扩展到两栏布局中的整行宽度,而 `\centering` 则确保了图片和标题的居中显示[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值