3 divs, middle div needs to be a variable length dotted line - css

I would like to create a restaurant style menu card.
I do not want to use tables. I'm trying to accomplish this using DIVs only.
This is what I have:
.review-row { // (1)
padding: 0;
}
.review-cat { // (2)
font-size: 25px;
float: left;
}
.review-dots { // (3)
padding-bottom: 5px;
float: left;
}
.review-dots-inner { // (3)
height: 5px;
border-bottom: 3px dotted #E65540;
}
.review-rating { // (4)
float: right;
font-size: 50px;
}
In the image think of (3) as being 2 DIVS, the inner div is there to get the dots on the same baseline as the text.
Now this doesn't work. How to proceed?
All DIVs should adjust width according to content
Middle DIV needs to act as a 'filler'

You don't need images..
See working example here..
do the following..
<!--Markup and styles-->
<div class="item-container">
<span class="item">Quality</span>
<span class="fill"></span>
<span class="score">8.0</span>
</div>
<div class="item-container">
<span class="item">Presentation</span>
<span class="fill"></span>
<span class="score">9.5</span>
</div>
<style>
.item-container{
width:200px;
/*border:1px solid #AAA;*/
display:block;
padding:5px;
margin:2px;
}
.item{
float:left;
margin:2px;
}
.score{
float:right;
margin:2px;
}
.fill{
border:none;
border-bottom:1px dotted #000;
display:inline-block;
}
</style>
And do this in your $().ready()
$('.item-container').each(function(){
//alert($('.fill', $(this)).width());
var item = $('.item', $(this));
var score = $('.score', $(this));
var itemWidth = item.width();
var scoreWidth = score.width();
var offset1 = item.offset().left;
var offset2 = score.offset().left;
var fillerWidth = (offset2 - offset1) - (itemWidth + scoreWidth);
$('.fill', $(this)).css('width', fillerWidth + 10);
});

Easy with Flexbox :) . See working example here..
<div class="row">
<div class="text-box">Breakfast</div>
<div class="dots-box"></div>
<div class="text-box">8:30 am - 9:30 am</div>
</div>
CSS
.row{
display: flex;
overflow:hidden;
padding:15px;
width:90%;
}
.text-box{
flex: 0 0 auto;
}
.dots-box{
flex: 1 1 auto;
position: relative;
}
.dots-box:before{
position:absolute;
bottom: 5px;
width: 94%;
border-bottom: 1px dotted #000;
content: '';
left: 3%;
}

You could set the dots as a repeating background, then add a white (or whatever) background for .review-cat and .review-rating.
This way you can then continue as you are going, float the rating to the right, make sure it is first in the html before (2) which is floated to the left.
background-color: white; is what you'll need to do
and for the .review-row you'll want to add the dots in as a repeating background
background: transparent url(../images/dots.png) repeat 0 0;
Good luck

Related

Custom underline effect, other than creating a background image for it

