How to place custom scrollbar buttons one by one left/right? - html

Problem
Scroll bars are implemented with images.
I made the scroll bar like this with reference to the following.
With reference to the following, the scroll bar has become like this now.
Reference site:
I want to make knob of input range an image - StackOverflowJP (I'm sorry at the Japanese site..)
Implement scrollbar-button - JSFiddle
▼ I want to do this:
specify the width & height size of the scrollbar
scrollbar-button left / right one by one
position scrollbar at a distance away from target
Code
▼ Probably is not properly displayed unless it's a webkit browser (eg Chrome etc.)
html {font-size: 62.5%;}
#thumb-wrap {
position: relative;
box-sizing: border-box;
width: 100%;
margin-bottom: 12.4rem;
overflow-x: scroll;
overflow-y: hidden;
writing-mode: bt-lr; /* IE */
-webkit-appearance: none;
}
#thumb-wrap::-webkit-scrollbar {
width: 33.2rem;
}
#thumb-wrap::-webkit-scrollbar-track {
-webkit-appearance: none;
width: 30.1rem;
background: url("https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228080150.png");
}
#thumb-wrap::-webkit-scrollbar-thumb {
width: 1.5rem;
height: 1.3rem;
background: #fff;
border: 1px solid #000;
}
#thumb-wrap::-webkit-scrollbar-button {
width: 1.6rem;
height: 1.6rem;
}
#thumb-wrap::-webkit-scrollbar-button:start {
display: block;
}
#thumb-wrap::-webkit-scrollbar-button:horizontal:decrement {
width: 1.6rem;
height: 1.6rem;
background: url("https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228080158.png") no-repeat center center;
}
#thumb-wrap::-webkit-scrollbar-button:end {
display: block;
}
#thumb-wrap::-webkit-scrollbar-button:horizontal:increment {
width: 1.6rem;
height: 1.6rem;
background: url("https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228080155.png") no-repeat center center;
}
#thumb-wrap ul {
width: 100%;
white-space: nowrap;
}
#thumb-wrap li {
display: inline-block;
}
#thumb-wrap li:first-child {
margin-left: 3rem;
}
#thumb-wrap li:last-child {
margin-right: 3rem;
}
#thumb-wrap li + li {
margin-left: 3rem;
}
<div id="thumb-wrap">
<ul>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075715.png" alt="あ=a" />
</li>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075712.png" alt="い=b" />
</li>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075710.png" alt="う=c" />
</li>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075706.png" alt="え=d" />
</li>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075704.png" alt="お=e" />
</li>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075810.png" alt="か=f" />
</li>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075807.png" alt="き=g" />
</li>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075805.png" alt="く=h" />
</li>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075802.png" alt="け=i" />
</li>
<li>
<img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075759.png" alt="こ=j" />
</li>
</ul>
</div>

This is the best I could do using CSS and JS. It uses a range input as a slider
<input id="slider" type="range" min="1" max='100' value="0" step="1">
with the value representing the percentage of the view to scroll left :)
I could not find a pure-CSS solution
See demo below
$(function() {
// this just reads the initial value of the input and displays it on the span
$("#position").text($("#slider").val());
// this is an event handler. The the slider changes it executes the function within
$("#slider").on('change input', function() {
// display the input value on the span (updates it)
$("#position").text($(this).val());
// calculate the new left position of the displayDiv by getting a percentage of the width
// of the parent.
// the idea here is that the range has a min value of 1 and a max of 100, they represent
// a percentage of pixels to move right or left. So if I move the input/range slider to
// have a value of 10, I mean to slide the displayDiv 10%.
// this means, 10% of the width of the wrapper (350px) which is 35px;
var posLeft = $(this).val() * $("#wrapper").width() / 100;
// set the new left position of the displayDiv with the calculated value
$("#displayDiv li").css('left', -posLeft);
});
});
#wrapper {
overflow: hidden;
width: 400px;
white-space: no-wrap;
}
.nav {
padding:0;
margin:0;
width: 400px;
height: 210px;
columns: 100px 100;
column-gap: 1px;
overflow: hidden;
}
.nav li {
position: relative;
list-style: none;
display: inline-block;
padding: 2px;
margin: 0 auto;
text-align: center;
}
input['range'] {
margin: 0 auto;
width: 100px;
}
#sliderDiv {
text-align: center;
width: 350px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="wrapper">
<ul id="displayDiv" class="nav">
<li>
<img src="http://placekitten.com/100/200" />
</li>
<li>
<img src="http://placekitten.com/100/200" />
</li>
<li>
<img src="http://placekitten.com/100/200" />
</li>
<li>
<img src="http://placekitten.com/100/200" />
</li>
<li>
<img src="http://placekitten.com/100/200" />
</li>
<li>
<img src="http://placekitten.com/100/200" />
</li>
<li>
<img src="http://placekitten.com/100/200" />
</li>
<li>
<img src="http://placekitten.com/100/200" />
</li>
<li>
<img src="http://placekitten.com/100/200" />
</li>
</ul>
</div>
<div id="sliderDiv">
<input id="slider" type="range" min="1" max='100' value="0" step="1">
</div>
Position: <span id="position"></span> %

