Demo: http://codepen.io/anon/pen/JdWrKX?editors=110
As you can see there is a responsive table inside ".panel" which you can scroll horizontally. Great.
But it makes the entire page expand horizontally and not fit in the window.
Try on small screens to see the bug.
HTML:
<div id="wrap">
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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="">Logo</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
Logout
</li>
</ul>
</div>
</div>
</nav>
<div class="content content-primary content-sm">
<div class="container-fluid">
<div class="row">
<div class="col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<table class="table-bordered">
<tr>
<td>
<div>a</div>
</td>
<td>b</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="">Copyright</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
Logout
</li>
</ul>
</div>
</div>
</nav>
</footer>
</div>
CSS:
html,
body {
height: 100%;
}
#wrap {
height: 100%;
display: table;
width: 100%;
}
#wrap > nav,
footer {
display: table-row;
}
nav.navbar {
margin-bottom: 0;
}
.content-sm {
padding: 15px 0;
}
.content-primary {
background: #337ab7;
}
.content {
display: table-cell;
height: 100%;
}
td {
text-wrap: no-warp;
}
td div {
width: 900px;
}
Since the child elements of .content seems to be ignoring % width values, the work around that worked for me was:
.content > * {
width: 100vw;
}
I also added the class .table to your table element
<table class="table table-bordered">
Here is a Demo
NOTE: The vw unit only works in modern browsers. Check support here
Change the table code like this:
<div class="content content-primary content-sm">
<div class="container-fluid">
<div class="row">
<div class="col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-body">
<table class="table table-responsive table-bordered">
<tr>
<td>
<div>a</div>
</td>
<td>b</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
and remove this from your css file
td div {
width: 900px;
}
Try editing the width of your td's child div like this
td div {
width: auto;
}
I hope it helps fixing the bug.
If the window size is less or equal to 900px the td content will go beyond that. You should not fix the td div size in px. Use instead % (percentage).
td div
{
width: 100%;
}
The problem is that tables are by nature not responsive. You have resorted to using display table, table-row, and table-cell which are expanding beyond the veiwport with the content, and creating your undesired effects.
As you can see in this fiddle: if you remove the table elements, your width issue goes away, but then you don't get the sticky footer you're looking for.
changing your CSS to:
html,
body {
height: 100%;
}
#wrap {
min-height: 100%;
background: #337ab7;
}
.page-wrap:after {
content: "";
display: block;
height: 51px;
}
nav.navbar {
margin-bottom: 0;
}
.content-sm {
padding: 15px 0;
}
.box-content {
width: 9000px;
height: 5000px;
background: red;
}
.box-responsive {
width: 100%;
max-width: 100%;
overflow-x: scroll;
border: 1px solid green;
}
You will get your desired responsive width, as well as a full height webpage with sticky footer.
Related
I believe my background img is creating a blank space between it and my flexbox sticky footer. I’ve tried numerous ways, but they just create different problems so far... Can someone help? I created a placeholder image that’s the size of my original background img to recreate the problem for you! Thanks!
JS Fiddle Link
CSS:
.masthead {
height: 100vh;
min-height: 100%;
background:; /* ie 6 cheat */
background-image: url('http://via.placeholder.com/3024x4032?Placeholder%27');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
/* Sticky Footer Classes */
body
{
display: flex;
flex-direction: column;
}
html, body
{
height: 100%;
}
#page-content {
flex: 1 0 auto;
}
#sticky-footer {
flex-shrink: 0;
}
This can be solved in multiple ways,
Method 0: I think there is some unwanted text content before the Footer tag. If that text content is intentional then move to Method 2 else do this
Remove this below code snippet which under the <body class="d-flex flex-column">
<div id="page-content">
<div class="container text-center">
<div class="row justify-content-center">
<div class="col-md-7">
<h1 class="font-weight-light mt-4 text-white">Sticky Footer using Flexbox</h1>
<p class="lead text-white-50">Use just two Bootstrap 4 utility classes and three custom CSS rules and you will have a flexbox enabled sticky footer for your website!</p>
</div>
</div>
</div>
<div id="push"></div>
</div>
Method 1: Moving the footer towards the place where the content ends.
#sticky-footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
or Method 2: In the style .css file Move the CSS background-image description defined under the class .masthead to the body
background:; /* ie 6 cheat */
background-image: url('http://via.placeholder.com/3024x4032?Placeholder');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
(use this in body not in .masthead)
This Blank space is your page-content.
You need to add this to your header:
.masthead {
position: absolute;
width: 100%;
margin-top: 56px; // your navbar height
}
Also add this to show your footer:
#sticky-footer {
z-index: 1;
}
If you want to center your content vertically add this classes to your page-content:
<div id="page-content">
<div class="container text-center h-100">
<div class="row justify-content-center align-items-center h-100">
See the snippet:
.masthead {
height: 100vh;
min-height: 100%;
background: ;
/* ie 6 cheat */
background-image: url('http://via.placeholder.com/3024x4032?Placeholder');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
position: absolute;
/* added */
width: 100%;
/* added */
}
/* Sticky Footer Classes */
body {
display: flex;
flex-direction: column;
}
html,
body {
height: 100%;
}
#page-content {
flex: 1 0 auto;
}
#sticky-footer {
flex-shrink: 0;
z-index: 1/* added */
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light shadow fixed-top">
<div class="container">
<a class="navbar-brand" href="#">website</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#home">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#blogs">Blogs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#events">Events</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#music">Music</a>
</li>
</ul>
</div>
</div>
</nav>
<!--—Full Page Image Header with Vertically Centered Content —-->
<header class="masthead">
<div class="container h-100">
<div class="row h-100 align-items-center">
<div class="col-12 text-center">
<h1 class="font-weight-light">website</h1>
<p class="lead">2nd line</p>
</div>
</div>
</div>
</header>
<div id="page-content">
<div class="container text-center h-100">
<div class="row justify-content-center align-items-center h-100">
<div class="col-md-7">
<h1 class="font-weight-light mt-4 text-white">Sticky Footer using Flexbox</h1>
<p class="lead text-white-50">Use just two Bootstrap 4 utility classes and three custom CSS rules and you will have a flexbox enabled sticky footer for your website!</p>
</div>
</div>
</div>
<div id="push"></div>
</div>
<footer id="sticky-footer" class="py-4 bg-dark text-white-50">
<div class="container text-center">
<small>Copyright © website</small>
</div>
</footer>
I am using bootstrap to create a layout however, I can't seem to understand why display:inline-block with vertical-align: middle isn't working.
I would prefer not to use position absolute.
JSFiddle: https://jsfiddle.net/yheep9hh/
Any help would be appreciated
HTML:
Currently using bootstrap to create the layout (navbar, etc)
<header>
<nav class="navbar navbar-transparent">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#myNavbar"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a class="navbar-brand" href="#">hello</a></div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a class="active" href="/Home">Home</a></li>
<li>Website Design</li>
<li>Tech Support</li>
<li>Data Security</li>
<li>Networking</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container-fluid wrapper bgImage">
<div class="indexWelcome">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">Welcome To Amparo Tech</h1>
<h3 class="text-center">How Can We Help You?</h3></div>
</div>
<div class="row input-fixedWidth">
<div class="col-md-12">
<form class="homeForm" method="POST">
<div class="row">
<div class="col-sm-8 col-sm-push-2 col-md-8">
<input class="homeFormEmail" type="text" name="email" placeholder="Email">
</div>
</div>
<div class="row">
<div class="col-sm-8 col-sm-push-2 col-md-8">
<input class="homeFormPostcode" type="text" name="postcode" placeholder="Postcode">
</div>
</div>
<div class="row">
<div class="col-sm-8 col-sm-push-2 col-md-8">
<textarea class="homeFormMessage" name="message" placeholder="Your Message or Tech Issue"></textarea>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="push"></div>
</div>
<footer class="footer">
<div class="container">
<div class="row clearfix">
<div class="col-md-4 text-left pull-left">
<p>name</p>
</div>
<div class="col-md-4 text-right pull-right">
<p>number</p>
</div>
<div class="col-md-4 text-center">
<p>address</p>
</div>
</div>
</div>
</footer>
CSS:
Custom CSS
* {
box-sizing: border-box;
}
html,
body {
height:100%;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin:0 auto;
margin-bottom: 10px;
}
.wrapper {
min-height:calc(100% - 82px);
margin: 0 auto -10px;
}
.footer, .push {
height: 10px;
}
.navbar {
margin:0;
height:52px;
}
input, textarea {
width: 100%;
margin:0 auto;
}
.input-fixedWidth {
max-width:750px;
margin: 0 auto;
}
.formWrapper {
position:relative;
}
.indexWelcome {
display:inline-block;
vertical-align:middle;
width: 100%;
text-align:center;
}
.navbar-transparent {
background-color: transparent;
}
.homeFormEmail {
margin-top: 20px;
}
.homeFormEmail,
.homeFormPostcode,
.homeFormMessage {
text-indent: 10px;
margin-bottom: 15px;
font-size:14px;
}
.homeFormEmail,
.homeFormPostcode {
height:40px;
}
.homeFormMessage {
height: 80px;
padding-top:10px;
resize: vertical;
}
Vertical-align:middle; works well with display:table-cell; that is if the parent div is display:table;
To display a <div> block vertically aligned in the middle, you need to use display table and table-cell to the parent and child respectively.
Have a look at the updated Fiddle (jsFiddle)
Just like:
/* Parent */
.wrapper {
display: table;
}
/* Child */
.indexWelcome {
display: table-cell;
}
Hope this helps!
since css flexbox is supported almost everywhere these days i would use it, since it makes vertical alignment very easy:
.wrapper {
display:flex;
align-items:center;
justify-content:center;
}
demo: https://jsfiddle.net/7totjt2p/2/
I'm trying to create a responsive website. Everything looks great except for the footer when in mobile view the content dont seem to align perfectly.
Here are screenshots.
This is the desktop view
This is the mobile view
As you can see everything is messed up. Here's my code
<div id="footer" class="navbar navbar-default navbar-fixed-bottom">
<div class="container-fluid">
<div class="navbar-text pull-left">
<p id="color"> Supported By </p>
</div>
<div class="navbar-text pull-left">
<img class="img-responsive" src="Images/King-Abdullah-Fund-Development-Jordan-360-Panorma-Video.png" id="imageclass1">
</div>
<div class="navbar-text pull-left">
<img class="img-responsive" src="Images/Jordan-Tourism-Board-Visit-Jordan-Lolo.png" id="imageclass1">
</div>
<div class="navbar-text" id="centered">
<img class="img-responsive" src="Images/Request-a-Recording-Jordan-360-Panorama.png" id="imagecenter">
</div>
<div class="navbar-text pull-right">
<img class="img-responsive" src="Images/Oasis-500-logo-360.png" id="imageclass">
</div>
<div class="navbar-text pull-right">
<img class="img-responsive" src="Images/Ayla-Logo.png" id="imageclass1">
</div>
<div class="navbar-text pull-right">
<img class="img-responsive" src="Images/Manaser.png" id="imageclass2">
</div>
<div class="navbar-text pull-right">
<p id="color">Partners</p>
</div>
</div>
</div>
And for the CSS
#centered {
position: absolute;
overflow: visible;
left: 40%;
}
#imagecenter{
max-width: 200px;
max-height: 200px;
}
#imageclass1{
max-width: 90px;
max-height: 90px;
}
#imageclass2{
max-width: 70px;
max-height: 60px;
}
And here's my attempt on mobile view
#media screen and (min-width: 400px) {
body {
overflow: auto;
}
.img-responsive {
position:relative;
max-width: 20%;
}
#color{
font-size: 5px;
}
#footer{
max-height: 200px;
}
}
If there's an easier approach than the way I did it, I would be very thankful.
Thank you!
Forget the pull-left pull-right on each element and use col's layout (col offset will be helpfull for the centered one).
Bootstrap provides easy ways for designing responsive sites. You just add classes to your divs and bootstrap's css will do the job! You can find it here:
http://getbootstrap.com/
I want to put an image on top of the footer, but my image is lying somewhere in the middle of the screen. I have tried vertical-align, wokaround using margin, but no success yet.
Here's jsFiddle
Here's my HTML structure,
<body id="extranav">
<div class="wrapper">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" 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="index.php"><img src="images/logo.png" ></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 navbar-right">
<li>Home</li>
<li>Link1</li>
<li>Link2</li>
<li>FAQ</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<div class="row">
<div class="col-sm-6">
</div>
<div class="col-sm-6">
</div>
</div>
</div>
<div class="push"></div>
</div>
<div class="footer">
<br><br>
<div class="text-center">
<a href="#" class="fa icon fa-twitter fa-lg" ></a>
<br><br>
<div class="footer-links">
Feedback
AboutUs
FAQ
<p>© All Rights Reserved</p>
</div>
</div>
</div>
</body>
And the CSS
html,body
{
height: 100%;
/*font-size: 15pt;*/
font-family: 'Varela Round', sans-serif;
background-color: #fff;
min-height: 1024px;
}
.footer
{
background-color: #2D3339;
color: white;
}
.footer a
{
line-height: 2.8em;
}
.footer-links a,.footer-links p
{
color: #aaa;
text-align: center;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -200px;
}
.footer, .push {
height: 200px;
font-size: 15px;
}
.push
{
background: url("http://i564.photobucket.com/albums/ss86/ban0107/aya/footer.gif") repeat-x scroll center bottom transparent;
}
Why don't you put the footer image div directly inside the footer? It will naturally fall right above the footer that way, then you just need to adjust the CSS so that the footer is 400px tall(200px for the image and 200px for the footer section below the image):
.footer
{
height:400px;
font-size: 15px;
background-color:#2D3339;
color:white;
}
.push
{
height:200px;
background:url("http://i564.photobucket.com/albums/ss86/ban0107/aya/footer.gif") repeat-x scroll center bottom;
}
JSFiddle
Do you mean like this?
Relevant HTML:
<div class="footer">
<div class="push"></div>
<br />
<br />
<div class="text-center">
<br />
<br />
<div class="footer-links">
Feedback
AboutUs
FAQ
<p>© All Rights Reserved</p>
</div>
</div>
</div>
Relevant CSS:
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -400px;
}
.footer {
height: 400px;
font-size: 15px;
}
.push
{
height:200px;
background: url("http://i564.photobucket.com/albums/ss86/ban0107/aya/footer.gif") repeat-x scroll center bottom transparent;
}
I'm currently making a website using bootstrap, but at the end of the homepage's background image there is a piece of white space about 50px in length.
Is it possible to get rid of this strip of white space? I have provided my html and css code for the site. Help would be much appreciated.
HTML
<!-- html-->
<div id="title-page">
<div class="container">
<div id="nav" class="navbar navbar-inverse navbar-static-top">
<div class="container">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
<div id="pic-headings">
<h1 class=" text-center" ></h1><>
<br>
<h2 class=" text-center"></h2>
</div>
</div>
</div>
CSS
<!--css-->
#nav{
margin-bottom: 0px;
background-color: transparent;
border: none;
padding-right: 20px;
}
.navbar-brand{
color: #fff;
}
#title-page{
background-size: 100%;
background-size: cover;
background-image: url(stephen1.jpg);
color: #fff;
height: 830px;
margin-bottom: 0px;
}
#pic-headings{
padding-top: 200px;
text-align: center;
}
h1{
font-family: eb-garamond, sans-serif;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
h2{
font-family: eb-garamond, sans-serif;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
On line 24 you have some stray characters <> which can't be helping your situation. And you may consider restructuring your code without the nested container classes and overall just not nesting your div's so deeply. In the process of doing that you will most certainly identify the problem.
Please post link or jsfiddle or more code, and which version of Bootstrap your trying to use to get more help.
this may or may not help get you started
<div id="header">
<div class="container clearfix">
<ul id="nav">
<li></li>
</ul>
</div>
</div>
<div class="container">
<div class="row-fluid">
<div class="span12">
something
</div>
</div>
</div>