is there a better way to create this style of "underline" through CSS, other than creating a background image for it?
To be clear, I'm only interested in the "duplicated line" effect, a thicker and shorter line sitting directly atop a thinner and longer line of a different color. Thanks!
You can use pseudo elements here, i.e. :before and :after. Here, what am doing is, using an h1 element which am displaying it as inline-block. Later, we need to use CSS positioning to set both the bottom borders in place, as the borders are smaller than your element.
Later, again by using CSS positioning, we position the small border on top of the bigger one. Note that am using left: 50%; and transform: translateX(-50%) to position the border in horizontally center.
Make sure you don't miss out the z-index as it is important to use here, else the other border will render on top of the smaller one.
#import url('https://fonts.googleapis.com/css?family=Varela+Round');
* {
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
h1 {
position: relative;
display: inline-block;
font-family: Varela Round;
font-size: 24px;
text-transform: uppercase;
font-weight: bold;
color: #401f1c;
margin: 40px; /* not required, only for demo purpose */
}
h1 span {
color: #efcc4c;
}
h1:before,
h1:after {
content: '';
position: absolute;
left: 50%;
transform: translateX(-50%);
}
h1:before {
bottom: -11px;
width: 40px;
border-bottom: 3px solid #efcc4c;
z-index: 1;
}
h1:after {
width: 80%;
border-bottom: 1px solid #ddd;
bottom: -10px;
}
<h1>Our <span>Services</span></h1>
Edit: Refactored my code and making the demo more precisee.
Try this
HTML
<div class="text">
<span>our</span>
Services
</div>
CSS
.text{
font-weight:600;
font-size:25px;
color:red;
position: relative;
display:inline-block;
}
.text::after,
.text::before{
content:"";
position: absolute;
left: 0;
right: 0;
bottom: -5px;
margin:auto;
border-radius:5px;
height:0px;
}
.text::before{
width:100%;
border:1px solid #ccc;
}
.text::after{
width:50%;
border:2px solid red;
bottom:-6px;
}
.text span{
color:#000000;
}
Link for reference
hope this helps..
I always create "divider", like:
<div class='divider'>
<div class='divi-1'></div>
<div class='divi-2'></div>
<div class='divi-3'></div>
</div>
CSS:
.divider{
padding-top:15px; //or other
text-align:center;
display:block; // or column in bootstrap like col-md-12
}
.divider .divi-1{
display:inline-block;
height:2px; //or other
width:50px; // or other
background:#e5e5e5;
.
.divider .divi-2{
display:inline-block;
height:2px;
width:50px;
background:#000000;
}
.divider .divi-1{
display:inline-block;
height:2px; //or other
width:50px; // or other
background:#e5e5e5;
}
And that's it. You can also use vertical-align for inline-block so You have some more options to move lines verticaly ... and also it's in the flow so You know what size it have and can be sure that other elements won't overlap it.

Sliding transition for list items when one is removed

It has been a while since I last used CSS. I'm having trouble with this one. I have a list of items. When I click on the cross it removes the item from the DOM. However what I'm looking for is to make the rest of the items slide up when one has been removed.
Currently it just removes the item as desired but instantly moves the other to 'fill in the space'. I know there is a way to do it with CSS transitions, but the question is how...
var remove = function(id) {
document.querySelector('#'+id).remove();
}
div {
border: 1px solid grey;
width: 100px;
margin: auto;
margin-bottom: 10px;
text-align: center;
padding: 10px
}
span {
float: right;
cursor: pointer;
}
<div id="one">One <span onclick="remove('one')">×</span></div>
<div id="two">Two <span onclick="remove('two')">×</span></div>
<div id="three">Three <span onclick="remove('three')">×</span></div>
<div id="four">Four <span onclick="remove('four')">×</span></div>
Like this?
I added a class called closeSlide which will animate the element to slide up. And after the transition, it is removed by setting up a timer.
And for visual prettiness, I've added overflow:hidden to your target style, which can alternatively, be added via JS using elem.style.overflow = 'hidden'. But for justification, I added that to the target style because I want to avoid any possible jitters when initiating the closing animation.
var remove = function(id) {
var elem = document.querySelector('#'+id);
elem.className += 'closeSlide';
setTimeout(function(){
elem.remove();
}, 200);
}
div {
border: 1px solid grey;
width: 100px;
margin: auto;
margin-bottom: 10px;
text-align: center;
padding: 10px;
overflow:hidden;
}
span {
float: right;
cursor: pointer;
}
.closeSlide {
margin-bottom:0;
height:0px;
padding-top:0;
padding-bottom:0;
transition: 0.2s all ease-out;
/*Just reverse any spacing styling you've applied to make it **magically** disappear*/
}
<div id="one">One <span onclick="remove('one')">×</span></div>
<div id="two">Two <span onclick="remove('two')">×</span></div>
<div id="three">Three <span onclick="remove('three')">×</span></div>
<div id="four">Four <span onclick="remove('four')">×</span></div>

How to automatically add text to image on hover

I have an image that I would like to add text to. I don't know what the best method would be. I have seen the map tag in HTML but I don't know if that helps me. For each individual part of the image, I'd like to add a text next to it on hover.
My best solution so far is to make a div with the image as a background image, and have multiple spans for each part of my image, but that stopped working precisely when rescaling the image.
Here is a snippet for you.
$('.hover-with-caption').on('mousemove',function(e){
$('#dynamicCaption').remove();
$('body').append("<span id='dynamicCaption' class='dynamic-caption'></span>");
$('#dynamicCaption').text('what ever you want to show here!! '+event.pageX + ", " + event.pageY); // you need to decide what to show and how you are going to generate the caption, As you have not given mush info about it.
$('#dynamicCaption').finish().toggle(100).
css({
top: e.pageY + "px",
left: e.pageX + "px"
});
$(document).off("click.customCaption").on("click.customCaption", function (e) {
// alert('context menu other mouse events');
if (!$(e.target).parents('#dynamicCaption').length > 0) {
$('#dynamicCaption').remove();
}
});
});
div.parent{
width:200px;
height:150px;
position: relative;
border: 1px solid black;
cursor:pointer;
}
img{
width:200px;
height:150px;
}
.dynamic-caption {
display: none;
z-index: 1000;
position: absolute;
overflow: hidden;
border: 1px solid #CCC;
white-space: nowrap;
font-family: sans-serif;
background: #FFF;
color: #333;
border-radius: 0px;
list-style-type: none;
padding-left: 0px;
min-width: 100px;
margin-bottom:0px;
cursor:pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
<img class="hover-with-caption" src="http://cdn.codeproject.com/App_Themes/CodeProject/Img/logo250x135.gif" />
</div>
Hope this helps you out.

Pure CSS tabs switch

How can I make this tabs script: FIDDLE work like this: DEMO
I want to switch social tabs between each other but it doesn't work.
Where did I made a mistake?
a[name="tab1"] + .facebook_box {
display: block
}
:target + .twitter_box {
display: block
}
:target ~ a[name="tab1"] + .facebook_box {
display: none
}
** UPDATE: This is a duplicate of this question **
Here are the changes to make it work:
First a small bug: close the anchor tag like this: </a> not like this <a/>.
Then change the order of your articles:
<div class="tab-content">
<a name="tab2"></a>
<article class="twitter_box">t</article>
<a name="tab1"></a>
<article class="facebook_box">f</article>
</div>
Then delete the ".social_slider .tab-content" before the ".facebook_box" or add it also to the lines doing the magic otherwise you overwrite the magic with the more precice definition of your class.
And then you need to increase the size of your link inside the tab, otherwise you only click on the label, not the anchor.
.facebook_box {
border-radius: 8px;
background-color: #fff;
position: relative;
z-index: 99998;
display:none;
height:300px;
border:10px solid #3a93d6;
}
.twitter_box {
border-radius: 8px;
background-color: #19bfe5;
position: relative;
z-index: 99998;
display:none;
height:300px;
border: 10px solid #68c2ff;
}
.twitter_icon > a, .facebook_icon > a{
display: block;
height: 100%;
width: 100%;
}

Mouse over text adds border to several images, but when mouse over images there should be no effect

I have some text on a page, when someone mouses over it, it will highlight (using outline) several selected images on the same page. I want this to be one way, so mousing over the text highlights the images, but I want mousing over the images to have no effect, right now it also highlights everything. Is this possible? Note: each image has an id and a class (jquery draggable) already attached to it.
HTML:
<div class="container">
<div class="containerLeft">alignments</div>
<div><img src="http://www.cool-smileys.com/images/out11.jpg" id="position7" class="ui-widget-content" /></div>
<div><img src="http://www.cool-smileys.com/images/out12.jpg" id="position8" class="ui-widget-content" /></div>
<div><img src="http://www.cool-smileys.com/images/out13.jpg" id="position9" class="ui-widget-content" /></div>
<div> <img src="http://www.cool-smileys.com/images/out14.jpg" id="position12" class="ui-widget-content" /> </div>
</div>
CSS:
/* Normal Styles */
.containerLeft {
color:#333;
width:100px;
}
.containerLeft:hover {
width:100px;
}
/* Hover Styles */
.container:hover .containerLeft {
background-color: none;
}
.container:hover #position12 {
outline:2px solid #CFF;
}
.container:hover #position7 {
outline:2px solid #CFF;
}
.container:hover #position8 {
outline:2px solid #CFF;
}
.container:hover #position9 {
outline:2px solid #CFF;
}
#position7{
position:absolute;
margin: 0;
padding: 0;
border:none;
left: 13em;
top:9em;
z-index:17;
}
#position8{
position:absolute;
margin: 0;
padding: 0;
border:none;
left: 4em;
top:15em;
z-index:2;
}
#position9{
position:absolute;
margin: 0;
padding: 0;
border:none;
left: 7em;
top:5em;
z-index:20;
}
#position12{
position:absolute;
margin: 0;
padding: 0;
border:none;
left: 24em;
top:10em;
z-index:-14;
}
Right now everything is in css, but maybe there is a javascript solution?
The jsfiddle: http://jsfiddle.net/tMzMN/8/
If you want to use JS/Jquery you could achieve what you want this way:
$(".containerLeft").hover(function() {
$(".ui-widget-content").addClass("hover_class");
}, function() {
$(".ui-widget-content").removeClass("hover_class")
});
Then just replace all 4 of your CSS selectors that look like this:
.container:hover #position9 {
outline:2px solid #CFF;
}
...
with this:
.hover_class {
outline:2px solid #CFF;
}
Here is a fiddle of it in action: http://jsfiddle.net/tMzMN/9/
Also, and don't quote me on this, using the Jquery method above will probably have a greater level of backwards compatibility with older browsers as opposed to any CSS tricks you find. I could be wrong and there may very well be something that plays nice with IE<9 but I'm not sure...

Resources