Related

LI's with variable pixel/% widths not followed in full width of container

I'm working with the following code which creates a series of boxes as <UL><LI> tags. The splits are separate <LI>s with a background img containing the arrows. What needs to happen is that if you resize, the arrow-LI size must not change, but the data-LI size should accommodate and shrink accordingly. To accomplish this, the arrow-LI widths are specified in px, and the data-LI in %. At all times, the entire box bar must be 1-line.
This should work, but I see that if I resize, the last box is brought out to a 2nd line, and at some point later the next-to-last box will be lowered to a 2nd line too. The text does shrink, but it should auto-shrink even more to satisfy any reasonable browser width, while the arrow LIs are fixed.
Some text e.g. "Reference Letter Deadline" did shrink, but not enough to keep everything on 1 line.
Code:
<ul class="arrowDateBoxes dateLists">
<li class="arrowDateBox1">
<div class="arrowDateBoxContent">Application Cycle Opens</div>
</li>
<li class="arrowDateBox1Arrow">
</li>
<li class="arrowDateBox2">
<div class="arrowDateBoxContent">Application Deadline</div>
</li>
<li class="arrowDateBox2Arrow">
</li>
<li class="arrowDateBox1">
<div class="arrowDateBoxContent">Reference Letter Deadline</div>
</li>
<li class="arrowDateBox1Arrow">
</li>
<li class="arrowDateBox2">
<div class="arrowDateBoxContent">Selections for Program Interviews</div>
</li>
<li class="arrowDateBox2Arrow">
</li>
<li class="arrowDateBox1">
<div class="arrowDateBoxContent">Interviews</div>
</li>
<li class="arrowDateBox1Arrow">
</li>
<li class="arrowDateBox2">
<div class="arrowDateBoxContent">Offer Acceptance Deadline Date</div>
</li>
<li class="arrowDateBox2Arrow">
</li>
<li class="arrowDateBox1">
<div class="arrowDateBoxContent">ICRC Term Begins</div>
</li>
CSS
/* Generally for all boxes */
ul.arrowDateBoxes li {
display: inline;
float:left;
font-size:14px;
font-weight: bold;
}
/* Bi-color:
data boxes (arrowDateBoxN), width as % to be flexible, and
arrow boxes (arrowDateBoxNArrow), width as px to be fixed */
/* ----------------- */
.arrowDateBox1 {
background-color: #E8E8E8;
color: #143A66;
width: 12.5%;
height: 57px;
padding-left: 15px;
}
.arrowDateBox1Arrow {
background-image: url('../images/menuarrow-split1.svg');
background-repeat: no-repeat;
width: 30.5px;
height: 57px;
}
.arrowDateBox2 {
background-color: #A9CDF1;
color: #143A66;
width: 12.5%;
height: 57px;
padding-left: 15px;
}
.arrowDateBox2Arrow {
background-image: url('../images/menuarrow-split2.svg');
background-repeat: no-repeat;
width: 30.5px;
height: 57px;
}
Per request, the SVGs (bi-colored arrow splits):
<svg xmlns="http://www.w3.org/2000/svg" width="30.541" height="57.001" viewBox="0 0 30.541 57.001">
<g id="Group_225" data-name="Group 225" transform="translate(-312.858 -383.001)">
<path id="Polygon_30" data-name="Polygon 30" d="M28.5,0,57,18.143H0Z" transform="translate(331.001 383.002) rotate(90)" fill="#e8e8e8"/>
<path id="Subtraction_11" data-name="Subtraction 11" d="M18.4,57H0L18.142,28.5,0,0H18.4Z" transform="translate(325 383.001)" fill="#a9cdf1"/>
</g>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="30.541" height="57.001" viewBox="0 0 30.541 57.001">
<g id="Group_225" data-name="Group 225" transform="translate(-312.858 -383.001)">
<path id="Polygon_30" data-name="Polygon 30" d="M28.5,0,57,18.143H0Z" transform="translate(331.001 383.002) rotate(90)" fill="#a9cdf1"/>
<path id="Subtraction_11" data-name="Subtraction 11" d="M18.4,57H0L18.142,28.5,0,0H18.4Z" transform="translate(325 383.001)" fill="#e8e8e8"/>
</g>
</svg>
Change the ul to display:flex. It'll keep it all on one line. You can also probably cut out a fair amount of markup by using the ::after pseudo element for your arrows. Fire over the svg (or provide a link to it) and I'll have a look.
ul.arrowDateBoxes {
display:flex;
}
/* Generally for all boxes */
ul.arrowDateBoxes li {
list-style-type: none;
font-size: 14px;
font-weight: bold;
overflow: hidden;
}
/* Bi-color:
data boxes (arrowDateBoxN), width as % to be flexible, and
arrow boxes (arrowDateBoxNArrow), width as px to be fixed */
/* ----------------- */
.arrowDateBox1 {
background-color: #E8E8E8;
color: #143A66;
width: 12.5%;
height: 57px;
padding-left: 15px;
}
.arrowDateBox1Arrow {
background-image: url('../images/menuarrow-split1.svg');
background-repeat: no-repeat;
width: 30.5px;
height: 57px;
}
.arrowDateBox2 {
background-color: #A9CDF1;
color: #143A66;
width: 12.5%;
height: 57px;
padding-left: 15px;
}
.arrowDateBox2Arrow {
background-image: url('../images/menuarrow-split2.svg');
background-repeat: no-repeat;
width: 30.5px;
height: 57px;
}
I've updated this so you only need li elements
css
.arrowDateBoxes {
display: flex;
padding: 0;
font-size: 14px;
font-weight: bold;
}
.arrowDateBoxes>li {
position: relative;
list-style-type: none;
height: 57px;
padding-left: 15px;
margin-right: 29px;
}
.arrowDateBoxes>li:nth-child(odd) {
background-color: #E8E8E8;
color: #143A66;
}
.arrowDateBoxes li:nth-child(even) {
background-color: #A9CDF1;
color: #143A66;
}
.arrowDateBoxes>li::before {
position: absolute;
left: calc(100% - 1px);
content: '';
width: 30.5px;
height: 57px;
background-repeat: no-repeat;
}
.arrowDateBoxes li:nth-child(odd)::before {
background-image: url('menuarrow-split1.svg');
}
.arrowDateBoxes li:nth-child(even)::before {
background-image: url('menuarrow-split2.svg');
}
and html
<ul class="arrowDateBoxes">
<li>
Application Cycle Opens
</li>
<li>
Application Deadline
</li>
<li>
Reference Letter Deadline
</li>
<li>
Selections for Program Interviews
</li>
<li>
Interviews
</li>
<li>
Offer Acceptance Deadline Date
</li>
<li>
ICRC Term Begins
</li>
</ul>
I'm not 100% satisfied with it as setting overflow-y: hidden doesn't work as it causes a horizontal scroll bar to appear but gives you the general idea.

