html - 使文本适合 div

标签 html css

我一直致力于重做我父亲创建于 90 年代的网站(呃),但我一直无法让文本适合 div 并水平对齐。我需要文本并排放置,以便它们适合 div。这是 jsfiddle 中页面的代码

示例 HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body>
    <div> 
        <img id="header" src="http://www.salesprofessionalsinc.com/images/new%20logo.jpg">
    </div>
    <div id="links">
        <div class="home">
            <a href="index.html"><span></span>Home</a>
        </div>
        <div class="home">
            <a href="insidestaff.html"><span></span>Inside Staff</a>
        </div>
        <div class="home">
            <a href="mission.html"><span></span>Our Mission</a> 
        </div>
    </div>

示例 CSS

div img#header{
    width: 50%;
    height: 15%;
    margin-left: 125px;
    margin-right: auto;
}center input#search{
    width: 300px;
    height: 45px;
    border: solid 1px black;
    margin-top: 55px;
    font-size: 25px;
}center button#searchbutt{
    border: solid 1px black;
    width: 65px;
    height: 30px;
}#searchbutt:hover{
    color: #FFF;
    background-color: #000;
}#searchbutt{
    background-color: #FFF;
    color: #000;
}#links{
    height: 40px;
    width: 100%;
    text-align: center;
    line-height: 40px;
}.home{
    width: 80px;
    text-align: center;
    height: 40px;
    background-color: white;
    color: black;
    padding-left: auto;
    padding-right: auto;
    display: inline-block;
    border: solid 1px black;
    vertical-align: middle;
}.DL{
    width: 95;
    text-decoration: none;
    text-align: center;
    height: 40px;
    background-color: white;
    color: black;
    padding-left: auto;
    padding-right: auto;
    display: inline-block;
    border: solid 1px black;
}.home a{
    text-decoration: none;
    color: gray;
}.DL a{
    text-decoration: none;
    color: gray;
}div center a#DLbutt{
    border: solid 1px black;
    width: 100px;
    height: 50px;
    background-color: black;
}div center a#DLbutt{
    text-decoration: none;
    color: gray;
}#download{
    padding-top: 30px;
}html{
     background-image: url("watermark.gif");
}.home a span{
     position:absolute; 
     width:100%;
     height:100%;
     top:0;
     left: 0;
     display: inline-block;
     vertical-align: middle;
     line-height: normal;
}

我需要“我们的使命部分”在同一个 div 中。

最佳答案

您需要为 div.home 设置显示为 display: table-cell 然后删除您拥有的 line-height为这些设定。这应该会自动为您对齐文本。

div img#header {
    width: 50%;
    height: 15%;
    margin-left: 125px;
    margin-right: auto;
}
#links {
    height: 40px;
    margin-left: 125px;
    text-align: center;
    display: inline-block;
}
.home {
    width: 80px;
    text-align: center;
    height: 40px;
    background-color: white;
    color: black;
    padding-left: auto;
    padding-right: auto;
    display: table-cell;
    border: solid 1px black;
    vertical-align: middle;
}
.home a {
    text-decoration: none;
    color: gray;
}

http://jsfiddle.net/03syn1to/

关于html - 使文本适合 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30353358/

相关文章:

javascript - 使用短\长文本垂直对齐按钮中的文本

html - 如何使单击按钮的效果持续 0.5 秒?

html - 将菜单栏中的一项设置为默认值(首次启动网页时)

css - PrimeNG:p-inputNumber 的 CSS 背景

HTML CSS h3 iframe 定位

Html5 全屏视频

html - 如何显示 div onclick 选项卡的内容

html - 在水平导航中均匀分布链接

javascript - 在 JQuery Id 选择器的 .css() 方法中指定输入类型

javascript - JSFiddle 代码在我自己的页面中不起作用