I am using the pagination component in bootstrap, the pagination itself is simple:
<ul class="pagination">
<li class="disabled"><span aria-hidden="true">«</span></li>
<li class="active">1 <span class="sr-only">(current)</span></li>
</ul>
However I want to show the metadata like total pages, total records beside the pagination, and I want the information can be aligned at middle by the pagination control.
And I can not add the page information inside the ul element since it is generated by a third-party library.
I have tried this:
http://plnkr.co/edit/abVwf6rnluYKiOOzXNrt?p=preview
As shown it does not align as expected.
And it seems that I can set the padding or margin for the div.pageinfo or set the height and line-height, but I wonder if this is possible without harding coding
The Problem
There are two main issues to contend with:
One issue blocking you from being able to move your blocks around is that you had the wrapping div with an inline-style of display: inline-block and Bootstrap classes like pull-left which were forcing your elements to display as they were.
The need for IE8 support will make it difficult at best to provide the same experience for your users without a hit to the performance of your site.
Recommendation
The expectation to have websites render identically in IE8 as to their modern counterpart is more or less unreasonable in this day and age. The number of hoops you'll have to jump through to do that is pretty insane. Bootstrap itself is also deprecating IE8 support as of Bootstrap 4. The only way I'd see a reasonable case for this is if there was Google Analytics data to show that a majority of your users are on IE8.
So the best thing you can do is to either (1) recommend that the pagination items are limited to X number so that it fits a certain width and update the fixed width every time something is added, or (2) accept graceful degradation of your site on IE8 in order to provide a better experience for what I am assuming is the majority of your users on modern browsers.
Solution: Modern Browsers
The easiest way to achieve what you want is to utilize flexbox. I've removed any unnecessary class names and included the simplest code sample below (that would primarily work in Chrome). The code with all the prefixes can be found in the demo, but this should get you what you want (minus IE8 and IE9).
Code (Demo)
HTML
<div class="text-center">
<div id="nav">
<div class="pageinfo">Total:xxx 1/xx</div>
<div>
<ul class="pagination">
<li class="disabled">
<a href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<li class="active">
1 <span class="sr-only">(current)</span>
</li>
</ul>
</div>
</div>
CSS
#nav {
display: flex;
justify-content: center;
align-items: center;
}
.pageinfo {
margin-bottom: 5px;
margin-right: 10px;
}
Update: IE8 Solution
Here is a demo for an IE8 alternative that utilizes blocks in order to achieve the effect. However, while I know that you specifically requested not to hard code the size of the elements, that is not something (to my knowledge) that can be avoided due to the need to support legacy browsers like IE8.
The key thing to understand is that legacy browsers are far less intelligent than their modern counterparts. The only other alternative I can think that you can try is to use JavaScript to determine the width of the element dynamically, but it begins to be a lot of effort and impacts performance as well.
HTML
<div class="text-center">
<div id="nav">
<div class="pageinfo">Total:xxx 1/xx</div>
<div>
<ul class="pagination">
<li class="disabled">
<a href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<li class="active">
1 <span class="sr-only">(current)</span>
</li>
</ul>
</div>
</div>
</div>
CSS
#nav {
display: block;
width: 200px;
margin: 0 auto;
}
#nav div {
display: block;
}
.pageinfo {
float: left;
margin-right: 10px;
margin-top: 8px;
}
.page-menu {
float: left;
}
.page-menu ul {
margin: 0;
padding: 0;
margin-top: 2px;
}
I hope you are looking for something like below,
/* Styles go here */
.mata-data {
display: inline;
position: absolute;
margin-top: 27px;
margin-left: 25px;
}
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap#3.3.5" data-semver="3.3.5" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="text-center">
<div>
<div class="mata-data">Total:xxx 1/xx</div>
<div class="container pull-left">
<ul class="pagination">
<li class="disabled"><span aria-hidden="true">«</span></li>
<li class="active">1 <span class="sr-only">(current)</span></li>
</ul>
</div>
</div>
</div>
</body>
</html>
Related
I am having quite a time debugging some CSS on my deployed website. For context: this is my first deployed website. All of my debugging was done with LiveServer locally and had none of these problems. My navbar design uses two navigations with different ordered elements, one for desktop and one for mobile. I use the style #mobile-nav{ display: none;} to intially keep the mobile block hidden, then using a media query #desktop-nav{display: none}; and mobile-nav{ display: block;} to switch them. However I am running into many issues with this in different browsers. First off, on my iphone, the website displays perfectly, you can check yourself because it is live. Secondly, in Chrome, Firefox, or edge the mobile-nav never becomes visible on the query and when inspected in each browser, the style is written as #mobile-nav{display: none !important;} which is not written in the stylesheet anywhere, only shows !important on the live browsers on desktop. Thirdly, in the brave browser, both navbars are visible all the time. I will attach the HTML block with my navbars below, as well as the related styles. Somebody please tell me what I'm doing wrong here.
the URL is dsarmwrestling.com
<nav id="desktop-nav">
<!-- Nav bar element designed to have center logo with links on either side -->
<ul>
<a class="navlink" href="sponsor.html">Sponsor</a>
<a class="navlink" href="rank.html">Rankings</a>
<a href="index.html">
<img id="logo" src="images/BackLogoText1.png" alt="Logo">
</a>
<a class="navlink" href="social.html">Social</a>
<a class="navlink" href="about.html">About</a>
</ul>
</nav>
<nav id="mobile-nav">
<!-- Nav bar element designed to have center logo with links on either side -->
<ul id="nav-wrapper">
<a href="index.html" id="logolink">
<img id="logo" src="images/BackLogoText1.png" alt="Logo">
</a>
<ul id="nested-nav">
<a class="navlink" href="sponsor.html">Sponsor</a>
<a class="navlink" href="rank.html">Rankings</a>
<a class="navlink" href="social.html">Social</a>
<a class="navlink" href="about.html">About</a>
</ul>
</ul>
</nav>
#mobile-nav{
display: none;
}
#media (max-width: 1199.98px){
#desktop-nav{
display: none;
}
#mobile-nav{
display: block;
}
#nav-wrapper{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#logo{
width: 100%;
}
}
on even further inspection, it appears that the styles I have tried in the previous changes are persistent across redeployments. I am using hostinger and I am completely deleting all website files and folders when I make a change and redoing the process of importing a website. Here are images for proof that the hosted css is different than the css found on inspect.
"the styles I have tried in the previous changes are persistent across redeployments" - this looks like a cache issue (your browser doesn't bother downloading the same .css file again and again). Did you try clearing your cache between redeployments?
I don't even know where to start on this one. When I resize below 1600px the site breaks 100% even though it has media queries in place to resize/hide/move elements. But to pinpoint one issue that eludes me, I have a logo in an id that is set to a height of 175px and width to auto. At any browser size it's always a height of 564px. Check out some code below:
img #fpa-logo {
bottom: -25px;
height: 175px;
margin-left: 12.5%;
position: absolute;
width: auto;
}
<div class="row">
<div class="col-sm-12 nav" id="nav-w-back">
<div class="col-sm-5 fLeft">
<img src="../images/FPA-logo-new150-02.png" alt="FPA Logo" id="fpa-logo">
</div>
<div class="col-sm-7">
<ul class="nav fRight" id="nav-ul">
<li>Home</li>
<li>Services<span style="font-size: .75em"> ▼</span>
<ul>
<li>Personalized Care</li>
<li>Health Care Services</li>
</ul>
</li>
<li>Links<span style="font-size: .75em"> ▼</span>
<ul>
<li>Patient Information and Forms</li>
<li>Patient Friendly Sites</li>
</ul>
</li>
<li>Staff Bios</li>
<li>Careers</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
If you're interested in more code - the test site is: http://fpacny.com/index_test.php where you can play with the sizing etc. At this point you would likely notice that the main image background only resizes properly when an inline HTML style addition of:
style="height: auto; width: 100%;"
is added. Otherwise, that breaks too.
Why won't my linked CSS override this? I've never had this issue on any website I've developed and it is driving me absolutely nuts!
JSFiddle: https://jsfiddle.net/hjo8pLxe/
You need to write
img#fpa-logo
to target the logo.
Edit: Just saw you are using bootstrap 4: Why not use the "img-fluid" class on the image? Then it won't get too big and scale down automatically if the row/column gets smaller.
<img class="img-fluid" {...} >
Or do you need any special behaviour, other than automatic resizing?
And you should also look more into the column features of bootstrap, you are using a lot of position: absolute in your css which is not needed at all for your design and would prevent a lot of errors if you would use bootstrap instead.
Change your ccs to
img#fpa-logo {
bottom: -25px;
height: 175px;
margin-left: 12.5%;
position: absolute;
width: auto;
}
Answered
I begin to think I am losing my mind...
Currently I'm trying to set up a simple top navigation which is margin-0-auto-ed in the header. It contains five children <li>-elements with each a width of 200px. If I can still calculate correctly, that equals 1000px in width.
But to hold all children the top <ul>-element requires 1016px width. I just don't get where this comes from. All margins, paddings etc. are removed by a CSS Reset.
Code is as follows:
HTML
<div id="header-wrapper">
<div id="header">
<ul id="head-menu">
<li class="head-menu-item">Navlink</li>
<li class="head-menu-item">Navlink</li>
<li class="head-menu-item">Navlink</li>
<li class="head-menu-item">Navlink</li>
<li class="head-menu-item">Navlink</li>
</ul>
</div>
</div>
CSS
#header-wrapper { width: 100%; height: 56px; position: relative }
#header { width: 100%; height: 56px; background: #111; position: absolute; }
#head-menu { width: calc(5*200px); margin: 0 auto;}
.head-menu-item { display: inline-block }
.head-menu-item-link { display: inline-block; padding: 20px; width: calc(200px - 40px); text-align: center }
Update 29.09.13
If anyone wonders, instead of commenting out the white spaces or going for some negative left-margins, I just used this syntax:
</li><li class="head-menu-item">Navlink
</li><li class="head-menu-item">Navlink
That has done it easily, without altering the code too much and keeps it clean.
The problem is inline elements add a extra space between each other because of the empty space on your html ( even a simple line-break ) here is your fix jsfiddle
HTML
<div id="header-wrapper">
<div id="header">
<ul id="head-menu">
<li class="head-menu-item">Navlink
</li><!--
--><li class="head-menu-item">Navlink
</li><!--
--><li class="head-menu-item">Navlink
</li><!--
--><li class="head-menu-item">Navlink
</li><!--
--><li class="head-menu-item">Navlink
</li>
</ul>
</div> </div>
display:inline-block is inserting spaces in between the li's (that is, displaying the white space shown in the HTML). You can see this more clearly if you put a background color on the li's.
or else if you just want your html to look neat, you can add a negative margin to the display:inline-block elements (to account for the gaps between them in html code), but it would work only if you have a kinda fixed layout, which rarely changes, and you are too adamant to mess up your code by removing spaces or adding comments
I don't have enough 'reputation' to comment, but I would like to restate something Vinícius Moraes said, WHITE SPACES in you code ie...
<div id="foo"></div>
<div id="bar"></div>
<div id="thing"></div>
as seen here by putting on different lines (creating a coded white space) can make a a dramatic effect, where putting...
<div id="foo"></div><div id="bar"></div><div id="thing"></div>
can create the desired effect, as I found after spending several hours wondering why my three 's where next lining when positioned perfectly with a jquery resize. Thank you again Vinícius Moraes for pointing out this rookie mistake.
I want the vertical border of the vertical tab to run on the whole page instead of finishing off where the tabs end.
however since I have given border-right on the tab it ends
with the last tab that is trending. Giving border-right to the content makes sure the height of the border is right but it spoils the spacing between tab and content.
HTML :-
<div class='tabbable tabs-left'>
<ul class='nav nav-tabs'>
<li class='active'>
All
</li>
<li>
New
</li>
<li>
Featured
</li>
<li>
Ending Soon
</li>
<li>
Trending
</li>
</ul>
</div>
This is not default Bootstrap behavior so you will have to modify the css a little. For this to work, the vertical tab <ul> and all of its parents should have the property height: 100%.
For html and body I would apply the styling directly but for the <div> and <ul> I would use custom class so as not to modify the Bootstrap classes to maintain expected behavior for eventual future use in other layouts.
Here is a demo.
The css to add:
html{
height: 100%;
}
body{
height: 100%;
}
.tabbable.tabs-left.full-height{
height: 100%;
}
.nav.nav-tabs.full-height{
height: 100%;
}
The html to modify:
<body>
<div class='tabbable tabs-left full-height'>
<ul class='nav nav-tabs full-height'>
...........
I want to make a scalable 100% table using DIV's only. I don't want to use to display:table or display: table-cell since this doesnt work with IE7. The goal is to make this as cross browser compliant as possible.
<div class="Wrapper">
<div class="Row">
<div class="Cell">1</div>
<div class="Cell">2</div>
<div class="Cell">3</div>
</div>
<div class="Row">
<div class="Cell">4</div>
<div class="Cell">5</div>
<div class="Cell">6</div>
</div>
</div>
If it's possible, I would like to make the cell width auto so if I add in more cells, it would fit into the row perfectly without pushing the cell to a second row. Been trying to figure this out. Any help would be awesome. Thanks
You can give your cells a width of 100/amount of cells %.
But if you want it automatically adjusted to the number of cells you will need javascript.
But I can't really get what advantage you see making a table out of divs.
I think it's not a nice idea to...reinvent tables (what about header, footer and groups?). You may use 100% width (so it'll works with 90% of browsers) and conditional include for IE7, patching them with a CSS workaround (anchors?) for that people that are still using IE7.
Something like:
http://linuxandfriends.com/2009/04/04/how-to-style-div-elements-as-tables/
But what for?
I recently did this as, even for tabular data, I wanted to challenge myself to present it using ul and li. You can emulate ul and li to act as your rows and columns.
Consider the following:
<ul id="column-one">
<li>Cell #1</li>
<li>Cell #2</li>
<li>Cell #3</li>
</ul>
<ul id="column-two">
<li>Cell #1</li>
<li>Cell #2</li>
<li>Cell #3</li>
</ul>
CSS
ul { list-style: none; }
ul li { height: 20px; }
#column-one,
#column-two {
float: left;
position: relative;
width: 50%;
}
If you need to emulate colspan:
.span-4 {
clear: left;
float: left;
position: relative;
width: 100%; /* if you have 4 UL elements */
}
You'll run into issues if the height of your cells is different. You could create "rowspan" classes which would increase the height.
It's totally up to you. I have always been a proponent for displaying tabular data within a <table>, but if you want to challenge yourself, please do so!