Possible to stack images within a flex container?

I have a project that I am currently trying to refactor and am wondering if it is possible to stack images within a flex container?
Here is the HTML for reference:
<div id="dealWrapper">
<!-- HEADER START -->
<div id="flexContainer">
<div id="bigImage">
<img id="orgZ" src="https://i.imgur.com/1KWyDov.jpg" alt="Image of Food" />
<img id="gluZ" src="https://i.imgur.com/9GHwSZR.jpg" alt="Image of Food" />
<img id="sugZ" src="https://i.imgur.com/ugltt9v.jpg" alt="Image of Food" />
<img id="vegZ" src="https://i.imgur.com/zi9R9yl.jpg" alt="Image of Food" />
<img id="ketZ" src="https://i.imgur.com/SSd9KST.jpg" alt="Image of Food" />
<img id="palZ" src="https://i.imgur.com/zs92uob.jpg" alt="Image of Food" />
</div>
<ul class="flexUL">
<li class="vm_clickable" id="organic" data-src="/" data-url="/">
Organic
</li>
<li class="vm_clickable" id="glutenFree" data-src="/" data-url="/">
Gluten-Free
</li>
<li class="vm_clickable" id="sugarFree" data-src="/" data-url="/">
Sugar-Free
</li>
<li class="vm_clickable" id="vegan" data-src="/" data-url="/">
Vegan
</li>
<li class="vm_clickable" id="keto" data-src="/" data-url="/">
Keto
</li>
<li class="vm_clickable" id="paleo" data-src="/" data-url="/">
Paleo
</li>
</ul>
</div>
<!-- END FLEX CONTAINER -->
</div>
<!-- deal wrapper end -->
I would like to stack the images displayed on top of each other (varying z index of course). Is this possible? As far as I know you have to use position:absolute to do this. Seems guaranteed to interfere with flex styles of the previous design. Do I need to get rid of flex and set up the CSS positioning in another way?
Code Pen for reference: https://codepen.io/gchis66/pen/qBZNgBw
edit: sorry if i wasnt clear about the ultimate goal. Ultimately, I want to stack the images on top of eachother then set a css hover rule on each of the links to the right of the images to show the corresponding image by updating the z index to the highest number.
Get rid of the display: flex; in #bigImage a - only the container needs that.
Add position: absolute to #bigImage a.
Then, add ids to the links. So for example then you could do:
#veganlink:hover + #veganimage {
z-index: 1000;
}
This may help you: On a CSS hover event, can I change another div's styling?
Try the following
#flexContainer a{
display: block;
}
#flexContainer a img{
width: 100%;
height: auto;
max-width: 100%;
object-fit: cover;
}
you could use position:absolute + target :
body {
max-width: 1280px;
}
#flexContainer {
display: flex;
width: 100%;
height: auto;
flex-wrap: nowrap;
margin: .5vw auto 1vw;
}
#bigImage a {
display: flex;
justify-content: center;
flex-direction: column;
flex-wrap: nowrap;
align-items: center;
}
#bigImage {
position: relative;
}
#bigImage>a+a {
top: 0;
left: 0;
width: 100%;
position: absolute;
}
#bigImage img:target {
position: relative;
z-index: 1
}
#orgZ {}
#gluZ {}
#sugZ {}
#vegZ {}
#ketZ {}
#palZ {}
#bigImage {
width: 75%;
}
.flexUL {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
width: 25%;
}
.flexUL>li {
height: 100%;
width: 100%;
max-width: 320px;
max-height: 100px;
}
.flexUL>li>a {
color: white;
font-size: 2vw;
margin: auto;
}
.flexUL>li:hover>a:after {
content: "\203A";
font: 300 36px/18px "Roboto Slab";
margin-left: 0.2em;
height: 24px;
vertical-align: middle;
display: inline-block;
color: white;
}
#organic {
background-color: #ccb3d1;
}
#organic:hover {
background-color: #b7a1bc;
}
#glutenFree {
background-color: #e7b020;
}
#glutenFree:hover {
background-color: #cf9d1c;
}
#sugarFree {
background-color: #f07f53;
}
#sugarFree:hover {
background-color: #d8724a;
}
#vegan {
background-color: #889a2c;
}
#vegan:hover {
background-color: #7a8a27;
}
#keto {
background-color: #f49382;
}
#keto:hover {
background-color: #db8475;
}
#paleo {
background-color: #9e5860;
}
#paleo:hover {
background-color: #8e4f56;
}
<div id="dealWrapper">
<!-- HEADER START -->
<div id="flexContainer">
<div id="bigImage">
<img id="orgZ" src="https://i.imgur.com/1KWyDov.jpg" alt="Image of Food" />
<img id="gluZ" src="https://i.imgur.com/9GHwSZR.jpg" alt="Image of Food" />
<img id="sugZ" src="https://i.imgur.com/ugltt9v.jpg" alt="Image of Food" />
<img id="vegZ" src="https://i.imgur.com/zi9R9yl.jpg" alt="Image of Food" />
<img id="ketZ" src="https://i.imgur.com/SSd9KST.jpg" alt="Image of Food" />
<img id="palZ" src="https://i.imgur.com/zs92uob.jpg" alt="Image of Food" />
</div>
<ul class="flexUL">
<li class="vm_clickable" id="organic" data-src="/" data-url="/">
Organic
</li>
<li class="vm_clickable" id="glutenFree" data-src="/" data-url="/">
Gluten-Free
</li>
<li class="vm_clickable" id="sugarFree" data-src="/" data-url="/">
Sugar-Free
</li>
<li class="vm_clickable" id="vegan" data-src="/" data-url="/">
Vegan
</li>
<li class="vm_clickable" id="keto" data-src="/" data-url="/">
Keto
</li>
<li class="vm_clickable" id="paleo" data-src="/" data-url="/">
Paleo
</li>
</ul>
</div>
<!-- END FLEX CONTAINER -->
</div>
<!-- deal wrapper end -->
Pen Demo

