html - 图像未居中,文本对齐 :center

标签 html css

html,

<div id="home_wrap">
            <div id="home_header">
                <div id="home_header_minitab">
                    <a class="modalbox" href="#login_frame" id="external_btn">Login</a>
                    <img src="topnavi_1.gif" /><img src="topnavi_2.gif" /><img src="topnavi_3.gif" /><img src="topnavi_4.gif" />

                </div>
                <!-- <div class="hr">
                <hr/>

                </div> -->
                <div id="line">

                </div>

                <div id="home_header_maintab">

                    <img id="home_navimenu_1" src="navimenu_1.gif" />
                    <img id="home_navimenu_2" src="navimenu_2.gif" />
                    <img id="home_navimenu_3" src="navimenu_3.gif" />

                </div>
            </div>
            <div id="home_container">

                <div id="home_content">

                    <img id="home_frontimg" src="frontimg.jpg" />
                </div>
            </div>
            <div id="home_sidebar">

                <img id="home_logo" src="logo.gif" />
                <div id="home_loginbox">

                    <img id="home_login_message" src="login_message.gif" />
                    <br/>
                    <input id="home_email_input" placeholder="       E-mail" />
                    <br/>
                    <input id="home_pw_input" placeholder="       PW"/>
                    <br/>
                    <img id="home_login_btn" src="home_login_btn.gif" />
                    <img id="home_pw_search_btn" src="home_pwsearch.gif" />
                </div>

            </div>

            <div id="home_footer">

                <div id="home_footer_bannerbar">
                    <img id="home_footer_banner_1" src="banner_1.png" /><img id="home_footer_banner_2" src="banner_2.jpg" /><img id="home_footer_banner_3" src="banner_3.png" />
                </div>
                <div id="home_footer_lastbar">
                    <div id="footer_line"></div>

                    <div id="home_footer_addressbar">
                        <img id="home_footer_bottomlogo" src="bottomlogo.gif" />
                        <img src="address.gif" />
                        <img id="home_footer_familysite" src="familysite.gif" />    
                    </div>

                </div>
            </div>
        </div>

CSS,

body{
margin-top: 0px;
margin-right: 0px;
margin-left: 0px;
margin-bottom: 0px;
}

#home_wrap{
    width: 100%;
    margin: 0 auto;

}
#home_header{
    width: 100%;
    height: 110px;
    /*background:orange;*/
}
#home_container{
    background-image:url('main_bg.gif');
    width:100%;
    height:430px;
    /*background:green;*/
    float:;
}
#home_loginbox{
    width: 222px;
    height: 355px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}
#home_login_message{
    padding-top: 50px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

#home_logo{
    /*width: 222px;
    height: 155px;*/
    padding-top: 10px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}



#line {
    background: #e6e6e6;
    width: 100%;
    height: 1px;
}
#footer_line{
    margin-bottom:40px;
    background: #e6e6e6;
    width: 100%;
    height: 1px;
}
#home_footer{
    width: 100%;
    height:auto;
    margin-top: 30px;
    /*background:yellow;*/
}
#home_footer_familysite{
    margin-left: 180px;
}
#home_footer_bottomlogo{
    margin-left: 20px;
}
#home_footer_banner_1{
    margin-left: 10px;
}
#home_footer_banner_2{
    margin-left: 80px;
}
#home_footer_banner_3{
    margin-left: 80px;
    height: 121px;
}
#home_footer_bannerbar{
    text-align: left;
    margin-bottom: 40px;
}
#home_sidebar{
    background-color:white;
    width:222px;
    height:510px;
    /*background:red;*/
    float:left;
    position:absolute;
    bottom:540px;
    left:20px;
    top:0px;
    border: 1px solid #bdbdbd;
}
#home_email_input{
    margin-left: 22px;
    margin-bottom: 10px;
    width: 176px;
    background: url(envelope.gif) no-repeat scroll 4px 3px;
}
#home_frontimg{
    text-align: center;
    display: table-cell;
    margin: 0;

}

#login_frame{
    width: 380px;
    height: 325px;
    background-image: url(loginbox_frame.gif)
}

#home_pw_input{
    margin-left: 22px;
    margin-bottom: 10px;
    width: 176px;
    background: url(lock.gif) no-repeat  5px -0.5px;
}
#home_header_minitab{
    width: 100%;
    float: right;
    text-align: right;
}
#line{
    margin-top:30px;
    float: right;
}
#home_header_maintab{
    margin-top:18px;
    width: 100%;
    float: right;

}
#home_login_btn{
    margin-left: 22px;
    margin-bottom: 10px;
}
#home_pw_search_btn{
    margin-left: 22px;
}
#home_navimenu_1{
    margin-left: 350px;
}
#home_navimenu_2{
    margin-left: 180px;
}
#home_navimenu_3{
    margin-left: 180px;
}


#home_content {
    background-color: transparent;
    width: auto;
    height: 430px;
    /*background-image: url('frontimg.jpg');
    background-repeat: no-repeat;
    background-attachment: fixed;

    background-position: center;*/
    /*background: pink;*/
    padding-left: 243px;
    text-align: center;

    display: block;
}

代码很长,但是

我的目标是让 frontimg.jpg 居中。

在这里,

<div id="home_container">

                <div id="home_content">

                    <img id="home_frontimg" src="frontimg.jpg" />
                </div>
            </div>

我尝试对这里的所有 div text-align: center,但它不起作用:(

当然,如果我制作一个简单的 div 和 img 标签以及文本对齐,它就可以工作。

在这种情况下我找不到原因。

最佳答案

使用 margin:0 auto;显示: block ;。这将使它到达中心。由于图像默认具有 display:inline-block; 特征。

关于html - 图像未居中,文本对齐 :center,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20373823/

相关文章:

javascript - 如何在转换后的数字旁边输出货币类型

javascript - 当我在 eclipse 浏览器中运行 url 时,HTML 表单未被验证它不起作用

html - 背景透明图像使文本变得丑陋且难以阅读 - CSS

html - 如何在 div 中为这些 div 设置动画?

css - 防止渐进式(逐行)加载背景图像

javascript 选择自定义光标 (svg)

angularjs - Bootstrap datetimepicker 在 Bootstrap 模式中使用时显示不一致

javascript - 如何将 href 链接到 TAB?

html - 无法重置 CSS 外观属性

javascript - CSS - 浏览器如何知道在实现固定表头表时如何使两个表的列保持同步?