Indent even rows of hexagons in CSS - html

I currently have a list of hexagons (images) that I have wrap to the next line when the browser width decreases. However, when this happens, they form even lines as seen in the first image, each starting at the same point on the x axis.
Here is the JS Fiddle (albeit, the hexes don't flow right because they aren't images). The real code for this is:
<div class="container">
<span>
<img class="hex" src="img/hex.png">
</span>
...
</div>
And the CSS is:
.container {
padding-top: 80px;
width: 50%;
margin-left: auto;
margin-right: auto;
}
.container span {
line-height: 129px;
display: inline-block;
}
.container .hex {
display: block;
margin-left: auto;
margin-right: auto;
}
What I would like to do is alternate the rows such that every other row starts at an offset of the hexagon size as seen in figure two. It should also be noted that this example also has a negative y position relative to the respective position as determined from the first image.
Is there a way to do this with just CSS? I'd like to avoid using a library if at all possible.
This is similar to the question asked here, but I need the entire structure to be able to have an undetermined number of rows, so the solution where I specify which items are in which rows isn't feasible for my application.

Solution in JS Fiddle Demo :
Demo 1 :
http://jsfiddle.net/mkginfo/bhxohocv/
HTML Code :
<div class="container">
<!-- odd line -->
<span>
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
<!-- even line -->
<span class="odd">
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
<!-- odd line -->
<span>
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
</div>
CSS Code :
.container {
padding-top: 80px;
width: 65%;
margin-left: auto;
margin-right: auto;
}
.container span {
line-height: 129px;
display: inline-block;
position: relative;
margin-bottom: 25px;
}
.container span.odd {
line-height: 129px;
display: inline-block;
position: relative;
margin-bottom: 25px;
margin-left: 52px;
margin-top: -20px;
}
.container .hex {
display: block;
margin-left: auto;
margin-right: auto;
}
.hexagon {
width: 100px;
height: 55px;
background: red;
position: relative;
}
.hexagon:before {
content: "";
position: absolute;
top: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 25px solid red;
}
.hexagon:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 25px solid red;
}
Demo 2 :
http://jsfiddle.net/mkginfo/wnsjfwt0/

Here's a solution that uses javascript to add the necessary transformations to the elements.
CSS:
.container {
padding-top: 80px;
width: 65%;
margin-left: auto;
margin-right: auto;
}
.floatBox {
margin-left: 15px;
margin-right: 15px;
}
.floatBox div {
display: inline-block;
}
.floatBox div.odd {
margin-left: 67px;
}
JS:
var floatBox = $(".floatBox");
var elements = floatBox.children();
var numElements = elements.length;
//reset all styles so they don't compound
elements.removeClass("odd");
elements.css("transform", "translateY(0)");
elements.css("-ms-transform", "translateY(0)");
elements.css("-webkit-transform", "translateY(0)");
var width = $(window).width() *.65;
var evenRowWidth = Math.floor(width / 135);
var oddRowWidth = Math.max(evenRowWidth - 1, 1);
var numberOfRows = 0;
var floatBoxWidth = evenRowWidth *138;
var delta = Math.floor((width-floatBoxWidth)/2);
floatBox.css("margin-left", delta);
floatBox.css("margin-right", delta);
var test = numElements;
var j = 2;
while (test > 0)
{
if (j % 2 == 0)
{
test -= evenRowWidth;
}
else
{
test -= oddRowWidth;
}
numberOfRows++;
j++;
}
j = 0;
var actionRow = 2;
var rowCount = 1;
var first = true;
for (var i = evenRowWidth; i < numElements; i++)
{
var translationAmt = -37*(actionRow-1);
if (actionRow % 2 == 0 && first)
{
first = true;
}
if (first)
{
$(elements.get(i)).addClass("odd");
first = false;
}
$(elements.get(i)).css("transform", "translateY(" + translationAmt + "px)");
$(elements.get(i)).css("-ms-transform", "translateY(" + translationAmt + "px)");
$(elements.get(i)).css("-webkit-transform", "translateY(" + translationAmt + "px)");
if (actionRow % 2 == 0)
{
if (rowCount == oddRowWidth)
{
actionRow++;
rowCount = 0;
}
}
else
{
if (rowCount == evenRowWidth)
{
actionRow++;
rowCount = 0;
first = true;
}
}
rowCount++;
}
HTML:
<div class="container">
<div class="floatBox">
<div>
<span>
<img src="image.png">
</span>
</div>
...
</div>
</div>

