Twitter Bootstrap 3 - Losing container full width on affix scroll - css

Twitter Bootstrap 3.3.7
I have the following two navs:
<nav class="navbar navbar-default navbar-fixed-top" id="topNavBar">
<div class="container-fluid"></div>
</nav>
<nav class="navbar navbar-default navbar-lower" role="navigation" data-spy="affix" data-offset-top="50" data-offset-bottom="80">
<div class="container container-navbar">
<div class="row take-test-heading">
<asp:Label ID="lblTakeTestTitle" runat="server" Text="Take Text Title Here...."></asp:Label>
<asp:Label ID="lblTakeTestTimeRemaining" runat="server" Text="00:00"></asp:Label>
<i class="fa fa-bars pull-right"></i>
</div>
<div class="row take-test-heading-two">
</div>
</div>
</nav>
with the following CSS:
body {
margin-top: 50px;
padding-top: 0px !important;
}
.container-navbar {
}
.take-test-heading {
background-color: rgb(51, 122, 183);
height: 20px;
color: white;
font-size: 18px;
font-weight: 700;
margin-left: 10px;
margin-right: 20px;
margin-top: 5px;
}
.navbar-lower {
z-index: 999;
}
which gives me the following when the page is first rendered:
and then as I scroll (note the top affix):
I have a couple of issues that no matter what CSS changes I make I cannot seem to solve:
I want the blue bar "Take Text Title..." to be 100% and occupy the entire width of the viewport (yellow areas)
When scroll spy kicks in the navbar goes to 1170px (!) and is no longer full width (see green area). I want it to be full width all the time.
Cam someone please point me in the right direction here?

In bootstrap 3 .container has 15px of padding-left and padding-right. You can set both to 0px; manually.
Also setting margin-left and margin-right to 0px will do the trick
.take-test-heading {
background-color: rgb(51, 122, 183);
height: 20px;
color: white;
font-size: 18px;
font-weight: 700;
margin-left: 0px;
margin-right: 0px;
margin-top: 5px;
}

Related

CSS Text align when wrapping

I'm having trouble aligning text when the window is resized, e.g. on mobile.
Here's the HTML:
.count-panel {
float: left;
width: 64px;
border: 1px #888 solid;
}
.count {
font: 15px/18px Roboto, sans-serif;
font-size: 42px;
}
.message {
font-size: 20px;
}
.row {
clear: both;
margin-bottom: 16px;
}
<div class='table'>
<div class='row'>
<div class='count-panel'>
<span class='count'>1</span>
</div>
<div class='message'>This is line one</div>
</div>
<div class='row'>
<div class='count-panel'>
<span class='count'>2</span>
</div>
<div class='message'>This is line two which is longer than the rest so it can test wrapping</div>
</div>
<div class='row'>
<div class='count-panel'>
<span class='count'>3</span>
</div>
<div class='message'>This is line three</div>
</div>
At larger sizes: Larger
At smaller sizes: Smaller
I need the text in the second line to align with the others and not wrap hard left as in the image. Thanks.
That behaviour on mobile is due to the float applied to the .count-panel element. You could instead use flexbox and clean a bit the css code, like so:
Codepen demo
.count-panel {
border: 1px #888 solid;
flex: 0 0 64px;
}
.count {
font: 15px/18px Roboto, sans-serif;
font-size: 42px;
}
.message {
font-size: 20px;
}
.row {
margin-bottom: 16px;
display: flex;
}
It's just your float: left that's taking the count-panel out of sync.
I have replaced your example with display: flex instead. I would suggest avoiding float when positioning your elements as it was never intended to be used for layout. Flex is a much cleaner solution and I think it gives you more flexibility of layout choices. :-)
I've also amended the HTML layout slightly to include the border on the number itself so that it doesn't stretch the full size of the text content on smaller devices.
.count {
font: 42px Roboto, sans-serif;
min-width: 64px;
border: 1px #888 solid;
text-align: center;
max-height: max-content;
}
.message {
font-size: 20px;
}
.row {
display: flex;
flex-direction: row;
margin: 0 10px 16px 0;
}
<div class='table'>
<div class="row">
<span class="count">1</span>
<div class="message">This is line one</div>
</div>
<div class="row">
<span class="count">2</span>
<div class="message">This is line two which is longer than the rest so it can test wrapping</div>
</div>
<div class="row">
<span class="count">3</span>
<div class="message">This is line three</div>
</div>
</div>

