I create a responsive page using Bootstrap and SASS.
Faced a problem - it’s impossible to center the maintext div and logo while reducing the screen size. Tried the most different options with margin, left, right, clear, float, display, position, etc. Something like this for example:
@media (max-width: 750px) { #maintext { margin-left: 0; margin-right: 0; } }
I also tried to wrap the maintext div into another div (centerhelper) and set the parent div 50% and maintext left: -50%, like this:
@media (max-width: 750px) { .centerhelper { left: 50%; } #maintext { left: -50%; } }
But the height of the centerhelper div was zero, experimenting with different display and position options, but it was not possible to make the parent div a height with a div-descendant.
Here is my HTML:
<!-- NAVIGATION TOP --> <nav class="navbar my-navbar navbar-inverse"> <div class="container"> <div class="navbar-header"> <!-- LOGO --> <a href="#" class="my-logo pull-left"><img src="img/Logo.png"></a> <!-- LOGO --> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div id="navbar" class="collapse navbar-collapse pull-right"> <ul class="nav navbar-nav"> <li><a href="#"><button class="navbutton active">Home</button></a></li> <li><a href="#"><button class="navbutton">About</button></a></li> <li><a href="#"><button class="navbutton">Services</button></a></li> <li><a href="#"><button class="navbutton">Portfolio</button></a></li> <li><a href="#"><button class="navbutton">Blog</button></a></li> <li><a href="#"><button class="navbutton lastbutton">Contact</button></a></li> </ul> </div><!--/.nav-collapse --> </div> </nav> <!-- NAVIGATION TOP END --> <!-- SHOWCASE --> <section class="showcase"> <div class="container showcase-content"> <!-- MAINTEXT DIV --> <div class="centerhelp"> <div id="maintext" ></div></div> <!-- MAINTEXT DIV --> </div> </section> <!-- SHOWCASE END -->
And CSS:
.showcase { background-image: url(...); height: 380px; width: 100%; #maintext { padding: 0px; display: inline-block; float: left; margin-top: 91px; width: 430px; h1 { padding: 0; margin: 0; } p { padding: 0; margin: 0; } } .my-logo { position: absolute; margin-top: 15px; } img { width: 105px; height: auto; }
Perhaps some kind of problem with cascading CSS rules, which I still can not understand. I would be grateful for the advice on how to center the maintext div and Logo (link with the image inside).