html - 当 div 具有左右属性的相对定位时,如何使它响应

标签 html css twitter-bootstrap css-position responsive

我正在尝试使其具有响应性,因此当您缩小它时,它会像响应式网站一样与导航栏一起移动。我正在使用 Bootstrap ,但是我想将 div 保留在网站的中心,而不是填满整个宽度。

<div class="main-body">
    <div class="MainImage">
        <img src="shirini1.jpg"  height="700">
    </div>
    <div class="RedBar">       
        <p id="Welcome">Welcome to my Website</p>
    </div>

</div>

和CSS

.main-body{
position: relative;
left: 370px;
width: 60%;
display: inline-block;
}

.main-body,img{ 
position: relative;
max-width: 100%;
height: auto;
display: block;
}

.RedBar{
height:50px;
background-color:#ff4c55;

}

#Welcome{
color: white;
text-align: center;
position: relative;
top: 10px;
font-size: 24px
}

最佳答案

尝试设置 margin: 0 auto; display:block;.main-body 并删除 left: 370px 以使其始终居中。

关于html - 当 div 具有左右属性的相对定位时,如何使它响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44214985/

相关文章:

javascript - 当由外部源托管时,jquery 代码停止工作

html - 输入框字体大小不起作用。不知道为什么

html - 将缩略图区域调整为图像和文本

html - 如何安装 Bootstrap

html - 如何在表头和表体之间设置 bootstrap 3 边框的样式

javascript - 我不明白为什么我的代码没有被执行

html - 如何使用 float 并仍然将子div放在父div内?

ajax - 使用 MVC 3 ajax 样式上传文件

html - 无法在 3 列固定流体宽度布局中打开选择

css - 错误 : CSS: background:/is an incorrect operator