【问题标题】:Unordered list not centering in DIV for responsive CSS?响应式 CSS 的无序列表不在 DIV 中居中?
【发布时间】:2012-11-20 01:40:28
【问题描述】:

在进行响应式设计时,我注意到除了我的无序列表之外的所有内容都是响应式的。当我调整浏览器的大小时,列表不会移动或保持在其 DIV 的中心。我一整天都尝试了很多东西,但就是想不通。对于上下文,#sitecontent 是包含所有内容的容器,#sitecontent .leftsidebar 包含图像和无序列表,#sitecontent .leftsidebar ul 是无序列表。有人可以检查一下并告诉我出了什么问题吗?

@-moz-document url-prefix() {
* { font-weight: 400; }
h1, h2 
}

@font-face { font-family: 'helvetica neue'; src: local('Arial'); } 

x:-o-prefocus, h1 {
padding-top: 22px;
}

x:-o-prefocus, h2 {
margin-top: -2%;
}

x:-o-prefocus, ul li {
line-height: 20px;
}


#sitecontent {
display: block;
width: 90%; /* 780px */
max-width: 780px;
padding-top: 150px;
margin: 0 auto;
}

#sitecontent .leftsidebar {
float: left;
width: 19.2%; /* 150px */
}

#profilepic {
-moz-border-radius: 20px;
border-radius: 20px;
max-width: 100%;
}
#sitecontent .leftsidebar ul {
position: relative;
top:-5px;
list-style-type: none;
font-family: 'Patua One', cursive;

}

#sitecontent a {
text-decoration: none;
color: #3f83ca;
}

#sitecontent .leftsidebar ul li{
display:inline;
margin-bottom: 3%;
float: left;
clear: both;
border-bottom: 1px solid #E5E5E5;
font-family: helvetica;
}

#sitecontent .leftsidebar ul li:hover {
border-bottom: 1px solid #3f83ca;
}



#sitecontent .rightsidebar {
float: right;
width: 76.9%;

}

#sitecontent .rightsidebar > h1 {
font-size:3.750em;
font-weight: normal;
color: #3f83ca;
line-height: 0;
font-family: helvetica;
font-weight:bold;

}

#sitecontent .rightsidebar > h2 {
line-height: 10px;
font-weight: normal;
color: #38414f;
font-family: helvetica;
font-weight: bold;

}

#sitecontent .rightsidebar > p {
text-align: justify;
padding-top: 16px;
line-height: 20px;
font-size: 0.938em;
font-family:'Helvetica Neue', Arial, sans-serif;


}

#secondparagraph {
text-align: justify;
color: #A1A1A1;
font-family:'Helvetica Neue', Arial, sans-serif;


}

#secondparagraph:hover {
color:#3f83ca;
opacity: 1.0;

}

#secondparagraph a {
font-size: 14px;
text-decoration: none;
color: inherit;
}

@media screen and (max-width: 480px) {


#sitecontent {
width: 100%;
padding-top: 10px;
}

#sitecontent .leftsidebar {
width: 100%;
float: none;
}

#profilepic {
display:block;
margin: 0 auto;
border-radius: 77px;
float:none;
}

#sitecontent .leftsidebar ul {  
position: relative;
top:35px;
}



#sitecontent .leftsidebar ul li{
margin-bottom: none;
border-bottom: none;
float: none;
clear: none;
padding:10px;
border-radius: 2px;
background-color:#3f83ca;
border: 1px solid #00688B;
font-family: helvetica;
font-weight: 400;
}

#sitecontent a {
text-decoration: none;
color: #EDEDED;
}

#sitecontent .leftsidebar ul li:hover {
border-bottom: none;
}

#sitecontent .rightsidebar {
float: none;
margin: 0 auto;
width: 90%;

}

#sitecontent .rightsidebar > h1 {
position: relative;
bottom: 36px;
text-align: center;
font-size:1.875em;
font-weight: 600;
color: #3f83ca;
margin-top: 6%;
font-family: helvetica;
font-weight:bold;

}

#sitecontent .rightsidebar > h2 {
display:none;

}

#secondparagraph {
display: none;

}

#sitecontent .rightsidebar > p > a:first-child {
color:#3f83ca;
}

}

【问题讨论】:

  • 如果您可以使用 HTML 代码提供指向您的站点的链接或发布 jsfiddle 会更容易为您提供帮助。
  • 只需在我的网站上查看源代码:tommaxwell.me
  • 进行响应式设计绝对是一个好主意,但如果你要这样做,你不应该只是一头扎进去,你应该先深入研究并使用em's 和百分比来定义几乎所有的数值,然后看看添加媒体查询,如果你还没有。

标签: css html html-lists responsive-design


【解决方案1】:

我只在站点最小化和最小化时才看到居中问题。

我添加了text-align:center;,它起作用了。

#sitecontent .leftsidebar {
  width: 100%;
  float: none;
  text-align: center;
}

【讨论】:

  • 这似乎可以在您通过屏幕尺寸移动时保持其位置,但它实际上并不是居中列表,这是问题所在。
  • 我可以使用类似 right:20px;修复它,但这违背了响应式设计的目的,因为当您执行旋转屏幕之类的操作时它不会移动。
  • 我的意思是它没有将列表放在移动网站的中心(当浏览器最小时)。
猜你喜欢
  • 2021-08-01
  • 1970-01-01
  • 2015-09-23
  • 2012-12-18
  • 2019-05-28
  • 2018-08-25
  • 1970-01-01
  • 2020-07-18
相关资源
最近更新 更多