Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 用CSS对图像进行定心_Html_Css_Image_Centering - Fatal编程技术网

Html 用CSS对图像进行定心

Html 用CSS对图像进行定心,html,css,image,centering,Html,Css,Image,Centering,我试图简单地使用CSS和一些调整大小的机制将图像居中,但我就是不明白。它总是左对齐的 我们将不胜感激 代码如下: <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <style type="text/css"> .img { display: block; margin:0 auto; max-width: 900px;

我试图简单地使用CSS和一些调整大小的机制将图像居中,但我就是不明白。它总是左对齐的

我们将不胜感激

代码如下:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
 <style type="text/css">
    .img {
        display: block;
        margin:0 auto;
        max-width: 900px;
        top:10px;
        width: 60%;
        height: 70%;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <img class="img" src="gP.png" alt="..." />
</asp:Content>

  • 10/10/2007
  • 10/10/2007
  • 好极了!成功了当用户调整浏览器的大小时,有没有办法调整它的高度?我的意思是,始终保持图像大小为broser高度的80%?

    正如您所看到的,您的代码没有任何问题。可能您有其他元素的css与图像css交互

    试试这个,看看它是否有效:

    .img {
            display: block;
            margin:0 auto !important;
            max-width: 900px;
            top:10px;
            width: 60%;
            height: 70%;
    }
    

    不能将父元素与
    文本对齐:居中?能否创建一个小提琴来重新创建此错误?根据您提供的CSS,我看不到它:正如@circle73所指出的,这里有一个更新版本,其中父容器只应用了
    text align:center
    :不,没有这样做(可能是母版页上的内容?尝试添加
    padding:0 auto;
    padding:0 auto;也不起作用。我在上面的问题中发布了母版页代码。émais fácil assim..估计一个ler o teu código total e não Encentrei aárestás a inserir a imagem com a classeimg@Tiago卡索·塞贾·埃斯塔
    vais ter de a colo汽车车身
    div.container
    ou ento adicionares
    text align:center;
    a tua tag
    body
    tipo assim
    body{text align:center;}
    .img {
            display: block;
            margin:0 auto !important;
            max-width: 900px;
            top:10px;
            width: 60%;
            height: 70%;
    }