Related

put arrows left and right of an element

I have an icon in the center and two arrows on the right and left to scroll through the icons present.
I would like the arrows on the sides of the icon to be positioned horizontally in the center of the icon itself. How can I do? In this way the arrows are located at the top right and left and the icon displays it in the center but lower.
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
.increase {
float: right;
cursor: pointer;
}
.decrease {
float:left;
margin: 0px 15px 15px 0px;
cursor: pointer;
}
span {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
#contenitore {
width: 60%;
background-color: blue;
}
img {
max-width: 100%;
height: auto;
}
img:hover {
width: 310px;
height: auto;
}
.mySlides {
display:flex;
width: 300px;
height: 300px;
border-radius: 50%;
margin: auto;
top:250px;
left:0;
right:0;
bottom:0;
position: absolute;
}
<!-- Icons fontAwesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<header class="ricerca">
<div class="container">
<div class="row">
<div class="col-sm-12 align-self-center">
<span class="decrease" onclick="plusDivs(-1)" value="Decrease Value"><i class="fas fa-chevron-circle-left" style="font-size:50px;"></i></span>
<div class="w3-tooltip">
<img class="mySlides" shadow-lg p-3 mb-5 src="https://image.flaticon.com/icons/png/512/945/945170.png" ";>
</div>
<span class="increase" onclick="plusDivs(1)" value="Increase Value"><i class="fas fa-chevron-circle-right" style="font-size:50px;"></i></span>
</div>
</div>
</div>
</header>
In your case I don't think that styling with position: abosolute on the icon would be a wise idea. I changed it to be a flex child of .icon-container. You can see if it helps.
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
.increase {
float: right;
cursor: pointer;
}
.decrease {
float:left;
margin: 0px 15px 15px 0px;
cursor: pointer;
}
span {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
#contenitore {
width: 60%;
background-color: blue;
}
img {
max-width: 100%;
height: auto;
}
img:hover {
width: 310px;
height: auto;
}
.icon-container {
display: flex;
align-items: center;
justify-content: space-between;
}
.mySlides {
width: 300px;
height: 300px;
border-radius: 50%;
margin: auto
}
<!-- Icons fontAwesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<header class="ricerca">
<div class="container">
<div class="row">
<div class="icon-container col-sm-12 align-self-center">
<span class="decrease" onclick="plusDivs(-1)" value="Decrease Value"><i class="fas fa-chevron-circle-left" style="font-size:50px;"></i></span>
<div class="w3-tooltip">
<img class="mySlides shadow-lg p-3 mb-5" src="https://image.flaticon.com/icons/png/512/945/945170.png">
</div>
<span class="increase" onclick="plusDivs(1)" value="Increase Value"><i class="fas fa-chevron-circle-right" style="font-size:50px;"></i></span>
</div>
</div>
</div>
</header>

Trouble keeping buttons positioned at the bottom of the image - In responsive image gallery

