What I'm trying to create
Using HTML5 and CSS3 only, a horizontal row of three circles, each sitting on top of a different image, containing another image and one word of text.
What I have tried
I have tried to create this by just adding divs within divs and specifying heights and widths, but this has not worked. I sense I'm over-complicating something quite simple, or forgetting something very obvious. What is the simplest way of doing this?
A note
Go easy on me! I've been trying to self-learn for only 2 months.
The HTML
<div class="circlewrapper">
<div class="sector" id="read">
<img src="images/test1.jpg" class="image1" height="165" width="165" />
<div class="round" id="reading">
<img src="images/book.jpg" class="image2" height="20" width="20" />
<p id="readread">Read</p>
</div>
</div>
<div class="sector" id="listen">
<img src="images/test2.jpg" class="image1" height="165" width="165" />
<div class="round" id="listening">
<img src="images/book.jpg" class="image2" height="20" width="20" />
<p id="listlist">Listen</p>
</div>
</div>
<div class="sector" id="watch">
<img src="images/test3.jpg" class="image1" height="165" width="165" />
<div class="round" id="watching">
<img src="images/book.jpg" class="image2" height="20" width="20" />
<p id="watchwatch">Watch</p>
</div>
</div>
</div>
The CSS
.circlewrapper {
width: 800px;
height: 270px;
padding: 0px;
margin: 0px auto 0px auto;}
.sector {
width: 250px;
height: 250px;
padding: 0px;
margin: 8px;
display: inline;}
.round {
height: 165px;
width: 165px;
padding: 0px;
margin: 0px auto 0px auto;
background-color: blue;
border-radius: 165px;
-moz-border-radius: 165px;
-webkit-border-radius: 165px;
z-index: 10;}
p {
text-align: center;
color: white;}
.image1 {
margin: 0px auto 0px auto;
padding: 0px;
z-index: 5;}
.image2 {
margin: 0px auto 0px auto;
padding: 0px;}
Add to .sector float: left;. It worked for me.
Related
I need to center images side by side (warp) & also be able to change images on hover, seems like I can't do both at the same time.
Here is what is have tried:
The first part is the centering part; it works.
The 3rd part is the hover part; that works too but only if justified to the left
and the 2nd part is both and it gets crazy when I hover over.
a img:last-child {
display: none;
}
a:hover img:last-child {
display: block;
}
a:hover img:first-child {
display: none;
}
.fblogo {
display: inline-block;
margin-left: auto;
margin-right: auto;
height: 200px;
}
#images{ text-align: center; }
#images2{ text-align: center; }
<div id="images">
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141420_2072_Artboard-55.png" />
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141436_2072_Artboard-50.png" />
</div>
<div id="images2">
<a href="https://cs13498732.churchspring.org/get-involved/breakway/">
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141420_2072_Artboard-55.png" />
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141416_2072_Artboard-56.png" />
</a>
<a href="https://www.facebook.com/OlympiaHaacht">
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141436_2072_Artboard-50.png" />
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141441_2072_Artboard-49.png" />
</a>
</div>
<div id="images3">
<a href="https://cs13498732.churchspring.org/get-involved/calvary-kids/">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141420_2072_Artboard-55.png" alt="" style="float: left; margin: auto;">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141416_2072_Artboard-56.png" alt="" style="background-color: initial; float: left; margin: auto;">
</a>
<a href="https://cs13498732.churchspring.org/get-involved/breakway/">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141436_2072_Artboard-50.png" alt="" style="float: left; margin: 0px 30px 30px 0px;">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141441_2072_Artboard-49.png" alt="" style="float: left; margin: 0px 30px 30px 0px;">
</a>
</div>
This is a simple solution which uses a Flexbox to centre the content automatically
HTML
<div class="flex justify-center">
<div>
<a href="https://cs13498732.churchspring.org/get-involved/calvary-kids/">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141420_2072_Artboard-55.png" alt="" style="float: left; margin: auto;">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141416_2072_Artboard-56.png" alt="" style="background-color: initial; float: left; margin: auto;">
</a>
</div>
<div>
<a href="https://cs13498732.churchspring.org/get-involved/breakway/">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141436_2072_Artboard-50.png" alt="" style="float: left; margin: 0px 30px 30px 0px;">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141441_2072_Artboard-49.png" alt="" style="float: left; margin: 0px 30px 30px 0px;">
</a>
</div>
</div>
CSS
a img:last-child {
display: none;
}
a:hover img:last-child {
display: block;
}
a:hover img:first-child {
display: none;
}
.fblogo {
height: 200px;
}
.flex {
display:flex;
}
.justify-center {
justify-content: center;
}
View On JSFiddle
https://jsfiddle.net/MrGreyKnight/qmsfj89h/4/
Nice Guide to Flexboxes :)
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
so my problem is, that I can't make href area image-sized. I still get white border up, left, right of my image, I tried display: inline-block, without any luck. This is my CSS (I know it looks pretty awful):
div.gallery {
margin: 1%;
-webkit-box-shadow: 10px 10px 25px #000;
-moz-box-shadow: 10px 10px 25px #000;
box-shadow: 10px 10px 25px #000;
float: left;
min-width: 180px;
width: 23%;
}
div.gallery a {
background-color: red;
display: inline-block !important;
}
div.gallery img {
display: block;
}
div.desc {
padding: 15px;
text-align: center;
}
<div class="gallery">
<a href="myphoto.jpg">
<img src="http://dummyimage.com/200x150&text=myphoto.jpg" alt="" />
</a>
<div class="desc">XXX</div>
</div>
<div class="gallery">
<a target="_blank" href="myphoto.jpg">
<img src="http://dummyimage.com/200x150&text=myphoto.jpg" alt="" />
</a>
<div class="desc">XXX</div>
</div>
EDIT: Thanks for answer, but I think I could be a little unclear:
I made a gallery, that displays 4 imgs in a row, no matter if the screen resolution is hd, or 1024x768. It's responsive. in div.gallery img I set width to be 100% (which I forgot to add here). My problem is, that I have something like this when setting on the images: white border caused by a href.
The a inline-block element will not expand if its contents have no dimension. Once I set a dimension to the img than it works.
img {
width:180px;
height:100px;
}
div.gallery {
margin: 1%;
-webkit-box-shadow: 10px 10px 25px #000;
-moz-box-shadow: 10px 10px 25px #000;
box-shadow: 10px 10px 25px #000;
float: left;
min-width: 180px;
width: 23%;
}
div.gallery a {
background-color: red;
display: inline-block;
}
div.gallery img {
display:inline-block;
}
div.desc {
padding: 15px;
text-align: center;
}
<div class="gallery">
<a href="myphoto.jpg">
<img src="myphoto.jpg" alt="" />
</a>
<div class="desc">XXX</div>
</div>
<div class="gallery">
<a target="_blank" href="myphoto.jpg">
<img src="myphoto.jpg" alt="" />
</a>
<div class="desc">XXX</div>
</div>
you can use below code for solve your problem.
div.gallery {
margin: 1%;
-webkit-box-shadow: 5px 5px 15px #000;
-moz-box-shadow: 5px 5px 15px #000;
box-shadow: 5px 5px 15px #000;
float: left;
min-width: 160px;
width: 25%;
}
div.gallery a{
width: 100%;
background-color: yellow;
display: inline-block !important;
}
div.gallery img {
display:block;
position: absolute;
}
div.desc {
padding: 20px;
text-align: center;
}
<div class="gallery">
<a href="myphoto.jpg">
<img src="myphoto.jpg" alt="" height="100px" width="100%" />
<div class="desc">AAA</div>
</a>
</div>
<div class="gallery">
<a target="_blank" href="myphoto.jpg">
<img src="myphoto.jpg" alt="" height="100px" width="100%" />
<div class="desc">BBB</div>
</a>
</div>
There's a really simple fix for this.
Simply wrap your a around the div too, then set, on your images: height="48px" width="100%" position: absolute;
Finally, set the width of your anchors to 100%;
Let me know if you have any questions. Thanks
https://jsfiddle.net/v45k8ojk/2/
Try changing
<img src="myphoto.jpg" alt="" />
to
<img src="myphoto.jpg" alt="image1">
Image tag does not require end of the tag.
I have 7 divs in a row on and I can't get the arrows in the middle to be horizontally in the centre of the outer div.
I've tried
top: 50%;
text-align: centre:
margin: 0 auto;
But none of them seem to work. How can I correct this?
HTML:
<div id="instruct">
<div align="center" class="category">
<img src="http://www.devo.co.uk/wp-content/uploads/2016/07/1-DEVO.png" width="150" height="auto"/>
<p class="ititle">1. You Order</p>
<p class="itext">Shop and browse your favorite<br>brands from your local shops</p>
</div>
<div align="center" class="arrow">
<img src="http://www.devo.co.uk/wp-content/uploads/2016/08/rightgreyarrow.png" width="50" height="auto"/>
</div>
<div align="center" class="category">
<img src="http://www.devo.co.uk/wp-content/uploads/2016/07/2-DEVOnewblue.png" width="175" height="auto"/>
<p class="ititle">2. We Collect</p>
<p class="itext">Our drivers make their way to your<br>local shop</p>
</div>
<div align="center" class="arrow">
<img src="http://www.devo.co.uk/wp-content/uploads/2016/08/rightgreyarrow.png" width="50" height="auto"/>
</div>
<div align="center" class="category">
<img src="http://www.devo.co.uk/wp-content/uploads/2016/07/3-DEVOcolour.png" width="95" height="auto"/>
<p class="ititle">3. We Deliver</p>
<p class="itext">Our drivers make their way to<br>your location</p>
</div>
<div align="center" class="arrow">
<img src="http://www.devo.co.uk/wp-content/uploads/2016/08/rightgreyarrow.png" width="50" height="auto"/>
</div>
<div align="center" class="category">
<img src="http://www.devo.co.uk/wp-content/uploads/2016/07/4-DEVO.png" width="65" height="auto"/>
<p class="ititle">4. You Enjoy</p>
<p class="itext">Track and receive your order<br>in as little as 30 minutes</p>
</div>
</div>
CSS:
#instruct {
height: auto;
width: 100%;
background-color: transparent;
border-bottom: 3px solid #fd0e35;
}
.category {
padding: 40px 50px 10px 50px;
display: inline-block;
}
.arrow {
padding: 0px;
display: inline-block;
border: 1px solid pink;
}
.ititle {
margin-top: 20px;
margin-bottom: 0;
text-transform: uppercase;
font-weight: bold;
font-size: 14px;
color: #a6a6a6;
}
.itext {
font-size: 13px;
}
The simplest solution is the use of vertical-align: middle; on the children of the container:
#instruct > div { vertical-align: middle; }
See this fiddle.
You need to relatively position the element in order for the 'top' property to take effect:
.arrow {
padding: 0px;
display: inline-block;
border: 1px solid pink;
position:relative;
top:-50px; // <---- change this value to suit your preferred positioning.
}
Here is my code: http://pastebin.com/pDkM4FQi
#img1,
#img2,
#img3,
#img4 {
display: inline-block;
height: 100%;
}
#navBar {
background-color: white;
border: 1px solid white;
border-radius: 15px;
display: inline-block;
height: 100px;
margin: auto;
margin-top: 50px;
width: 1200px;
}
#navSplitter {
background-color: gray;
display: inline-block;
height: 80px;
margin-left: 20px;
margin-right: 20px;
width: 3px;
}
<div id="navBar">
<div id="navSplitter" style="background-color: black;" />
<img id="img1" src="img1.png" />
<div id="navSplitter" />
<img id="img2" src="img2.png" />
<div id="navSplitter" />
<img id="img3" src="img3.png" />
<div id="navSplitter" />
<img id="img4" src="img4.png" />
</div>
I can't get the images to line up in the navBar div. I tried everything I know about code, and even looked up some stuff but never found what I need to get these images to go on there with the splitters in between each picture.
How about putting all of the images in just one <div> and then add a left-padding and right-padding to the images? This way you don't have to deal with the alignment of the images that much.
Please note that id tags are unique. You don't use them everywhere in the html file. Use class if you need
The issue is in your HTML. There is no concept of self closing div tags in HTML 4.x.
change this <div id="navSplitter"/> to <div id="navSplitter"></div>.
or my suggestion is to use <span></span> tag to add splite because span is by-default inline-block element.
Hope this would help your issue.
Try this:- remove margin-left: 20px from #naviSplitter
<head>
<style>
#img1, #img2, #img3, #img4 {
display: inline-block;
height: 100%;
}
#navBar {
background-color: white;
border: 1px solid white;
border-radius: 15px;
display: inline-block;
height: 100px;
margin: auto;
margin-top: 50px;
width: 1200px;
}
#navSplitter {
background-color: gray;
display: inline-block;
height: 80px;
/*margin-left: 20px;*/
margin-right: 20px;
width: 3px;
}
</style>
</head>
<body>
<div id="navBar">
<div id="navSplitter" style="background-color: black;"/>
<img id="img1" src="img1.png"/>
<div id="navSplitter"/>
<img id="img2" src="img2.png"/>
<div id="navSplitter"/>
<img id="img3" src="img3.png"/>
<div id="navSplitter"/>
<img id="img4" src="img4.png"/>
</div>
</body>
divs aren't a self closing tag, which you are doing, therefore invalid HTML and by consequence the images are not working as expected.
So, I advise you to forget using div for splitting the images and just use a HTML list and then using a pseudo element ::before instead.
And to align, you need vertical-align:top because inline-block is baseline by default
#navBar {
background-color: white;
border: 1px solid white;
border-radius: 15px;
display: inline-block;
height: 100px;
margin: auto;
margin-top: 50px;
width: 1200px;
}
ul {
font-size: 0
}
li {
display: inline-block;
vertical-align: top;
height: 100%;
margin: 0 5px
}
li::before {
background-color: gray;
display: inline-block;
vertical-align: top;
height: 100px;
left: -5px;
width: 3px;
content: "";
position: relative
}
<div id="navBar">
<ul>
<li>
<img id="img1" src="//dummyimage.com/100x100" />
</li>
<li>
<img id="img2" src="//dummyimage.com/100x100" />
</li>
<li>
<img id="img3" src="//dummyimage.com/100x100" />
</li>
<li>
<img id="img4" src="//dummyimage.com/100x100" />
</li>
</ul>
</div>
Maybe you would rather something like this.
<div id="nav-bar">
<img src="http://dummyimage.com/80&text=1" alt="">
<img src="http://dummyimage.com/80&text=2" alt="">
<img src="http://dummyimage.com/80&text=3" alt="">
<img src="http://dummyimage.com/80&text=4" alt="">
</div>
Don't worry about closing tags for img elements anymore. But do make sure you write something descriptive in the alt attribute about what the image content is for people with disabilities.
html {
font-size: 16px;
}
I'm using rems to do most measurements. rems are based off of a base font-size. So we tend to set it in the html element. I think 16px is a good standard these days. 1rem therefore is 16px.
Using measurements like this allows you to arrange things relatively. You could also interchange with ems if you wanted to. They are based off of the parent element font-size.
#nav-bar {
max-width: 1200px;
width: 100%;
margin: 2rem auto;
text-align: center;
background-color: white;
border-radius: 1rem;
display: inline-block;
padding: .5rem;
}
#nav-bar img {
display: inline-block;
}
#nav-bar img:not(:last-child) {
margin-right: 1rem;
padding-right: 1rem;
border-right: 3px solid gray;
}
Instead of using an HTML element for aesthetics, we can push that into the CSS completely.
I use a right border on those navigation images and make use of the not pseudo-class combined with last-child as :not(:last-child) which selects all the images except the last one. So you don't see the right border at the end.
Your HTML is not valid. div tags cannot be closed this way.
<div />.
div tags are properly used this way.
<div></div>
Due to the lack of closing tags, your images and splitters are nested. This happens because your browser does not know how to display your page since the opened/closed tags don't match up. It is then trying to fix your code by adding a bunch of closing tags at the bottom of the code, one closing tag for each opened one that was not closed.
By simply closing your div tags, your images will align properly. Your CSS is valid.
No one talks about FLEXBOX. Still care about old IE?
#navBar {
background-color: white;
border: 1px solid white;
border-radius: 15px;
width: 1200px;
display: flex;
justify-content: center;
align-items: center;
}
img { width: 100px; height: 100px; background: red; }
hr {
border: none;
background-color: gray;
height: 80px;
margin-left: 20px;
margin-right: 20px;
width: 3px;
}
<div id="navBar">
<img id="img1" src="img1.png" />
<hr>
<img id="img2" src="img2.png" />
<hr>
<img id="img3" src="img3.png" />
<hr>
<img id="img4" src="img4.png" />
</div>
I would recommend removing the navSplitter elements completely, as they add an extra set of items (unnecessarily) that will need to be styled to ensure the images line up. Instead, you can just add padding / borders to the images individually, which will separate them as desired. Consider the following:
.image {
display: inline-block;
height: 100%;
padding: 20px;
border-right: 3px solid gray;
}
.image:last-of-type {
border-right: none;
}
#navBar {
background-color: white;
border: 1px solid white;
border-radius: 15px;
display: inline-block;
height: 100px;
margin: auto;
margin-top: 50px;
width: 1200px;
}
<div id="navBar">
<img class="image" src="http://placehold.it/150x150" />
<img class="image" src="http://placehold.it/150x150" />
<img class="image" src="http://placehold.it/150x150" />
<img class="image" src="http://placehold.it/150x150" />
</div>
I know this a rather specific question and basic html question, but it's been happening on a few of my pages now, and I'm curious as to what exactly is going on.
I have a series of div boxes lined up vertically on a page, each one contains a picture that is a link to a different page on the website. The problem is when I add more than 3 of these div boxes, suddenly all the links on above the bottom three stop working.
http://webstage.emich.edu/dining-new/locations/easterneateries.php
I've tried the same code in jsfiddle, as seen below:
.locationsbx {
position:absolute;
width: 540px;
height:70px;
z-index:5;
margin-left: auto;
margin-right:auto;
background-color: #363636;
margin-top:110px;
}
.primetriangle {
border-top:25px solid green;
height: 0;
position:absolute;
width: 0;
z-index:3;
border-right: 25px solid transparent;
height: 0;
position:absolute;
width: 0;
z-index:5;
border-top-color: #CCC;
}
<div class="locationsbx" style="position: absolute; width: 100%; height: 100px; margin-top: 20px;">
<div class="primetriangle" style="z-index: 4;"></div> <img style="width: 85px; margin-left: 5px; margin-top: -18px;" src="/dining-new/images/eateries/estreet.png" alt="" />
<div class="text" style="margin-left: 100px; margin-top: -35px; width: 430px;">text</div>
<div style="position: absolute; margin-left: 270px; margin-top: 45px; width: 320px;">
<img style="height: 35px;" src="/dining-new/images/open.png" alt="" />
<img style="margin-left: 2px; height: 35px; display: inline;" src="/dining-new/images/menu.png" alt="" onmouseover="this.src='/dining-new/images/menu_hover.png';" onmouseout="this.src='/dining-new/images/menu.png';" />
<img style="margin-left: 2px; height: 35px; display: inline;" src="/dining-new/images/nutrition.png" alt="" onmouseover="this.src='/dining-new/images/nutrition_hover.png';" onmouseout="this.src='/dining-new/images/nutrition.png';" />
</div>
</div>
<div class="locationsbx" style="position: absolute; width: 100%; height: 100px; margin-top: 130px;">
<div class="primetriangle" style="z-index: 4;"></div> <img style="width: 85px; margin-left: 5px; margin-top: -18px;" src="/dining-new/images/eateries/sunsetstripslogo.png" alt="" />
<div class="text" style="margin-left: 100px; margin-top: -35px; width: 430px;">text</div>
<div style="position: absolute; margin-left: 270px; margin-top: 45px; width: 320px;">
<img style="height: 35px;" src="/dining-new/images/open.png" alt="" />
<img style="margin-left: 2px; height: 35px; display: inline;" src="/dining-new/images/menu.png" alt="" onmouseover="this.src='/dining-new/images/menu_hover.png';" onmouseout="this.src='/dining-new/images/menu.png';" />
<img style="margin-left: 2px; height: 35px; display: inline;" src="/dining-new/images/nutrition.png" alt="" onmouseover="this.src='/dining-new/images/nutrition_hover.png';" onmouseout="this.src='/dining-new/images/nutrition.png';" />
</div>
</div>
<div class="locationsbx" style="position: absolute; width: 100%; height: 100px; margin-top:240px;">
<div class="primetriangle" style="z-index: 4;"></div> <img style="width: 85px; margin-left: 5px; margin-top: -18px;" src="/dining-new/images/eateries/sunsetstripslogo.png" alt="" />
<div class="text" style="margin-left: 100px; margin-top: -35px; width: 430px;">text</div>
<div style="position: absolute; margin-left: 270px; margin-top: 45px; width: 320px;">
<img style="height: 35px;" src="/dining-new/images/open.png" alt="" />
<img style="margin-left: 2px; height: 35px; display: inline;" src="/dining-new/images/menu.png" alt="" onmouseover="this.src='/dining-new/images/menu_hover.png';" onmouseout="this.src='/dining-new/images/menu.png';" />
<img style="margin-left: 2px; height: 35px; display: inline;" src="/dining-new/images/nutrition.png" alt="" onmouseover="this.src='/dining-new/images/nutrition_hover.png';" onmouseout="this.src='/dining-new/images/nutrition.png';" />
</div>
</div>
<div class="locationsbx" style="position: absolute; width: 100%; height: 100px; margin-top: 350px;">
<div class="primetriangle" style="z-index: 4;"></div> <img style="width: 85px; margin-left: 5px; margin-top: -18px;" src="/dining-new/images/eateries/sunsetstripslogo.png" alt="" />
<div class="text" style="margin-left: 100px; margin-top: -35px; width: 430px;">text</div>
<div style="position: absolute; margin-left: 270px; margin-top: 45px; width: 320px;">
<img style="height: 35px;" src="/dining-new/images/open.png" alt="" />
<img style="margin-left: 2px; height: 35px; display: inline;" src="/dining-new/images/menu.png" alt="" onmouseover="this.src='/dining-new/images/menu_hover.png';" onmouseout="this.src='/dining-new/images/menu.png';" />
<img style="margin-left: 2px; height: 35px; display: inline;" src="/dining-new/images/nutrition.png" alt="" onmouseover="this.src='/dining-new/images/nutrition_hover.png';" onmouseout="this.src='/dining-new/images/nutrition.png';" />
</div>
</div>
and it's working fine there- so I'm confused as to what might be some of the reasons why putting the code on the actual server would be causing problems with disabling the links.
Any thoughts/explanations would be super super appreciated
**NOTE: I am well aware that it is not in good form to have inline styles, especially when I have the external CSS sheet anyways. However, the inline styles are just there until I can resolve the actual problem with the links.
** ALSO: The link to the page is very obviously under construction still. I have been dealing with the disabled links over multiple pages now and am much more concerned with why they're disabling than the rest of the page
I went to check the source of your page you linked to and you're not closing the <div> with the class="locationsbx" on your page. I think you're doing in the code you pasted above but not on the actual page.
EDIT: Not really a complete answer. I would have just left a comment but I need 50 points for that, I don't have those.