Overlaying a Image with CSS

I have a store with a gallery. I was looking to overlay the Thumbnail if a Sold stamp that I made.
If i disable the image the overlay is showing bellow, so I know it is inserting the image, it isn't on top though.
What I see:
How I know the overlay is below (thumbnail disabled):
HTML:
<li class="post-66 product type-product status-publish has-post-thumbnail sold-individually shipping-taxable purchasable product-type-simple outofstock">
<center>
<a href="http://url.com">
<img width="150" height="150" src="thumbnail.jpg" class="attachment-shop_catalog wp-post-image" alt="coelho1" />
<h3>Coelho de Peluxe</h3>
</a>
</center>
</li>
CSS:
.outofstock {
background: url("soldoverlay.png") top left no-repeat;
position: relative;
z-index: 200;
}
.attachment-shop_catalog{
z-index: 1;
}
Can anyone please help me?
Kind Regards
The best way to make an overlay is use a pseudo-element using the class you already have outofstock. Check this snippet as an example:
li {
position: relative;
display: inline-block;
white-space: nowrap;
text-align:center;
margin:10px;
}
.outofstock:after {
content: " ";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, .6);
z-index: 10;
}
<ul>
<li>
<a href="http://url.com">
<img width="150" height="150" src="http://placehold.it/150" alt="coelho1" />
<h3>WITHOUT OVERLAY</h3>
</a>
</li>
<li class="outofstock">
<a href="http://url.com">
<img width="150" height="150" src="http://placehold.it/150" alt="coelho1" />
<h3>OVERLAY</h3>
</a>
</li>
</ul>
Edit
To keep the link to of the href you can create the pseudo-element inside the a tag like this:
li {
display: inline-block;
white-space: nowrap;
text-align: center;
margin: 10px;
}
a {
position: relative;
display:block;
}
.outofstock a:after {
content: " ";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, .6);
z-index: 10;
}
<ul>
<li>
<a href="http://url.com">
<img width="150" height="150" src="http://placehold.it/150" alt="coelho1" />
<h3>WITHOUT OVERLAY</h3>
</a>
</li>
<li class="outofstock">
<a href="http://url.com">
<img width="150" height="150" src="http://placehold.it/150" alt="coelho1" />
<h3>OVERLAY</h3>
</a>
</li>
</ul>
you could avoid to use an image and play with CSS 2D transformations (supported even on IE9)
e.g. http://codepen.io/anon/pen/NPydBP
Markup
<ul>
<li data-in-stock="vendido">
<a href="">
<img src="http://dummyimage.com/400x280/cccccc/fff.jpg" />
</a>
</li>
</ul>
CSS
li {
position: relative;
overflow: hidden;
}
[data-in-stock]:after {
position: absolute;
top: 0;
left: 0;
z-index: 1;
content: attr(data-in-stock);
display: block;
min-width: 160px;
color: #fff;
background: #222;
padding: 6px 10px;
text-transform: uppercase;
font: 1em Arial;
-webkit-transform: rotate(-42deg) translateX(-50px);
-moz-transform: rotate(-42deg) translateX(-50px);
transform: rotate(-42deg) translateX(-50px);
}
The text overlapped comes from the data-in-stock attribute in the markup, so you can easily change the text or optionally serve a different page language
This approach could also work if you need to show an image instead of a text (the content property also accepts an url to an image): see http://codepen.io/anon/pen/dPdNBQ
Final Result
1) Create a DIV to place your image in, set left and top css, and set z-index to 5, set width and height to be same as image
2) Create another DIV with same left, top, width, and height, but set z-index higher. Place img tag with outofstock in it

