0

I am writing the header for a basic sie, and am having trouble grasping the idea of the proper way to override the bootstrap CSS with my own CSS. I added the form-control input and buttom to act as a site search, but am having trouble with positioning. Positioning always seems to be an issue I run into, as I always add features that require me o adjust positioning of others. Anyway, I wrote some code for my header that I want to act as logo > menu > search > social buttons all in a row. My HTML is:

<!doctype html>
<html>
<head>

<link rel = "stylesheet" href = "css/style_samp2.css">
<link rel = "stylesheet" href = "css/bootstrap.min.css">


<meta charset="utf-8">
<title>Site</title>
</head>

<body>

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="logo_header_test1.html">
        <img alt="My Logo" src="logo.gif">
      </a>
    </div> 

    <div class="container">
    <ul class = "dropdown-menu-right">
     <div class = "top-menu">
      <li><a href="About.html">About</a></li>
      <li><a href="#">Blog</a></li>
      <li><a href="resume.html">Resume</a></li>
      <li><a href="#">Portfolio</a></li>

      </div>
      </ul>

      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>

      </div>
  </div>

</div>




</nav>



<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>

<script src="js/scripts.js" type="text/javascript"></script>
</body>
</html>

CSS:

html {
  font-family: sans-serif;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

.container-fluid {
    background-color: #30302f;
    height: 90px;
}
.top-menu a{
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  padding: 14px 10px;
  text-transform: uppercase;
  position: relative;
  left: 320px;
  top: 64px;
}

.top-menu a:hover {
    text-decoration: underline;
    color: #fff;
}

.container .top-menu li{
    display: inline-block;
}

.social{
    position: relative;
    top: 20px;
    left: 900px;
}

.navbar-header a {
    background-color: #30302f;
    height: 69px;
    width: 367px;
    position: relative;
    left: 120px;
}

Pseudo ::before element
:after, :before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
Pseudo ::after element
:after, :before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

Here is a fiddle (the logo isn't working, but the dimensions are correct):

https://jsfiddle.net/yp1pm3e8/

Thanks for any kind of input as to the correct way to position the divs!

Jason
  • 211
  • 1
  • 10
  • You need to clean up your Fiddle. Your style_same2.css file takes you to Drop box where you need to login in order to see it. I suggest taking your custom CSS out and adding it to the Fiddle itself. Also you dont need to add any header data to the HTML section (remove doctype, title etc) – crazymatt Apr 21 '15 at 20:19

3 Answers3

1

You must include your new style settings AFTER the bootstrap definitions, so that the bootstrap css definitions will get overwritten. So first need to include the default bootstrap css and afterwards your new style definiton file, so that settings get overwritten by the new settings.

AirUp
  • 426
  • 1
  • 8
  • 18
1

Check out this page http://getbootstrap.com/css/ and view bootstrap's "Grid System". This will help you understand rows and columns. As for your custom css I agree with the above answer. You must have your style sheet after the bootstrap stylesheet in the head.

The logo and the search bar should not be wrapped in a nav tag. http://www.w3schools.com/TAgs/tag_nav.asp Check this page out for a good definition on the use of nav. The nav should only wrap your site navigation or other main/utility site navigation. In this instance it would be your about, blog, resume and portfolio.

Bootstrap makes it easy to create fluid layouts. So you should be careful trying to override the code. Based on the code you provided and the question you are asking I would try wrapping everything like I have below. This will put everything on the same row and help you position like you want. You can then wrap everything in your tags and style how you want. Just remember bootstrap is a fluid and responsive layout.

<div class="container-fluid">
  <div class="row">
     <div class="col-md-4">Logo tags and code goes heare</div>
     <div class="col-md-4">Navigation and tags goes here</div>
     <div class="col-md-4">Search code and tags goes here</div>
  </div>
</div>

I would recommend setting the .img-responsive to your logo to keep it fluid. In js fiddle I noticed there was problems with the logo overlapping your navigation. I think this is because you provided fixed dimensions. Also, you are setting things to position relative when you may not need to. Let me know if you need further explanation.

Hope this helps!

EDIT: okay so after reviewing your question one more time and looking over your new code in jsfiddle I came up with this solution: https://jsfiddle.net/8yufLL4n/embedded/result/

here is link to editable jsFiddle code: https://jsfiddle.net/8yufLL4n/

I used a few resources for this: http://getbootstrap.com/components/#navbar-default I copied the code over from bootstrap and I made slight alterations to fit what I think you are trying to do. Now on large screens and normal tablet view the logo, navigation and search form all sit in the same row. As you adjust the screen size this changes like in all fluid and responsive designs. To get the dropdown working you will have to add javascript. This link should help: http://getbootstrap.com/javascript/#dropdowns

Here is the html:

    <nav class="navbar navbar-default navbar-fixed-top">
     <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
     <button type="button" class="navbar-toggle collapsed menuIcon" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
  <a class="navbar-brand" href="#">
      <img alt="Brand" src="http://i.imgur.com/jeJYf95.gif" class="img-responsive" id="brandImage" />
  </a>
</div>

  <!-- Collect the nav links, forms, and other content for toggling -->
  <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  <ul class="nav navbar-nav">
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">About <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Blog <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Resume <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Portfolio <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
    </ul>
     <form class="navbar-form navbar-right" role="search">
    <div class="form-group">
        <label for="search" class="sr-only">Search Bar</label>
        <input type="text" name="search" class="form-control" placeholder="Search" />
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
  </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
  </nav>

And the css:

.container {
   background:#30302f;
}

.menuIcon {
    background:rgb(200,200,200);
}

.navbar-brand {
   height:auto;
}

#brandImage {
   max-width:60%;
}

@media (max-width:600px) {

.navbar-brand {
width:95%;
padding:8px 2.5%;
}

#brandImage {
max-width:100%;
}
}

@media (min-width:990px) and (max-width:1200px) {
.navbar-brand {
width:250px;
}
}

Notice that I use media queries to style it at different screen sizes. I am not trying to make drastic changes to the bootstrap css. Instead, try adding id or classes to the elements that you need to style (like what I did with menuIcon and brandImage). Try making small changes one at a time to see how it effects the design.

Let me know if this helps!

Charlie
  • 163
  • 8
  • Many thanks for the help...here's an edited HTML with your recommendation (no changes to the CSS yet). Was this what you were suggestion I go with? https://jsfiddle.net/g3vmoz75/ – Jason Apr 22 '15 at 00:38
1

well this pretty simple buddy you should place your custom css file below the bootstap css file. something like this:

<!doctype html>
<html>
<head>


<link rel = "stylesheet" href = "css/bootstrap.min.css"> <!-- first place bootstrap -->
<link rel = "stylesheet" href = "css/style_samp2.css"> <!-- place of custom css file to override your bootstrap css file 

</head>

<body>
<!-- your body -->
</body>
    
</html>

this way you can override bootstrap css file

hadi
  • 1,104
  • 8
  • 23