I have set of icons that are for hotel amenities and I am trying to use CSS sprite to show them on my page.
This is what I have for html
<div class="sprite">
<ul id="amenities">
<li class="bathtub"></li>
<li class="shower"></li>
<li class="next"></li>
<li class="tv"></li>
<li class="safe"></li>
</ul>
</div>
my css
.amenities { position: relative; }
.amenities li { margin: 0; padding: 0; list-style: none; position: absolute; top: 0; }
.bathtub { background: url('graphics/icons.png') no-repeat 0 0; width: 60px; height: 60px;}
.shower { background: url('graphics/icons.png') no-repeat -61 0; width: 60px; height: 60px;}
only the first icon shows and the second one doesnt.
jsfiddle
how I need it to look
You haven't set any units on the background position. Setting this to any type of unit will make it work. Zero is a value that is an exception to this rule.
shower { background: url('graphics/icons.png') no-repeat -61px 0; width: 60px; height: 60px;}
See: https://jsfiddle.net/kbrbc62h/
EDIT:
In response to your recent comment, see: https://jsfiddle.net/Ls8wLsa6/
Elements like li, ul, h*, and div have a display:block by default. This means these elements will take up an entire line. We can set a specified width, but even still the container will be placed on a new line. By changing the li elements to use inline-block, we are able to cram them on to one line. Since the ul has a fixed width, every 3rd element will appear on a new line.
We use vertical-align:top; to align the li content to the top of the container, and then adjust the p tag to display the text in the center with no margin.
HTML:
<div class="sprite">
<ul id="amenities">
<li><div class="bathtub"></div><p>Bath</p></li>
<li><div class="shower"></div><p>Shower</p></li>
<li><div class="kitchen"></div><p>Kitchen</p></li>
<li><div class="bathtub"></div><p>Bath</p></li>
<li><div class="shower"></div><p>Shower</p></li>
<li><div class="kitchen"></div><p>Kitchen</p></li>
<li><div class="bathtub"></div><p>Bath</p></li>
<li><div class="shower"></div><p>Shower</p></li>
<li><div class="kitchen"></div><p>Kitchen Long</p></li>
</ul>
</div>
CSS:
#amenities {
width:320px;
}
.bathtub {
background: url('http://i.stack.imgur.com/NdUbQ.png') no-repeat 0 0; width: 60px; height: 60px;
}
.shower {
background: url('http://i.stack.imgur.com/NdUbQ.png') no-repeat -61px 0; width: 60px; height: 60px;
}
.kitchen {
background: url('http://i.stack.imgur.com/NdUbQ.png') no-repeat -122px 0; width: 60px; height: 60px;
}
.sprite ul li {
list-style-type:none;
display:inline-block;
vertical-align:top;
margin:10px;
width: 60px;
}
.sprite ul li p {
text-align:center;
margin:0;
}
Related
I'm having an issue with a fixed menu on iOS 10 Safari where the button sometimes becomes unclickable after scrolling. From debugging, the best I can tell is that the menu button's position isn't always updated properly after the scroll.
position bug screenshot
Sometimes it takes several clicks for the button to become responsive, and occasionally it forces the screen to scroll or zoom before the menu will open.
The issue only seems to be occurring on iPhone 7 using Safari, from what I've seen, but it may be present somewhere else I haven't found yet.
I've created a simplified version of the page with the issue here: http://meghandove.com/test.html
jQuery(document).ready(function() {
jQuery('a.menu-trigger').click(function(e) {
e.stopPropagation();
e.preventDefault();
if (jQuery('.menu').hasClass('menu-open')) {
jQuery('.menu').removeClass('menu-open');
jQuery('.menu').addClass('menu-close');
} else {
jQuery('.menu').removeClass('menu-close');
jQuery('.menu').addClass('menu-open');
}
});
});
body {
padding-top: 60px;
}
header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 60px;
background: #FFFFFF;
transform: translate3d(0, 0, 0);
}
header .menu-trigger {
padding: 20px;
display: block;
text-align: center;
}
.menu ul {
height: 100%;
background: #FFFFFF;
margin: 0;
padding: 30px 0 0;
list-style: none;
position: fixed;
top: 50px;
right: 0;
}
.menu ul li,
.menu ul li a {
display: block;
}
.menu ul li {
display: none;
opacity: 0;
}
.menu.menu-open ul li {
display: list-item;
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<header class="navbar">
<span>Menu</span>
<nav class="menu">
<div class="menu-ul">
<ul>
<li class="menu-item">About</li>
<li class="menu-item">Something</li>
<li class="menu-item">Something Else</li>
</ul>
</div>
</nav>
</header>
I'm trying to create a Bootstrap carousel with images that have text over them. To do that, I need to make the position of the images in the carousel absolute. Here is an image in the carousel before I made it absolute
I need the testimonials and this is LA text over the image. So I make it absolute and this happens
And no matter what I do, I can't seem to fix it.
Here is my Slim markup
.container#testimonialsSection
.carousel.slide#testimoniesCarousel data-ride="carousel"
ol
li data-target="#testimoniesCarousel" data-slide-to="0" class="active"
li data-target="#testimoniesCarousel" data-slide-to="1" class="active"
li data-target="#testimoniesCarousel" data-slide-to="2" class="active"
li data-target="#testimoniesCarousel" data-slide-to="3" class="active"
li data-target="#testimoniesCarousel" data-slide-to="4" class="active"
.carousel-inner role="listbox"
.item.active
= image_tag("losangelesskyline.jpg", :class => "img-responsive")
h2.center Testimonials
p This is LA
.item
= image_tag("newyorkskyline.jpg")
p This is NY
.item
= image_tag("miamiskyline.jpg")
p This is Miami
.item
= image_tag("bostonskyline.jpg")
p This is Boston
.item
= image_tag("atlantaskyline.jpg")
p This is Atlanta
a.left.carousel-control href="#testimoniesCarousel" role="button" data-slide="prev" onclick=""
span.glyphicon.glyphicon-chevron-left aria-hidden="true"
span.sr-only Previous
a.right.carousel-control href="#testimoniesCarousel" role="button" data-slide="next" onclick=""
span.glyphicon.glyphicon-chevron-right aria-hidden="true"
span.sr-only Next
And here is my SCSS
.carousel-control.left, .carousel-control.right {
background-image: none
}
#testimonialsSection {
height: 70%;
width: 100%;
}
#testimoniesCarousel {
width: 100%;
height: 100%;
h3 {
font-size: 300%;
}
p {
text-align: center;
margin-left: 5%;
margin-right: 5%;
font-size: 200% !important;
}
img {
position: absolute;
height: 70%;
width: 100%;
}
.carousel-control.left .glyphicon {
position: absolute;
left: 0;
top: 35%;
margin-left: 0;
color: #D6D6D6;
}
.carousel-control.right .glyphicon {
position: absolute;
right: 0;
top: 35%;
margin-right: 0;
color: #D6D6D6;
}
}
Any help would be greatly appreciated.
Actually, I just remembered that it scales with the amount of content. Once I added my text to it the image expanded. It works now
I have a list view in my jQuery mobile app. I need to position the Thumbnails to the right I have used the following code in my css file but it didn't work for jQuery mobile 1.4.0 ? is .ui-li-thumb class deprecated in jQuery mobile 1.4.0 ? how can i do that ? please help me ..
<ul data-role="listview" data-inset="true" data-filter="true" data-filter- placeholder="Search "
data-split-icon="delete" style="margin-top: 40px;" >
<li class="RTLList" > <img src="img/thumb" /> element </li>
</ul>
Css
.RTLList .ui-li .ui-btn-text .ui-link-inherit .ui-li-thumb {
position:absolute;
top:0;
bottom:0;
margin:auto;
right: 0;
margin-right: 0 !important;
}
I have tried also , but it didnt work for me !!
.ui-listview .ui-li-has-thumb .ui-li-thumb {
right: 0;
margin-right: 0 !important;
text-align:right;
float:right;
}
Here is a DEMO
.ui-listview>.ui-li-static.ui-li-has-thumb {
padding-left: 1em;
padding-right: 6.25em;
}
.ui-listview .ui-li-has-thumb>img:first-child {
position: absolute;
top: 0;
right: 0;
left: auto;
}
.ui-listview>li.ui-first-child img:first-child:not(.ui-li-icon){
border-top-left-radius: 0;
}
.ui-listview>li.ui-last-child img:first-child:not(.ui-li-icon){
border-bottom-left-radius: 0;
}
The CSS puts the LI padding on the right instead of left and then absolutely positions the thumbnail to the right.
Page A has an iframe (that loads Page B). That Page B has a div#OutputDiv. My goal is to make that div in that iframe scrollable.
SOLUTION (CREDIT TO STEVE!):
Include overflow: auto for that div. However you must specify height too. Simply give any fixed value. eg height: 0.
Use a javascript function to make the div's height always same as the window's, even after window resize. height is now not fixed.
Code:
#outputDiv {
font-size: 12px;
font-family: Arial;
margin-right: 1em;
overflow: auto;
overflow-x: hidden; (optional)
-webkit-overflow-scrolling: touch; (enable smooth scrolling on mobile)
height: 0; (omit-able)
}
$(window).resize(function(){
$("#outputDiv").css("height",0).css("height",$(this).height());
});
$(window).trigger("resize");
TL;DR Full story
Page A.html - has an iframe to load Page B. When on Page A, that div#OutputDiv in that iframe must be scrollable. Works fine on PC but not scrollable on iPad/Android. Page structure:
Page B.php - Left half div#OutputDiv, right half div#map-canvas containing Google Maps.
(Sidenote: I think the #map-canvas CSS is pretty unchangeable, for example changing something may cause the Maps to extend height beyond browser height, which is not what I want.)
Page A.html
<style type="text/css">
#title-banner {
position: fixed;
top: 0;
left: 0;
width: 100%;
}
#real-time-alert {
margin-top: 155px;
margin-left: 10px;
}
.tab-content {
border-left: 1px solid #ddd;
padding: 10px;
height: 100%;
}
#map {
height: 100%;
}
.nav-tabs {
margin-bottom: 0;
}
#panel {
position: fixed;
top: 120px;
right: 10px;
bottom: 10px;
left: 350px;
}
iframe {
width: 100%;
height: 100%;
}
</style>
<body>
<div id="title-banner" class="well"><h1>Real-time incident updates</h1></div>
<div id="real-time-alert">
DEMO:<br>
<a id="demolink" style="cursor: pointer; font-weight: bold;">22/11/2013, 0.32.18AM: 3.128268, 101.650656<br></a>
</div>
<div id="panel">
<ul class="nav nav-tabs" id="myTab">
<li class="active"><a data-toggle="tab" href="#map">Map</a></li>
<li><a data-toggle="tab" href="#message">Messages</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="map"><iframe seamless name="map-report"></iframe></div>
<div class="tab-pane" id="message"></div>
</div>
</div>
</body>
Page B.php
*for div#map-canvas, I had to do the code below, or else when I hover on the page, div#OutputDiv will disappear. This may be not important.
$("*").hover(function(){
$("#map-canvas").css("position","fixed"); });
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map-canvas {
height: 100%;
width: 50%;
}
#content-pane {
float:left;
width:48%;
padding-left: 2%;
}
#outputDiv {
font-size: 12px;
font-family: Arial;
margin-right: 1em;
}
</style>
<body>
<div id="content-pane">
<div class='well well-small' id="inputs" style="margin: 1em 1em 0 0">
<b>TESTING ONLY</b> <br>
<label for="originLat">Incident Site: </label><input type="text" id="originLat" style="width:6em;" />
<input type="text" id="originLng" style="width:6em;" />
<button type="button">Calculate distances</button>
</br>eg. 3.126547,101.657825
</div>
<div id="outputDiv"></div>
</div>
<div id="map-canvas" style="position: fixed; right: 1px;"></div>
</body>
I can't see any overflow controls specified in the CSS (apologies if I missed them).
Have you tried:
div#OutputDiv { overflow: auto; height: 200px; }
The height is just for testing purposes - but you could use Javascript to get the actual height and apply it using either raw javascript or jQuery.
A good example (including how to detect orientation changes if device goes portrait to landscape or similar) can be found on:
How do I get the new dimensions of an element *after* it resizes due to a screen orientation change?
I have been working on building my first CSS site using divs and am having an issue with a button. While I am able to get the button to work on rollover, the link does not respond. Can somebody please advise. Thank you.
HTML:
<div class="wrapArrow">
<div class="arrow" style="cursor: pointer;"><span>home</span></div>
</div><!-- END wrapArrow -->
CSS:
.wrapArrow {
margin: 70px 0 0 0;
padding: 0;
width: 20px;
height: 20px;
float: right;
}
.arrow {
display: block;
width: 20px;
height: 20px;
background-image: url(../images/nav/arrows.gif);
background-repeat: no-repeat;
}
.arrow:hover {
background-position: 0 -20px; }
.arrow span {
display: none; }
Since your <span> is not displayed, your link has no content, so it gets collapsed to a width and height of 0, thus making it unclickable.
Why not just make the anchor itself have the arrow class?
<div class="wrapArrow">
<span>home</span>
</div><!-- END wrapArrow -->
.arrow a is 0 x 0 px
Makes it really hard to click. Believe me I tried.
Try:
.arrow a {
width: 100%;
height: 100%;
display: block;
}
It looks like you need to get rid of
.arrow span {
display: none;
}
Is there any reason that needs to be there? With display set to none you are hiding the clickable element that is necessary for the link to work.