【问题标题】:Centering address, every solution i find i have already tried居中地址,我发现我已经尝试过的每个解决方案
【发布时间】:2014-07-07 16:30:12
【问题描述】:

我有一个真正的问题,我确信这只是因为我没有长时间编码,很容易忽略简单的错误。 我正在尝试将地址居中,并尝试将其包含在 div 中,或者只是自行格式化,但我无法将其居中。 请注意,我希望地址固定在屏幕上,所以滚动时它不会移动。 这是我的代码(我知道每个人都讨厌粘贴大段代码的人,但我还没有学会如何链接我的 jsfiddle 页面)

<link rel="stylesheet" href="stylesheet for real index.css">
</style>
    <head>
    <title>Test of notepad ++</title>
    </head>
        <body>
<div style="text-align: center;height: 100%;background: #4FD5D6;">
    <iframe src="index.html" scroll="no">Your browser doesn't support iFrames.</iframe>
</div>
<div class="center">
    <address>
    Made by <em><b>Dantoon e</b></em><br>So look out
    </address>
</div>
</body>

还有CSS

body {
  font-family: Nobile;
  background-color: #4FD5D6;
  display: empty-cells;  }  
iframe {
  display: block !important;
  width: 1200px;
  height: 1200px;
  margin-top: -20px;
  margin-right: auto;
  margin-left: auto;
  margin-bottom: -1000px;
  box-shadow: 10px 10px 10px;
  position: relative;
  z-index: 0;  }
.center  { 
  border-top: thick dotted;
  border-bottom: thick dotted;
  background-color: black;
  color: white;  
  position: fixed;
  bottom: 5px;
  width: 1204px;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
  margin-bottom:5px;
  display: inline;
  margin-top: 0px;
  z-index: 1;  }

我只包含整个页面,因为我不知道其他地方的疏忽可能会影响地址。谢谢提前!

【问题讨论】:

  • 如果就是这样,我会踢自己
  • 不,仍然无法正常工作,不过感谢您的帮助,不敢相信我做到了!
  • 我并不是说作为一种解决方案,只是一个注释。 .center 元素的宽度不应该是 100% 而不是 1204px?
  • width: 100% 导致地址跨越网站的整个宽度,它应该与 iframe 对齐

标签: html css position center


【解决方案1】:

您缺少一个开始的 html 标记,而正文在更接近之前,再加上一个随机的 /style :)

<html>
    <head>
        <link rel="stylesheet" href="stylesheet for real index.css" />
        <title>Test of notepad ++</title>
    <head>
    <body>
        <div style="text-align: center;height: 100%;background: #4FD5D6;">
            <iframe src="index.html" scroll="no">Your browser doesn't support iFrames.</iframe>
       </div>
       <div class="center">
           <address>
                Made by <em><b>Dantoon e</b></em><br>So look out
           </address>
       </div>
    </body>
</html>

使用 CSS:

.center {
    display: block;
    border-top: thick dotted;
    border-bottom: thick dotted;
    background-color: black;
    color: white;
    position: fixed;
    bottom: 5px;
    width: 100%;
    text-align: center;
}

这也是一个有效的小提琴(br 需要一个斜杠)。另外我不会把东西修到 1200 像素——使用 100% http://jsfiddle.net/QcSt9/1/

【讨论】:

  • 感谢您的帮助,但是您的代码仍然无法正常工作,我不明白为什么(我大约在 3 周前才知道 scc 是什么,大约一个月前才知道 html!所以是的,我的代码是可怜!)+我没有投反对票
  • 出于好奇,您使用的是什么浏览器,小提琴看起来不错?
  • 小提琴上的东西可以工作,但是当我复制任何更改时,它都不起作用,所以我认为它必须是进一步的问题,而不是地址本身
  • Okey dokey,等一下,我会用完整的 html 更新我的答案
  • 当我出于某种原因发布问题时删除了 html 标签,但随机 /style 在那里!谢谢
【解决方案2】:

您需要做的是对此进行一些更改:

添加一个容器/父 div,它将包含在 iframe 和中心类 div 的子 div 中:

<div class="container">
    <iframe></iframe>
     <div class="center">
        <address>blah</address>
     </div>     
</div>

该容器将有一个相对的类位置....然后您可以根据您给 iframe (1200px) 的容器宽度将您的发送者类绝对位于底部并居中

这里是:

FIDDLE

【讨论】:

  • 感谢您的帮助,但 iframe 不是问题,尽管我已采纳您的建议并添加了父 div,只是为了帮助格式化
  • np。很高兴我能以某种方式帮助你
【解决方案3】:

另外,不确定你是否注意到,但你的样式表链接在头部之外,你有一个无用的样式接近并使用内联样式(没有错,但不推荐 ether)

希望这会有所帮助:)

【讨论】:

    猜你喜欢
    • 2021-10-30
    • 2020-05-28
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-23
    • 2013-07-30
    相关资源
    最近更新 更多