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
Related
I am trying to make a navbar which kind of looks like this site: https://med.stanford.edu/ultrasound.html.
So far I have done my own styling but one thing I am stuck at is that, when I shorten the width of the browser, the title overlaps my logo. I do not want that. I want to keep the navbar title beside the logo always like the site I provided. How to achieve that?
My navbar component
import React from "react";
import NavbarItems from "./NavbarItems";
import "./navbar.css";
import logo from "../../logo/logo.png";
import { Image } from "#chakra-ui/image";
import { Text } from "#chakra-ui/react";
function Navbar(props) {
return (
<>
<nav className='NavbarItems'>
<div className='navbar-logo'>
<a href='#'>
<Image src={logo} alt='logo' />
</a>
</div>
<div className='navbar-title'>
<Text>Some text beside the logo</Text>
</div>
<div
className='menu-icon'
onClick={() => props.setIsMenuOpen(!props.isMenuOpen)}
>
<i className={props.isMenuOpen ? "fas fa-times" : "fas fa-bars"}></i>
</div>
<ul className={props.isMenuOpen ? "nav-menu active" : "nav-menu"}>
{NavbarItems.map((item, index) => {
return (
<li key={index}>
<a className={item.cname} href={item.url}>
{item.title}
</a>
</li>
);
})}
</ul>
</nav>
</>
);
}
export default Navbar;
my navbar CSS file
.NavbarItems {
height: 80px;
display: flex;
justify-content: center;
align-items: center;
font-size: 1rem;
font-weight: 600;
position: -webkit-sticky;
position: fixed;
top: 0;
width: 100%;
z-index: 1;
background: white;
}
.navbar-logo {
position: relative;
justify-self: start;
margin-left: 8px;
margin-right: 8px;
cursor: pointer;
width: 250px;
}
.navbar-title {
position: relative;
justify-self: start;
}
.nav-menu {
display: grid;
grid-template-columns: repeat(5, auto);
grid-gap: 10px;
list-style: none;
text-align: center;
width: 70vw;
justify-content: end;
margin-right: 2rem;
}
There is no need position: relative to this style my opinion.
.navbar-title {
//position: relative;
justify-self: start;
}
It should work for you on your case. Just comment this line and check.
<ul class="nav nav-pills">
...
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
Dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu">
...
</ul>
</li>
...
</ul>
use bootstrap navbar.
clarify your question. your image files such us logos do not found
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> %
I'm doing something wrong with the css code and it doesn't look the way I wanted. I attached a link to the post to see how it is supposed to look like and a picture to see how it looks like now. I'm posting the HTML code as well as CSS code. I tried to find what I'm doing wrong but after spending 2 hours, trying to find what is wrong, I finally gave up and I started to look for help.
How it should look like
Current design
HTML
<header>
<img src="pc_logo.png" alt="Pandaisia Chocolates" />
<nav class="horizontal">
<ul>
<li>Home</li>
<li>The Store</li>
<li>My Account</li>
<li>Specials</li>
<li>Reviews</li>
<li>Contact Us</li>
</ul>
</nav>
</header>
<div class="newRow">
<div class="col-2-3">
<article id="intro">
<h1>March Specials</h1>
<p>Spring is coming and we've got some mouth-watering specials to help you celebrate the change in seasons in style! Featured throughout March is our always-popular Chocolate Covered Strawberries / Rose Fruit Syrup Combo, now at the special low price
of $29.95. For that special someone, consider our Red Rose Select box of Spring chocolates. Remember that for every order of $25 or more, you receive a free truffle of your choice. For orders of $100 or more we throw in a four-piece gift box of
our signature chocolates and truffles.</p>
</article>
<div class="newRow">
<div class="col-1-3 specials">
<img src="pc_photo7.png" alt="" />
<h1>Red Rose Select</h1>
<p>A classic collection of 18 signature chocolates served with a romantic red rose for the special person in your life. One of our most popular box sets.</p>
<p>$24.95</p>
<p>Order Now</p>
</div>
<div class="col-1-3 specials">
<img src="pc_photo8.png" alt="" />
<h1>Your Choice</h1>
<p>Build your own collection of signature truffles and chocolates. Now you can choose old favorites from our 24-year history of award-winning chocolates and sweets.</p>
<p>$32.55</p>
<p>Order Now</p>
</div>
<div class="col-1-3 specials">
<img src="pc_photo9.png" alt="" />
<h1>Praline Signatures</h1>
<p>Delicious chocolate with delicious pralines presented in a beautiful and elegant box. Enjoy this fantastic collection inspired by the best Parisian chocolate shops.</p>
<p>$39.23</p>
<p>Order Now</p>
</div>
</div>
</div>
<div class="col-1-3" id="awardList">
<h1>Awards</h1>
<div class="awards" id="award1">
<img src="pc_award1.png" alt="" />
<p>Best of Show</p>
<p>Confectioners Association</p>
</div>
<div class="awards" id="award2">
<img src="pc_award2.png" alt="" />
<p>Five Stars</p>
<p>Confectioner Quarterly</p>
</div>
<div class="awards" id="award3">
<img src="pc_award3.png" alt="" />
<p>Best Chocolate</p>
<p>Food World</p>
</div>
<div class="awards" id="award4">
<img src="pc_award4.png" alt="" />
<p>Best Chocolate</p>
<p>Choco-Fest</p>
</div>
<div class="awards" id="award5">
<img src="pc_award4.png" alt="" />
<p>Best Dessert</p>
<p>Choco-Fest</p>
</div>
</div>
</div>
<footer>
Pandaisia Chocolates © 2017 All Rights Reserved
</footer>
CSS
body {
margin-left: auto;
margin-right: auto;
max-width: 960px;
min-width: 640px;
width: 95%;
}
/* Image Styles */
body img {
display: block;
width: 100%;
}
/* Horizontal Navigation Styles */
body>header>nav.horizontal li {
width: 16.66%;
}
nav.horizontal li {
display: block;
float: left;
}
nav a {
display: block;
}
/* Row Styles */
div.newRow {
clear: both;
width: 100%;
}
div.newRow:after {
clear: left;
content: "";
display: table;
}
/* Column Styles */
div[class^="col-"] {
float: left;
padding: 2%;
}
div.col-1-1 {
width: 100%;
}
div.col-1-2 {
width: 50%;
}
div.col-1-3 {
width: 33.33%;
}
div.col-2-3 {
width: 67.67%;
}
div.col-1-4 {
width: 25%;
}
div.col-3-4 {
width: 75%;
}
div[class^="col-"]:after {
clear: left;
content: "";
display: table;
}
/* Specials Styles */
div {
min-height: 400px;
outline: 1px dashed rgb(71, 52, 29);
}
/* Award Styles */
div#awardList {
position: relative;
height: 650px;
overflow: auto;
}
div.awards>div#award1 {
top: 80px;
left: 5%;
}
div.awards>div#award2 {
top: 280px;
left: 60%;
}
div.awards>div#award3 {
top: 400px;
left: 20%;
}
div.awards>div#award4 {
top: 630px;
left: 45%;
}
div.awards>div#award5 {
top: 750px;
left: 5%;
}
/* Footer Styles */
body>footer {
clear: both;
}
You have used wrong width value for the .col-2-3 i.e width: 67.67%...
....as col-1-3 has width: 33.33% and col-2-3 has width: 67.67%..it means the whole width will be 33.33%+67.67%=101%...which should be is 100%...
It should be width: 66.67%...Also apply box-sizing:border-box
div.col-2-3 {
width: 66.67%;
}
Fiddle Link
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
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;
}