I've made a image gallery and I'm stuck on this problem from from quite time now as I want to position next and previous button on the bottom of the image but how can I make the buttons relative to the image as images are different and changes. How to put controller button at the bottom of the image.
What I'm trying to do:
It has Full Screen background modal. (Done)
Upon that modal it shows images. (Done)
On image's bottom I want to keep a constant showing controller buttons which are next and previous button to change through images. (Stuck from two days)
Tried Till Now:
Tried to make buttons relative to div's class "modal-content and image" but according to width size my buttons moves.
Tried changing heights and widths of the divs and tried some other things too.
At the end when nothing worked. I tried to achieve layout in a improper way by positioning buttons all the way from 1900px to 400px by media queries. But it still doesn't look good and accurate. (Have to use media queries only.)
I know this is not a right way. What am I missing here? how to make elements responsive in this type of situations?
Please let me know by your expertise if I should try any different approach or If I do some mistakes with my CSS code.
function openModal() {
document.getElementById('myModal').style.display = "block";
}
function closeModal() {
document.getElementById('myModal').style.display = "none";
}
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
if (n > slides.length) {
slideIndex = 1;
}
if (n < 1) {
slideIndex = slides.length;
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
}
.photos-thumbnail {
width: 440px;
}
.photos-thumbnail img {
margin: 10px 2px 0 0;
width: 140px;
height: 100px;
cursor: pointer;
}
.view-all-photos:hover {
opacity: 0.7;
}
.column {
float: left;
width: 16.6%;
}
.pro-modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
}
.modal-content {
position: relative;
margin: 50px auto 0;
width: 100%;
height: 90%;
background-color: rgba(0, 0, 0, 0.1);
}
.myslides img {
object-fit: contain;
background-color: rgba(0, 0, 0, 0.1);
width: 100%;
height: 100%;
}
.mySlides {
display: none;
}
.column img {
width: 100%;
}
.controller {
position: absolute;
background: linear-gradient(transparent, #1A1A1A);
text-align: center;
height: 12%;
width: 100%;
padding-top: 20px;
margin-top: -110px;
}
.prev,
.next {
position: absolute;
cursor: pointer;
background-color: rgba(0, 0, 0, 0.4);
color: #ffffff;
border: 1px solid #02BFC1;
border-radius: 50%;
width: 33px;
padding: 15px;
font-size: 25pt;
transition: 0.6s ease;
user-select: none;
-webkit-user-select: none;
}
.next {
margin-left: 50px;
}
.prev {
margin-left: -50px;
}
<div class="photos-thumbnail">
<img class="hover-shadow" onclick="openModal(); currentSlide(1)" src="https://wallpaperscraft.com/image/hitman_xbox_360_absolution_76000_1280x720.jpg">
<img class="hover-shadow" onclick="openModal(); currentSlide(2)" src="https://www.technobuffalo.com/wp-content/uploads/2014/03/Hitman-Absolution-2-1280x720.jpg">
<img class="hover-shadow" onclick="openModal(); currentSlide(3)" src="http://fextralife.com/wp-content/uploads/2015/01/Far-Cry-4-Tiger.jpg">
</div>
<div id="myModal" class="pro-modal">
<div class="modal-content">
<div onkeydown="ff(e)" class="mySlides">
<img src="https://wallpaperscraft.com/image/hitman_xbox_360_absolution_76000_1280x720.jpg">
</div>
<div onkeydown="ff(e)" class="mySlides">
<img src="https://www.technobuffalo.com/wp-content/uploads/2014/03/Hitman-Absolution-2-1280x720.jpg">
</div>
<div onkeydown="ff(e)" class="mySlides">
<img src="http://fextralife.com/wp-content/uploads/2015/01/Far-Cry-4-Tiger.jpg">
</div>
<div class="controller">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="sep">|</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
</div>
Output I want Even While Resizing
This happens after Browser window Resize. Image will start to fit the window and shrink as I want but buttons will be statically at the bottom.
If you change the display of the slides to this:
slides[slideIndex - 1].style.display = "inline-grid";
and with a few additionally changes at the css it should work.
The green marks are my changes.
I inserted a smaller image so that you can see the result in the code below.
I hope it helps.
EDIT:
To make the images resizing just add to your css:
img{
max-width: 100%;
height: auto;
}
And if you want the buttons staying in the middle during resizing, just put the controller div into the mySlides div -> see my code snippet
function openModal() {
document.getElementById('myModal').style.display = "block";
}
function closeModal() {
document.getElementById('myModal').style.display = "none";
}
var slideIndex = 1;
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
if (n > slides.length) {
slideIndex = 1;
}
if (n < 1) {
slideIndex = slides.length;
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex - 1].style.display = "inline-grid";
dots[slideIndex - 1].className += " active";
}
.photos-thumbnail {
width: 440px;
}
.photos-thumbnail img {
margin: 10px 2px 0 0;
width: 140px;
height: 100px;
cursor: pointer;
}
.view-all-photos:hover {
opacity: 0.7;
}
.column {
float: left;
width: 16.6%;
}
.pro-modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
}
.modal-content {
text-align: center;
position: relative;
width: 100%;
height: 90%;
background-color: rgba(0, 0, 0, 0.1);
}
.mySlides img {
padding-left:75px;
object-fit: contain;
background-color: rgba(0, 0, 0, 0.1);
}
img{
max-width: 100%;
height: auto;
}
.mySlides {
display: none;
margin-right:75px;
margin-top:25px;
}
.column img {
width: 100%;
}
.controller {
background: linear-gradient(transparent, #1A1A1A);
height: 100px;
width: 100%;
padding-top: 20px;
margin-top: -100px;
}
.prev,
.next {
text-align: center;
position: absolute;
cursor: pointer;
background-color: rgba(0, 0, 0, 0.4);
color: #ffffff;
border: 1px solid #02BFC1;
border-radius: 50%;
width: 50px;
padding: 15px;
font-size: 25pt;
transition: 0.6s ease;
user-select: none;
-webkit-user-select: none;
}
.next {
margin-left: 50px;
}
.prev {
margin-left: -50px;
}
<div class="photos-thumbnail">
<img class="hover-shadow" onclick="openModal(); currentSlide(1)" src="https://wallpaperscraft.com/image/hitman_xbox_360_absolution_76000_1280x720.jpg">
<img class="hover-shadow" onclick="openModal(); currentSlide(2)" src="https://www.technobuffalo.com/wp-content/uploads/2014/03/Hitman-Absolution-2-1280x720.jpg">
<img class="hover-shadow" onclick="openModal(); currentSlide(3)" src="http://lorempixel.com/400/200/">
</div>
<div id="myModal" class="pro-modal">
<div class="modal-content">
<div onkeydown="ff(e)" class="mySlides">
<img src="https://wallpaperscraft.com/image/hitman_xbox_360_absolution_76000_1280x720.jpg">
<div class="controller">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="sep">|</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
<div onkeydown="ff(e)" class="mySlides">
<img src="https://www.technobuffalo.com/wp-content/uploads/2014/03/Hitman-Absolution-2-1280x720.jpg">
<div class="controller">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="sep">|</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
<div onkeydown="ff(e)" class="mySlides">
<img src="http://lorempixel.com/400/200/">
<div class="controller">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="sep">|</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
</div>
</div>
You can add display: flex, justify-content: (wherever in the image you want your buttons to be), and text-align to centre your buttons and their text.

Bind the index and ionic card together - ionic

I am doing a project on ionic. It is a quiz type app. I have scrollable div on the top which contains all the question numbers. Below that I have cards where questions are appearing. The screenshot is below :
The cards have swipable feature in it that users can swipe the cards to and fro.
My requirement is when the user selects a particular question from the top question number panel, corresponding questions should show and the selected question should be highlighted. Also when the user swipes the cards, the selection of the question numbers in the top should also change.
I created a circle using css for the above panel and using ng-repeat, I am repeating the question numbers. I added a ng-click option on the question number and passing the index. So that I can show the corresponding question. By using this I am able to bind the both panels in one way. I need to bind it reverse too. So that when user swipes the card, the question number should change.
Also I need to highlight a particular item in ng-repeat to show that that is selected. I tried :hover property in css, it somehow highlighting the selected item but not as good as expected.
Here is my code:
angular.module('quiz', ['ionic'])
.controller('QuizController', function($scope) {
$scope.nodes = [{
count: 1,
disabled: false
}, {
count: 2,
disabled: false
}, {
count: 3,
disabled: false
}, {
count: 4,
disabled: false
}, {
count: 5,
disabled: true
}];
$scope.goToQuestionNumber = function(index) {
console.log('goToQuestionNumber: ', index);
$scope.currentQuestion = index;
$scope.act_type = $scope.quiz.clues[$scope.currentQuestion].act_type;
$scope.isActive = $scope.nodes[index];
changeTemplate();
}
$scope.next = function() {
if ($scope.currentQuestion != ($scope.nodes.length - 1)) {
$scope.currentQuestion++;
$scope.currentTry = 1;
$scope.act_type = $scope.quiz.clues[$scope.currentQuestion].act_type;
$scope.failureResult = false;
changeTemplate();
}
}
$scope.prev = function() {
if ($scope.currentQuestion != 0) {
$scope.additionalActivity = false;
$scope.addtionalQuestionAvailability = false;
console.log('Left swipe');
$scope.currentQuestion = $scope.currentQuestion - 1;
$scope.currentTry = 1;
$scope.act_type = $scope.quiz.clues[$scope.currentQuestion].act_type;
$scope.failureResult = false;
changeTemplate();
}
}
})
.events {
position: relative;
}
.event,
span .event,
.event span {
content: "";
float: left;
position: relative;
padding: 3%;
margin: 0% 2% 0% 2%;
border-radius: 50%;
background-color: lightgrey;
border: 3px solid darkgray;
top: 15%;
left: 2%;
font-size: 15px;
z-index: 1;
text-align: center;
line-height: 150%;
color: hotpink;
}
.slider-column {
position: relative;
display: flex;
flex: 0 0 30%;
}
.slider-column::after {
content: '';
height: 3px;
width: 100%;
background-color: #66a3ff;
position: absolute;
top: 45%;
z-index: -5;
margin-left: 0%;
border-radius: 1% 1% 1% 1%;
padding: 1%;
}
.slider-column:last-child:after {
content: '';
height: 2%;
width: 100%;
background-color: transparent;
position: absolute;
top: 30%;
}
/*.event::after{
content:'';
height:3px;
width:170%;
background-color:#6d6dff;
position: absolute;
top: 45%;
z-index: -5;
margin-left: 55%;
border-radius: 1% 1% 1% 1%;
padding: 1%;
}*/
.event::before {
content: '';
height: 5px;
width: 100%;
background-color: transparent;
position: absolute;
top: 30%;
z-index: -5;
padding-left: 10%;
}
.events:first-child:before {
content: '';
height: 5px;
width: 100%;
background-color: transparent;
position: absolute;
top: 30%;
}
.events:last-child-1:after {
content: '';
height: 5px;
width: 100%;
background-color: transparent;
position: absolute;
top: 30%;
}
.timeline-text {
z-index: 4;
top: 0;
bottom: 5px;
}
.enabled-event {
background: red;
}
.event:hover {
border-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/ionic/1.3.0/js/ionic.bundle.min.js"></script>
<ion-content ng-app="quiz" ng-controller="QuizController">
<div style="padding-top:10px;padding-left:5px;">
<label class="hamburger" style="float:left">Score:{{totalPoints}} pts</label>
<button style="float:right" class="button button-clear button-small bonus-button" ng-click="bonus()">Try Bonus</button>
</div>
<br>
<br>
<ion-scroll direction="x" class="timeline-scroll">
<div class="timeline">
<div class="events row">
<div class="slider-column" ng-repeat="count in nodes">
<span class="event " ng-click="goToQuestionNumber($index)" ng-if="!count.disabled">
{{count.count}}/{{nodes.length}}
</span>
<span class="event" ng-click="goToQuestionNumber($index)" ng-if="count.disabled">
{{count.count}}/{{nodes.length}}
<!-- </span> -->
</div>
</div>
</div>
</ion-scroll>
<br>
<br>
<div ng-include="currentClueTemplate" ng-swipe-right="prev()" ng-swipe-left="next()" class="question-card"></div>
</ion-content>
Can anyone help me ?

How To Place Buttons Around A Circle with HTML5 and CSS 3?

I want to arrange 4 buttons (or bootstrap tabs,doesn't matter) around a circle and load a content in the middle of that circle,something like this:
How can i do that?
you could use a small bit of jquery to load your center circle with the text you want.
$(document).ready(function() {
$('.quart').click(function() {
var ind = $(this).index();
switch (ind) {
case 0:
var tex = "div 1";
break;
case 1:
var tex = "div 2";
break;
case 2:
var tex = "div 3";
break;
case 3:
var tex = "div 4";
break;
}
$('.center').text(tex);
});
});
.wrap {
height: 300px;
width: 300px;
border-radius: 50%;
position: relative;
overflow: hidden;
}
.quart {
position: absolute;
height: 50%;
width: 50%;
background: tomato;
transition: all 0.4s;
}
.quart:first-child {
top: 0;
left: 0;
}
.quart:nth-child(2) {
top: 0;
left: 50%;
}
.quart:nth-child(3) {
top: 50%;
left: 0;
}
.quart:nth-child(4) {
top: 50%;
left: 50%;
}
.center {
height: 80%;
width: 80%;
position: absolute;
top: 10%;
left: 10%;
background: lightgray;
border-radius: 50%;
text-align: center;
line-height: 160px;
}
.quart:hover {
background: dimgray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrap">
<div class="quart"></div>
<div class="quart"></div>
<div class="quart"></div>
<div class="quart"></div>
<div class="center">Click My non-existent Corners!</div>
</div>
This probably won't be as efficient as an svg solution, but colud be altered to your needs.
You can use the HTML <map> tag - more info

Lines behind image (top and bottom)

I have a centered image on my website, where i need a top and bottom line.
The catch here, is that i need both lines 1px in behind the image, so that they are "align" in top and bottom of the image. I tried using box-shadow but it doesn't work in IE8 (i know it's terrible).
Anyone who has a answer and dying to tell me?
A quick UPDATE to show you my issue:
I'm using bootstrap 2 and displaying a carousel for images. And when there are only one image, the line should be visible. It need to be able to run in IE8 for the customer.
Image example:
http://postimg.org/image/xi3eurm81/
My example with shadow-box is here:
Html:
<div id="artist-carousel">
<div class="simple-carousel-window">
<div class="simple-carousel-rail">
#if (Model != null)
{
for (var i = 0; i < 3 * Model.Images.Count; i++) // times 3 due to infinite scrolling
{
var index = i % Model.Images.Count;
<div class="simple-carousel-div" data-index="#(i)" data-link="#Model.NativeImages[index]">
<a class="element">
<img src="#Model.Images[index]" />
</a>
<a class="fullsize">
<img src="~/content/images/carousel-fullsize.png" />
</a>
</div>
if (Model.Images.Count <= 2 && i >= 0) { break; }
}
}
</div>
#if (Model.Images.Count >= 3)
{
<a class="simple-carousel-prev" href="#" data-slide="prev">
<img src="~/content/images/carousel-left.png" /></a>
<a class="simple-carousel-next" href="#" data-slide="next">
<img src="~/content/images/carousel-right.png" /></a>
}
</div>
</div>
CSS:
.simple-carousel-window {
width: 820px;
white-space: nowrap;
overflow: hidden;
position: relative;
display: block;
margin-left: -20px;
box-shadow: inset 0 2px 2px -2px #ebebeb, inset 0 -2px 2px -2px #ebebeb;
line-height: 0;
margin-bottom: 20px;
.simple-carousel-rail {
font-size: 0;
}
.simple-carousel-prev {
position: absolute;
top: 150px;
left: 10px;
display: block;
opacity: 0.8;
}
.simple-carousel-next {
position: absolute;
top: 150px;
right: 10px;
display: block;
opacity: 0.8;
}
.simple-carousel-div {
display: inline-block;
position: relative;
.element {
img {
height: 360px;
float: left;
}
}
.fullsize {
display: block;
opacity: 0.5;
position: absolute;
// centering image
top: 150px;
margin-left: -85px;
left: 50%;
}
}
}
DEMO: http://jsfiddle.net/CXKrh/
HTML
<div>
<img src="http://placekitten.com/100" />
</div>
CSS
div {
width: 300px;
height: 98px;
overflow: visible;
border: 1px solid red;
}
div > img {
height: 100px;
margin-top: -1px;
}
The idea is that the height of the container = image height - border width (top and bottom)
We then apply a negative margin to the images to "bump" the image back over the border.