Center-align horizontal inline-block list of page numbers - css

I am trying to center-align a block of page numbers at the bottom of this page. The HMTL and CSS looks like this:
.pt-cv-pagination-wrapper {
position: relative;
display: block;
text-align: center;
margin: 20px 0;
padding: 0;
}
.pt-cv-pagination {
position: static;
display: inline-block;
text-align: center;
margin: 20px 0;
padding: 0;
}
li {
position: relative;
display: inline;
text-align: center;
margin: 0;
padding: 0;
}
.pt-cv-pagination a {
position: relative;
display: block;
float: left;
padding: 6px 12px;
margin: 1em;
}
<div class="pt-cv-pagination-wrapper">
<ul class="pt-cv-pagination pt-cv-ajax pagination" data-totalpages="3" data-currentpage="1" data-sid="98f4b5c3fg" data-unid="">
<li class="cv-pageitem-prev">
<a title="Go to previous page">‹</a>
</li>
<li class="cv-pageitem-number">
<a title="Go to page 1">1</a>
</li>
<li class="cv-pageitem-number">
<a title="Go to page 2">2</a>
</li>
<li class="cv-pageitem-number active">
<a title="Current page is 3">3</a>
</li>
<li class="cv-pageitem-next active">
<a title="Go to next page">›</a>
</li>
</ul>
<div class="clear pt-cv-clear-pagination"></div>
</div>
If you look on a narrow screen (on the live site), it will be easier to see that the page numbers are very slightly off centre. I've read several articles on here that all make sense but seem to have no further effect on my outcome. It's driving me crazy trying figure out why it's not working. Any help appreciated!

Ah, the art of centering elements in CSS. Good thing we have flexbox to help us all out.
This should do the trick:
.pt-cv-pagination-wrapper .pt-cv-pagination.pagination {
display: flex;
justify-content: center;
}

The centering looks fine. If you want to have a border on the <li> then change the inline of the li in an inline-block.
.pt-cv-pagination li {
position: relative;
display: inline-block;
text-align: center;
margin: 0;
padding: 0;
}
Remove the float from the <a> to have the block on this anchor working the correct way.
.pt-cv-pagination a {
position: relative;
display: block;
padding: 6px 12px;
margin: 1em;
}

Related

Align item left, or right if no room left in window

How can you display an item per default in its "normal" position (preferably over any following items), like this:
div {
border: 1px solid black;
}
ul {
display: flex;
padding: 0;
list-style: none;
width: 250px;
border: 1px solid black;
}
li {
display: flex;
position: relative;
}
.item {
padding: 0.4em;
background-color: #f99;
}
.dropdown {
position: absolute;
left: 100%;
z-index: 1;
padding: 0.4em;
opacity: 0.7;
background-color: #2f6f44;
}
<ul>
<li>
<div class="item">First</div>
</li>
<li>
<div class="item">Second</div>
<div class="dropdown">Dropdown</div>
</li>
<li>
<div class="item">Third</div>
</li>
<li>
<div class="item">Fourth</div>
</li>
</ul>
but if the window becomes too small (represented by the ul here), it sticks to the right:
div {
border: 1px solid black;
}
ul {
display: flex;
position: relative;
padding: 0;
list-style: none;
width: 150px;
border: 1px solid black;
}
li {
display: flex;
}
.item {
padding: 0.4em;
background-color: #f99;
}
.dropdown {
position: absolute;
right: 0;
z-index: 1;
padding: 0.4em;
opacity: 0.7;
background-color: #2f6f44;
}
<ul>
<li>
<div class="item">First</div>
</li>
<li>
<div class="item">Second</div>
<div class="dropdown">Dropdown</div>
</li>
<li>
<div class="item">Third</div>
</li>
<li>
<div class="item">Fourth</div>
</li>
</ul>
In other words, if (this.left + this.width > totalWidth) stick right else stay left.
I can either get one or the other behaviour (like above), but not so that it switches seamlessly between the two.
The simplest solution is to compute the element width and the window width and position it using JavaScript, but bugs/edge cases easily slip in, so I'm trying to look for a complete CSS solution.
Any number of containers/wrappers are welcome. One solution I tried looking at was wrapping all the "following" elements (Third and Fourth in the examples above) in a separate li with Dropdown. That way a flex element can take up the space between the previous element (Second) and the edge of the container, but then Dropdown can't go any further left than Second (if the container gets too small).
The elements are dynamic in width based upon changing content.

Question on why this list item needs float?

So i was looking at https://youtu.be/8gNrZ4lAnAw?t=8831 to learn how to do repsonsive sites, at step 2:27:11 he creates the navigation by
Edit:
Forgot to mention, it's mobile first, so the below css is for width > 1024, the mobile css is this:
nav ul {
position: fixed;
width: 60%;
top: 0;
right: 0;
text-align: left;
background-color: rgba(36,41,44);
height: 100%;
z-index: 7;
padding-top: 3em;
}
1024 css
nav ul {
/* NOTE position fixed to reset */
position: inherit;
width: auto;
background: none;
display: flex;
padding-top: 0;
}
nav ul li {
float: left;
}
I don't understand why flex on the ul didn't work, that you still need to float the list item? If anyone knows what's going on that would be really helpful.
edit: html
<nav>
<a href="#" class="hide-desktop">
<img src="images/ham.svg" alt="toggle menu" class="menu" id="menu" />
</a>
<ul class="show-desktop hide-mobile">
<li id="exitMenu" class="exit-btn hide-desktop"><img src="images/exit.svg" alt="exit menu"></li>
<li>Home</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>

problem with creating dropdown within flexbox navigation bar, the dropdown content can't be displayed normally