Wrap image with text in special style

I have the following code which creates a list containing images.
HTML:
<ul>
<li class="list">
<div class="list_div">
<img class="list_image" align="top" src=""/>
<h3><a>Headline 1</a></h3>
<p>text,text,text,text,text,text</p>
</div>
</li>
<li>
<div class="list_div">
<img class="list_image" align="top" src=""/>
<h3><a>Headline 2</a></h3>
<p>text,text,text,text,text,text.</p>
</div>
</li>
</ul>
CSS:
li {
padding: 2px;
color: #000000;
font-size: 12px;
text-align: left;
vertical-align: middle;
word-wrap: break-word;
border-bottom: 1px solid #AFAFAF;
background-color: #CCD5DF;
}
.list_div {
width: 100%;
display: block;
}
.list_image {
float: left;
width: 30%;
height: auto;
border: 2px solid #000;
left: 0;
top: 0;
}
I want to:
place image in left and headline, text in right side. ==> in first List
place image in center and show headline, text within Image in center ==> in second List
BUT, this style need to follow:
image width 30% in 1st List and 50% in second List.
ul, li in static position.
page is responsive.
here is my code sample, link: http://jsfiddle.net/2ycggga9/
is this what u want to do
http://jsfiddle.net/2ycggga9/5/
.list2 > h3,.list2>p{
position:relative;
left:-23%;
}
<li class="list2">
<img class="list_image" src="http://thekitemap.com/images/feedback-img.jpg"/>
<h3><a>Headline 2</a></h3>
<p>text,text,text,text,text,text.</p>
</li>

