草庐IT

html - 使文本适合 div

coder 2023-08-12 原文

我一直致力于重做我父亲创建于 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/

有关html - 使文本适合 div的更多相关文章

  1. ruby - 使用 ruby​​ 将 HTML 转换为纯文本并维护结构/格式 - 2

    我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h

  2. ruby-on-rails - Rails HTML 请求渲染 JSON - 2

    在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这

  3. ruby-on-rails - 使用 Sublime Text 3 突出显示 HTML 背景语法中的 ERB? - 2

    所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择

  4. ruby-on-rails - Nokogiri:使用 XPath 搜索 <div> - 2

    我使用Nokogiri(Rubygem)css搜索寻找某些在我的html里面。看起来Nokogiri的css搜索不喜欢正则表达式。我想切换到Nokogiri的xpath搜索,因为这似乎支持搜索字符串中的正则表达式。如何在xpath搜索中实现下面提到的(伪)css搜索?require'rubygems'require'nokogiri'value=Nokogiri::HTML.parse(ABBlaCD3"HTML_END#my_blockisgivenmy_bl="1"#my_eqcorrespondstothisregexmy_eq="\/[0-9]+\/"#FIXMEThefoll

  5. ruby-on-rails - Ruby url 到 html 链接转换 - 2

    我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.

  6. ruby-on-rails - capybara ::ElementNotFound:无法找到 xpath "/html" - 2

    我正在学习http://ruby.railstutorial.org/chapters/static-pages上的RubyonRails教程并遇到以下错误StaticPagesHomepageshouldhavethecontent'SampleApp'Failure/Error:page.shouldhave_content('SampleApp')Capybara::ElementNotFound:Unabletofindxpath"/html"#(eval):2:in`text'#./spec/requests/static_pages_spec.rb:7:in`(root)'

  7. ruby - 如何使用 Ruby 将 CSV 文件读入 HTML 表格? - 2

    我正在尝试将一个简单的CSV文件读入HTML表格以在浏览器中显示,但我遇到了麻烦。这就是我正在尝试的:Controller:defshow@csv=CSV.open("file.csv",:headers=>true)end查看:输出:NameStartDateEndDateQuantityPostalCode基本上我只获取标题,而不会读取和呈现CSV正文。 最佳答案 这最终成为最终解决方案:Controller:defshow#OpenaCSVfile,andthenreaditintoaCSV::Tableobjectforda

  8. ruby - 如何使用 Selenium Webdriver 根据 div 的内容执行操作? - 2

    我有一个使用SeleniumWebdriver和Nokogiri的Ruby应用程序。我想选择一个类,然后对于那个类对应的每个div,我想根据div的内容执行一个Action。例如,我正在解析以下页面:https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=puppies这是一个搜索结果页面,我正在寻找描述中包含“Adoption”一词的第一个结果。因此机器人应该寻找带有className:"result"的div,对于每个检查它的.descriptiondiv是否包含单词“adoption

  9. ruby - 如何使用 Nokogiri 解析纯 HTML 表格? - 2

    我想用Nokogiri解析HTML页面。页面的一部分有一个表,它没有使用任何特定的ID。是否可以提取如下内容:Today,3,455,34Today,1,1300,3664Today,10,100000,3444,Yesterday,3454,5656,3Yesterday,3545,1000,10Yesterday,3411,36223,15来自这个HTML:TodayYesterdayQntySizeLengthLengthSizeQnty345534345456563113003664354510001010100000344434113622315

  10. ruby-on-rails - 连接字符串时如何在 <%=%> block 内输出 html_safe? - 2

    考虑一下:现在这些情况:#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2我需要用其他字符串输出URL。我如何保证&符号不会被转义?由于我无法控制的原因,我无法发送&。求助!把我的头发拉到这里:\编辑:为了澄清,我实际上有一个像这样的数组:@images=[{:id=>"fooid",:url=>"http://

随机推荐