How can I make an image take 100% width in smaller screens?

I am making an news blog. I have created my main article cards. The cards have an image to the left of the card, and with the card having the main content like the title, brief description, author and date.
Everything works when the browser is maximized (I'm on a 13 inch laptop). As I start resizing my browser and making it smaller, everything starts to kind of break. The image does not take up the full width, and has a lot of white space to the right of it.
I tried giving the image width of 100%, but it does not seem to fix the problem. I am not sure what is wrong and why this is happening. This is only happening to these article cards. Everything else on the homepage works correctly even on smaller sized screens.
If you have some time, can you explain what is happening, and how to solve this problem? Please and thank you.
Screenshots:
Large+ Screens
As I start resizing the browser window and making it smaller it does this:
And finally the phone sized screens:
HTML
<div class="card card-article">
<div class="row no-gutters right-shadow-games">
<div class="col-auto">
<img alt="" class="img-fluid" src="//placehold.it/200x200"> <a class="article-tag games" href="#">Games</a>
</div>
<div class="col">
<div class="card-block">
<div class="row">
<div class="col-md-12">
<h4 class="card-title">How Did van Gogh’s Turbulent Mind Depict One of the Most Complex Concepts in Physics?</h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="card-description">Pick the yellow peach that looks like a sunset with its red, orange, and pink coat skin, peel it off with your teeth. Sink them into unripened...</p>
</div>
</div>
<div class="row">
<div class="col-md-9">
<p class="card-author">Author on Sep 29, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
CSS
.card-article {
margin-top: 2px;
margin-bottom: 5px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.card-article .card-title{
margin-top: 15px;
margin-left: 15px;
margin-right: 10px;
font-size: 18px;
}
.card-article .card-author{
margin-left: 15px;
margin-right: 10px;
color: #8d8d8d;
font-size: 12px;
line-height: 1.4;
}
.card-article .card-title a{
color: black;
font-weight: 600;
}
.card-article .card-description{
margin-left: 15px;
margin-right: 10px;
color: #8d8d8d;
font-size: 14px;
line-height: 1.4;
}
For give the messy CSS I could definitely clean it up a little bit.
Here, the image will resized to 100% width at 640px media width. I think it is better when you could change the image size to something bigger (as per 100% width point) to get maximum picture clarity.
.card-article {
margin-top: 2px;
margin-bottom: 5px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.card-article .card-title {
margin-top: 15px;
margin-left: 15px;
margin-right: 10px;
font-size: 18px;
}
.card-article .card-author {
margin-left: 15px;
margin-right: 10px;
color: #8d8d8d;
font-size: 12px;
line-height: 1.4;
}
.card-article .card-title a {
color: black;
font-weight: 600;
}
.card-article .card-description {
margin-left: 15px;
margin-right: 10px;
color: #8d8d8d;
font-size: 14px;
line-height: 1.4;
}
.article-tag.games {
position: absolute;
left: 10px;
top: 10px;
background: red;
padding: 2px 5px;
color: white;
border-radius: 4px;
}
.col-auto img {
max-width:200px;
}
#media (max-width: 640px) {
.col-auto {
width:100%;
max-width:100% !important;
}
.col-auto img {
width:100%;
max-width:100%;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<div class="card card-article">
<div class="row no-gutters right-shadow-games">
<div class="col-auto">
<img alt="" class="img-fluid" src="//placehold.it/640x640"> <a class="article-tag games" href="#">Games</a>
</div>
<div class="col">
<div class="card-block">
<div class="row">
<div class="col-md-12">
<h4 class="card-title">How Did van Gogh’s Turbulent Mind Depict One of the Most Complex Concepts in Physics?</h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="card-description">Pick the yellow peach that looks like a sunset with its red, orange, and pink coat skin, peel it off with your teeth. Sink them into unripened...</p>
</div>
</div>
<div class="row">
<div class="col-md-9">
<p class="card-author">Author on Sep 29, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
What's happening is your image is exactly 200x200px, so it can't stretch when your page changes shape. You could find a different image (I don't recommend this - just putting it out there), or you could try adding a media query for another stylesheet on variable width devices, then resetting the height/width on those.
Use col-md-4 to image wrap div instead col-auto (see fidlle:https://jsfiddle.net/yemd0qnt/3/)
.card-article {
margin-top: 2px;
margin-bottom: 5px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.card-article .card-title{
margin-top: 15px;
margin-left: 15px;
margin-right: 10px;
font-size: 18px;
}
.card-article .card-author{
margin-left: 15px;
margin-right: 10px;
color: #8d8d8d;
font-size: 12px;
line-height: 1.4;
}
.card-article .card-title a{
color: black;
font-weight: 600;
}
.card-article .card-description{
margin-left: 15px;
margin-right: 10px;
color: #8d8d8d;
font-size: 14px;
line-height: 1.4;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="card card-article">
<div class="row no-gutters right-shadow-games">
<div class="col-md-4">
<img alt="" class="img-fluid" src="//placehold.it/200x200"> <a class="article-tag games" href="#">Games</a>
</div>
<div class="col">
<div class="card-block">
<div class="row">
<div class="col-md-12">
<h4 class="card-title">How Did van Gogh’s Turbulent Mind Depict One of the Most Complex Concepts in Physics?</h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p class="card-description">Pick the yellow peach that looks like a sunset with its red, orange, and pink coat skin, peel it off with your teeth. Sink them into unripened...</p>
</div>
</div>
<div class="row">
<div class="col-md-9">
<p class="card-author">Author on Sep 29, 2017</p>
</div>
</div>
</div>
</div>
</div>
</div>
You can 100% image width with use Media Queries for mobile.
#media (max-width: 575px) {
.img-fluid{width:100%;}
}

How to align bootstrap colums when setting margin of container to 0?

I have a question about aligning two bootstrap divs beside each other horizontally, whereas the left image "in one div" should have no margin to the left and the right text "in the other div" should be centered besides the image to the left. The right div may have some margin to the right
For some reason when I set my two divs beside each other and set margin to 0, I receive this result here as on the pic.
As can be seen, the div overlaps the other, why does that happen? What would I need to do in order to make it properly aligning to the right in the center?
I tried using col-md-offset-1 but it only displays it below the picture. What can I do best to keep it properly aligned to the right?
This is my html / css:
.row-provider-signup {
margin-top:6em;
margin-bottom:4em;
text-align:center;
}
.container-provider-signup > [class*="container"] {
padding-left: 0 !important;
padding-right: 0 !important;
margin-left:0;
margin-right:0;
}
.provider-signup-header-text {
color: #212121;
font-family: Raleway;
font-size: 62px;
font-weight: 400;
line-height: 72px;
margin-bottom:1.5em;
}
.provider-signup-body-text {
color: #616161;
font-family: Raleway;
font-size: 16px;
font-weight: 400;
line-height: 25px;
letter-spacing: 0.2px;
text-align:center;
margin-bottom:6em;
}
.provider-signup-button {
width: 150px;
height: 45px;
border-radius: 4px;
background-color: #4a90e2;
}
.provider-signup-button-text {
color: #ffffff;
font-family: Raleway;
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 2.5px;
}
<div class="container-provider-signup">
<div class="container">
<div class="row row-provider-signup">
<div class="col-md-6">
<img src="{{route('cacheImage', ['newDesign', 'panorama-signup.png']) }}"/>
</div>
<div class="col-md-6">
<p class="provider-signup-header-text">Test Header</p>
<p class="provider-signup-body-text">
Test Text <br/><br/>
Test Text <br/><br/>
Test Text <br/>
</p>
<button class="btn provider-signup-button"><span class="provider-signup-button-text">SIGN UP</span></button>
</div>
</div>
</div>
</div>

Multiple Divs / Classes On an Opaque Background

My goal (and the question of how-to) is to have an opaque / white background with black fields over the opaque area to serve as content holders. Here is what I have now:
/* translucent background*/
.background
{
width:950px;
height:1024px;
margin: 9px auto 10px;
background-color:#ffffff;
opacity:0.35;
filter:alpha(opacity=35); /* For IE8 and earlier */
border-radius: 15px;
-moz-border-radius: 15px;
z-index:0;
}
/*content wrapper*/
.content
{
font-family: Arial;
font-size: 11px;
width:950px;
height:1024px;
margin: 9px auto 10px;
border-radius: 15px;
-moz-border-radius: 15px;
z-index:1;
}
/*one of three content fields*/
.anounce_bar
{
font-family: Arial;
font-size: 16px;
width:940px;
height:225px;
float: left;
border: 5px 5px 5px 5px;
background-color: black;
border-radius: 15px;
-moz-border-radius: 15px;
z-index:2;
}
<div class="background"></div>
<div class="content">
<!--Top announcement bar-->
<div class="anounce_bar">
</div>
<!--Left side nav bar-->
<div class="nav" style="height: 1024px; ">
</div>
<!--Right side content window-->
<div class="content_window">
</div>
</div>
Right now its showing the anounce_bar below the translucent background.. how do I get the bar (and subsequent nav & content_window) to go on top of .background?
Note: I have other content, including a top 'masthead' image and a background JPG that might be screwing with this.
Any help would be GREATLY appreciated.
Update:
This was an issue with opacity inheritance - the work around I used is described very well here
'background' class became #background without any opacity, and a new item was added:#background .transparency with absolute positioning and opacity.
<div id="background">
<div class='transparency'></div>
/*OTHER STUFF*/
</div>
Change the order
<div class="anounce_bar"></div>
<div class="background"></div>
That should work.
<div class="background">
<div class="content">
<!--Top announcement bar-->
<div class="anounce_bar" style="color: white">Anounce Bar</div>
<!--Left side nav bar-->
<div class="nav" style="height: 24px; width: 940px; background-color: green; float:left;">Nav</div>
<!--Right side content window-->
<div class="content_window" style="height: 24px; width: 940px; background-color: yellow; float:left;">Content Window</div>
</div>
</div>
Sample Code

firefox dosen't support div width

I have a problem with Firefox to show this: (But IE show correctly)
<div id="main_div" dir="rtl">
<div dir="rtl">
<div class="outer_div" dir="rtl"> Text! </div>
</div>
<div dir="rtl">
<div class="outer_div" dir="rtl"> Text! </div>
</div>
<div dir="rtl">
<div class="outer_div" dir="rtl"> Text! </div>
</div>
</div>
======================================
body{
margin: 0px;
padding: 0px;
}
div.main_div{
border: dotted;
border-width: thin;
padding-bottom: 10px;
padding-top: 10px;
padding-left: 20px;
padding-right: 20px;
background: #ffffaa;
border-color: #FFCC66;
width: 100%;
float: right;
}
div.outer_div{
float: right;
padding-bottom : 5px;
padding-top : 5px;
padding-left: 10px;
padding-right: 10px;
width: 33.3%;
border: dashed;
border-width:thin
}
Why this happened?! tnx
You can't have pixel based padding when using % based sizing. Even IE doesn't get it right. If you look very closely (and change the size of the window), there is a white space to the left of your first div. When you add padding, it adds to the size of the div itself, so you have a div of 33.3% width + 20px (left-right). IE interprets this incorrectly and gives you a seemingly usable result. Firefox interprets this "as is" and you get the floated div.
What you need to do is apply padding to sub-divs inside your layout divs:
EDIT: Style Elements
body{
margin: 0px;
padding: 0px;
}
div.main_div{
border: dotted;
border-width: thin;
padding-bottom: 10px;
padding-top: 10px;
padding-left: 20px;
padding-right: 20px;
background: #ffffaa;
border-color: #FFCC66;
width: 100%;
float: right;
}
div.outer_div{
float: right;
width: 33.3%;
border: dashed;
border-width:thin
}
div.textformattingclass{
padding: 5px 10px 5px 10px;
}
HTML Elements
<div id="main_div" dir="rtl">
<div class="outer_div" dir="rtl">
<!-- remove all content formatting from the style for the outer_div
and place it in a style for this sub-div //-->
<div class="textformattingclass">
Some text!
</div>
</div>
<div class="outer_div" dir="rtl">
<div class="textformattingclass">
Some text!
</div>
</div>
<div class="outer_div" dir="rtl">
<div class="textformattingclass">
Some text!
</div>
</div>
</div>
You are missing the closing tag for the outer div, and also, no div should have the same ID on the page... You should be using the class attribute :)

Resources