首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我该如何解决这个问题?我无法定位或集中我的DIV

问我该如何解决这个问题?我无法定位或集中我的DIV
EN

Stack Overflow用户
提问于 2019-08-30 12:52:51
回答 2查看 64关注 0票数 1

我无法移动div (.searchblock)。我希望它在标题中居中。

附带问题:是否有一种简单的方法可以使标题和正文的内容对齐到相同的宽度?

在这个问题上,我尝试了立场:固定的,绝对的,相对的。我试过在div中间加上边距: auto和其他各种值。我试着向各个方向移动div (位置:绝对,顶部:50 in,右100-1000 in,等等)。也是。似乎没有什么对它的定位有影响。

​

代码语言:javascript
复制
html {
  background-color: #e9ebee;
}

body {
  margin: 0;
}

.header {
  background-color: #4267B2;
  #4267b width: 100%;
  height: 42px;
}

#search {
  color: gray;
  height: 24;
}

input[type=image] {
  height: 24;
  padding: 0px;
}

.searchblock {
  position: absolute;
  left: 1000px;
}

#profile {
  border-radius: 10px;
}

ul,
.bttn {
  color: white;
  list-style-type: none;
  display: inline-block;
}

li {
  float: right;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12pt;
  padding: 0 10px 1px;
  border-right: solid 1px gray;
}

button {
  border: none;
  padding: 0;
  margin: 0;
}

.footer {
  position: fixed;
  width: 100%;
  height: 50px;
  bottom: 0;
  background-color: #2851A3;
  margin: 0;
}
代码语言:javascript
复制
<div class="header">
  <div class="searchblock"></div>
  <img id="logo" src="facebook.png" height="24" width="24">

  <input id="search" type="text" name="search" value="search">
  <input type="image" name="submit" src="maglass.png">
  <img id="profile" src="blacwhit.jpg" height="24" width="24">
  <ul>
    <li>Create</li>
    <li>Find Friends</li>
    <li>Home</li>
    <li>Anthony</li>
  </ul>

  <div class="bttn">
    <button type="button"><img src="messages.png"height="24" width="24"> 
    </button>
    <button type="button"><img src="frequest.png"height="24" width="24"> 
    </button>
    <button type="button"><img src="alerts.png"height="24" width="24"> 
    </button>
    <button type="button"><img src="acct.png"height="24" width="24"></button>
    <button type="button"><img src="help.png"height="24" width="24"></button>
    <button type="button"><img src="dropdown.png"height="24" width="24"> 
    </button>
  </div>
</div>

​

我希望DIV在标题中居中。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-30 12:55:00

我希望DIV在标题中居中。

您可以使用flexbox对元素进行居中。如下所示:

代码语言:javascript
复制
.header {
  background-color: #4267B2;
  width: 100%;
  height: 42px;

  display: flex;
  justify-content: center;
  align-items: center;
}
票数 3
EN

Stack Overflow用户

发布于 2019-08-30 12:58:46

试试这个代码..。它也适用于十字绣者..。

css

代码语言:javascript
复制
.header {
    display: flex;
    display: -webkit-flex;
    align-items: center;
    -webkit-align-items: center;
    justify-content: center;
    -webkit-justify-content: center;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57727133

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档