Links do not centre as required

I'm having trouble aligning "buttons" in my pages, which are actually just text links that are made to look like buttons using CSS. It is used within an unordered list (see HTML below).
The responsible CSS code is here:
ul.cms {
width: 85%;
margin: 0px auto !important;
text-align: center;
}
ul.cms li {
width: 24.99%;
float: left;
background: none !important;
padding: 0px !important;
margin: 0px ;
text-align: center;
color: #666
}
ul.cms .has-icon {
margin: auto;
display: block;
background-position: center top;
background-repeat: no-repeat;
padding-top: 140px;
margin: 0px 8px;
}
a.ja-typo-btn {
display: inline-block;
text-decoration: none;
white-space: nowrap;
border: none;
color: #333;
background: none;
text-align: center;
}
a.ja-typo-btn:hover,
a.ja-typo-btn:active,
a.ja-typo-btn:focus {
border: none;
background-position: bottom;
color: #333;
}
a.ja-typo-btn-big {
text-align: center;
border: none;
font-size: 110%;
line-height: normal;
font-weight: normal;
}
a.ja-typo-btn-big span {
padding: 15px 23px;
border: none;
display: inline-block;
text-align: center;
}
a.btn-green { background-color: #74af57 !important; border: none; }
a.btn-green:hover,
a.btn-green:active,
a.btn-green:focus { border-color: #74af57; color: #fff; }
a.btn-green span { border: none; }
With the following HTML Code (I've cut out unnecessary text information as seen in the image below) :
<ul class="cms clearfix">
<li>
<a class = "has-icon icon1"
href = "barista-course-melbourne/espresso-basics"
target = "_parent"></a>
<a class = "ja-typo-btn btn-green ja-typo-btn-big btn-big-green"
href="barista-course-melbourne/espresso-basics"
target="_parent"
style="text-align: center; display: inline-block;">
<span>COURSE INFO</span>
</a>
</li>
</ul>
And renders in a mobile device like this where the button is not centred.
Here's a screenshot:
Any insight and help will be much appreciated.
This is the full HTML code I've used:
<div style="display: block;">
<p> </p>
<ul class="cms clearfix">
<li>
<a class="has-icon icon1" href="barista-course-melbourne/espresso-basics" target="_parent">
</a>
<h4>LEVEL 1</h4>
<h4>Espresso Basics</h4>
<br />
<h4>3 hours - $99</h4>
<span>An introductory barista course where you will learn fundamental barista skills.</span>
<a class="ja-typo-btn btn-green ja-typo-btn-big btn-big-green" href="barista-course-melbourne/espresso-basics" target="_parent">
<span>    COURSE INFO    </span>
</a>
</li>
<li>
<a class="has-icon icon2" href="barista-course-melbourne/latte-art" target="_parent">
</a>
<h4>LEVEL 2</h4>
<h4>Latte Art</h4>
<br />
<h4>2 hours - $150</h4>
<span>Learn to pour like a pro. You will learn to pour rosettas, hearts and tulips. </span>
<a class="ja-typo-btn btn-green ja-typo-btn-big btn-big-green" href="barista-course-melbourne/latte-art" target="_parent" style="text-align: center;">
<span>    COURSE INFO    </span>
</a>
</li>
<li>
<a class="has-icon icon3" href="barista-course-melbourne/advanced-barista-training" target="_parent">
</a>
<h4>LEVEL 3</h4>
<h4>Advanced Barista</h4>
<br />
<h4>3 hours - $250</h4>
<span>Do you have what it takes to become a top barista? Take your career to the next level! <br />
</span>
<a class="ja-typo-btn btn-green ja-typo-btn-big btn-big-green" href="barista-course-melbourne/advanced-barista-training" target="_parent" style="text-align: center;">
<span>    COURSE INFO    </span>
</a>
</li>
<li>
<a class="has-icon icon4" href="barista-course-melbourne/home-barista-training" target="_parent"></a>
<h4>HOME</h4>
<h4>Barista Classes</h4>
<br />
<h4>Various Classes</h4>
<span>Take a range of our home barista classes in the comfort of your own home.<br /></span>
<a class="ja-typo-btn btn-blue ja-typo-btn-big btn-big-blue" href="barista-course-melbourne/home-barista-training" target="_parent" style="text-align: center;">
<span>   LEARN MORE   </span>
</a>
</li>
</ul>
<div class="button-avartar clearfix">
<p> </p>
<p style="text-align: center;"> {modal href="barista-course-melbourne/index.php?tmpl=component&id=2333" class="ja-typo-btn btn-red ja-typo-btn-big btn-big-red"}
<span>Upcoming Barista Course Dates</span>
{/modal}
</p>
<p> </p>
</div>
On the li, with the button, set text-align:center and float:none.
Take out from ul.cms li the width: 24.99%; and float: left;
Set the width of li to 100%. I did it inline, but you can do it in the external css itself.
<ul class="cms clearfix">
<li style="width: 100%">
<a class = "has-icon icon1"
href = "barista-course-melbourne/espresso-basics"
target = "_parent"></a>
<a class = "ja-typo-btn btn-green ja-typo-btn-big btn-big-green"
href="barista-course-melbourne/espresso-basics"
target="_parent"
style="text-align: center; display: inline-block;">
<span>COURSE INFO</span>
</a>
</li>
</ul>
fiddle: http://jsfiddle.net/nuxbox/LhDKb/
Not sure where the problem comes from, text-align:center on the li should center all inline-block elements inside. Could you show the full HTML structure? Maybe there is something between has-icon and ja-typo-btn?
On the li add position:relative and on the button use position:absolute; top:0; left:50%; that should help you out.
In your CSS you are trying to apply margin twice:
ul.cms .has-icon {
margin: auto; /* once here */
display: block;
background-position: center top;
background-repeat: no-repeat;
padding-top: 140px;
margin: 0px 8px; /* again here */
}
Try this:
ul.cms .has-icon {
margin: 0 auto; /* center button, change 0 to 5-10 if you want some margin top and bottom */
display: block;
background-position: center top;
background-repeat: no-repeat;
padding-top: 140px;
}