I've been having trouble positioning and displaying dropdown menu below the navigation bar which is styled with flexbox, it appeas that the dropdown menu that overflows out of the flex container is hidden, even though it was given position: absolute and z-index. dropdown menu hidden vertically display please help me and take a look at my code.
<ul class="topNav" id="myTopNav" role="navigation">
<li>shopping bag</li>
<li>sign in</li>
<li class="all_categories">
<ul class="categories">
<li class="category-women">
women
<ul class="sub-category">
<li> New in!</li>
<li> Tops</li>
<li> Coats & Jackets</li>
</ul>
</li>
<li class="category-men">men</li>
<li class="category-home">home & gift</li>
</ul>
</li>
</ul>
The .topNav is the flex container is styled like this:
.topNav {
width: 100%;
padding-left: 2%;
padding-right: 2%;
padding-top: 0.6%;
padding-bottom: 0.6%;
border-bottom: #c9c8c7 0.02em solid;
position: sticky;
top: 0;
overflow: hidden;
display: flex;
flex-direction: row;
align-items: center;
}
The links inside navigation bar are displayed as block;
here's my code for the drop down menu:
.category-women{
border: 1px dotted red;
}
.sub-category {
display: none;
position: absolute;
background-color: green;
min-width: 100px;
z-index: 2;
border: 1px solid yellow;
}
.sub-category a {
font-size: 1em;
display: block;
padding: 0;
margin: 0 8px;
background-color: green;
}
.category-women:hover .sub-category {
display: flex;
flex-direction: column;
justify-content: space-between;
}

Vertically center link text in flexbox layout

I have a menu made up of 5 links. I need each link to be 33% of the available width with spacing between the links. The horizontal and vertical spacing must be the same.
Links must be the same height as the tallest link in there row, even though the length of the link text will vary per link. Ideally all links would be the same height but I doubt this is possible.
The link text is dynamic and will change. This for a responsive website so the page width will vary.
I cant change the HTML at all.
This is for a mobile only website so I dont need to worry about older browsers. I should be fine to use flexbox.
<ul>
<li>
<a href="#">
<span>Link 1</span>
</a>
</li>
<li>
<a href="#">
<span>Link 2 has much longer text than the other links</span>
</a>
</li>
<li>
<a href="#">
<span>Link 3</span>
</a>
</li>
<li>
<a href="#">
<span>Link 4</span>
</a>
</li>
<li>
<a href="#">
<span>Link 5</span>
</a>
</li>
</ul>
My code below works fine in Chrome. The only thing I still need to do is vertically center the link text (see the image below).
The align-items: center property looked promising however If I apply it to the ul then the lis' stop being the same height.
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
ul {
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
width: 50%;
border: 2px solid black;
margin: auto;
}
li {
list-style-type: none;
float: left;
width: 32%;
background: grey;
text-align: center;
overflow: hidden;
margin-bottom: 2%;
vertical-align: middle;
}
li:nth-of-type(2),
li:nth-of-type(5)
{
margin-left: 2%;
margin-right: 2%;
}
a {
display: inline-block;
margin: -10em;
padding: 10em;
}
a {
background: gold;
}
a:hover {
background: green;
}
http://codepen.io/anon/pen/CeiqK
I don't know if this solution that I post here will be valid for you. Anyway, I changed your css a bit to get it:
ul {
margin: 0;
padding: 0;
width: 50%;
border: 2px solid black;
margin: 0 auto;
font-size: 0; /* this fix inline-block margins */
}
li {
font-size: 14px;
list-style-type: none;
display: inline-block;
width: 32%;
min-height: 34px;
background: grey;
text-align: center;
overflow: hidden;
margin-bottom: 2%;
}
a {
display: table-cell;
width: 100em;
height: 34px;
vertical-align: middle;
}
Check it at codepen
Creates this:

How do i align my Thumb Nail images horizontally in CSS?

I am trying to align a set of images horizontally within a div tag and then display a horizontal scroll bar when the images exceed the length of the div tag. I am relatively new to CSS and have tried everything I can think of. The below code displays my images vertically!!!
Thank you very much for any help.
Inside the body tag:
<div id="TNBox">
<ul class="imagelist">
<li>
<img id="tnimage1" src="images/tn-images/Rio-Street-Art-TN01.jpg">
</li>
<li>
<img id="tnimage2" src="images/tn-images/Rio-Street-Art-TN02.jpg">
</li>
<li>
<img id="tnimage3" src="images/tn-images/Rio-Street-Art-TN03.jpg">
</li>
<li>
<img id="tnimage4" src="images/tn-images/Rio-Street-Art-TN04.jpg">
</li>
<li>
<img id="tnimage5" src="images/tn-images/Rio-Street-Art-TN05.jpg">
</li>
</ul>
</div>
And the CSS:
#TNBox {
width: 500px;
height: 88px;
border: 1px solid black;
position: absolute;
left: 50px;
top: 320px;
overflow-x: auto;
display: inline-block;
text-decoration: none;
}
.imagelist {
list-style: none;
margin: 0px;
padding: 0px;
}
#TNBox{
width: 500px;
height: 88px;
border: 1px solid black;
position: absolute;
left: 50px;
top: 320px;
overflow-x: auto;
display: inline-block;
text-decoration: none;
white-space:nowrap;
}
.imagelist{
list-style: none;
margin: 0px;
padding: 0px;
}
.imagelist li{
display:inline-block;
}
Preview >> jsfiddle (I have styled images too)
Link to fiddle. I also changed the image urls to point to something that exists
http://jsfiddle.net/GVdMz/2/
Here is what I added:
To get the images to display horizontally
.imagelist li{
display: inline;
}
And this will make a horizontal scroll appear if the images extend past the width of #TNBox
#TNBox{
white-space:nowrap;
}

Resources