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.
Related
I have translated an image up to go behind a div to make it fit the design, however it leaves a white space below it, where the original image would be. How would I go about fixing this?
This is for a website, I've tried translating the sitemap up however then there is even more white space below the sitemap.
HTML:
<div class="portfolioImage" id="images">
<div class="portLogoImages" id="myDIV5">
<img src="./resources/portfolio/logoportfolio/logoPortfolio1.png" alt="" class="portfolioImages">
<img src="./resources/portfolio/logoportfolio/logoPortfolio2.png" alt="" class="portfolioImages">
<img src="./resources/portfolio/logoportfolio/logoPortfolio3.png" alt="" class="portfolioImages">
<img src="./resources/portfolio/logoportfolio/logoPortfolio4.png" alt="" class="portfolioImages">
<img src="./resources/portfolio/logoportfolio/logoPortfolio5.png" alt="" class="portfolioImages">
</div>
</div>
<div class="sitemap portAdjustment"> <!-- SITEMAP -->
<div class="sitemapItems">
<img src="./resources/sitemapLogo.png" alt="" class="sitemapLogo" width="166.3px" height="22px">
<div class="links">
<p >Home</p>
<p>Products</p>
<p>Portfolio</p>
<p>About Us</p>
<p>Contact Us</p>
</div>
<div class="finePrint">
<p>X is a part of the family company X that specialises in custom made design ranging from logo design to apparel design.</p>
<p>X</p>
</div>
</div>
</div>
CSS:
.portfolioImages {
border: none;
font-size: 0px;
transform: translateY(-25px);
max-width: 100%;
}
.portLogoImages {
border: none;
font-size: 0px;
transform: translateY(-25px);
max-width: 100%;
height: auto;
width: 100%;
margin-left: auto;
margin-right: auto;
}
.sitemap {
width: 100%;
height: 215px;
background-color: #f4f4f4;
padding: 30px 0px 30px 0px;
display: block;
text-align: center;
}
.finePrint {
padding-top: 70px;
color: #c8c8c8;
}
.sitemapItems {
padding: 0px 30px 0 30px;
display: block;
}
.sitemap a {
text-decoration: none;
color: #c8c8c8;
transition-duration: .2s;
display: inline-block;
padding-right: 4px;
}
.sitemap a:hover {
text-decoration: underline;
color: #434343;
}
I expect there to be no white space however there is still white space below it.
Just use margin-top instead transform
I've tried everything, but it seems like this span just won't do anything I tell it to. No applied properties change its vertical position, but horizontal properties do.
I've followed all the recommendations from this guide: https://css-tricks.com/centering-css-complete-guide/
Code:
#header{
height: 50px;
width: 100% - 50px;
padding: 0px 25px 0px 25px;
background-color: #00A680;
}
#header-right-icon-div > img{
height: 20px;
display: inline;
padding: 15px 10px 15px 10px;
}
#menu-join-button{
}
<div id="header">
<div id="header-right" style="float: right;">
<div id="header-right-icon-div">
<img src="briefcase_icon.svg" alt="">
<img src="notification_icon.svg" alt="">
<img src="profile_icon.svg" alt="">
<img src="search_icon.svg" alt="">
<span id="menu-join-button">hello</span>
</div>
</div>
</div>
Even top or bottom margins and padding don't affect it at all... but side margins do...
What is the issue here, why does this menu-join-button have a mind of it's own? How do I center the span in that green header?
Verticle align middle Way:
* {
box-sizing: border-box;
}
#header{
width: 100%;
padding: 0px 25px 0px 25px;
background-color: #00A680;
}
#header:after {
content: '';
display: table;
clear: both;
}
#header-right{
float:right;
padding: 10px 25px 10px 25px;
background-color: #00A680;
}
#header-right-icon-div > img{
display:inline-block;
vertical-align: middle;
padding: 0px 10px 0px 10px;
}
#menu-join-button{
}
<div id="header">
<div id="header-right">
<div id="header-right-icon-div">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<span id="menu-join-button">hello</span>
</div>
</div>
</div>
Flex Way:
* {
box-sizing: border-box;
}
#header{
width: 100%;
padding: 0px 25px 0px 25px;
background-color: #00A680;
display: flex;
justify-content: flex-end;
align-items:center;
}
#header-right{
padding: 10px 25px 10px 25px;
background-color: #00A680;
}
#header-right-icon-div {
display: flex;
align-items:center;
}
#header-right-icon-div > img{
padding: 0px 10px 0px 10px;
}
<div id="header">
<div id="header-right">
<div id="header-right-icon-div">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<span id="menu-join-button">hello</span>
</div>
</div>
</div>
I am struggling to make a polaroid image like. In which the image have a text in the bottom. I tried every instruction but failed to do so.
Here is my HTML code
<div id="Places" class="gallery">
<ul>
<li>
<a href="https://www.w3schools.com/css/css_image_gallery.asp" target="_blank">
<img src="images/babot1.jpg" alt="bobat1">
</a>
</li>
<li>
<a href="https://www.w3schools.com/css/css_image_gallery.asp" target="_blank">
<img src="images/lhouse1.jpg" alt="bobat1">
</a>
</li>
<li>
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVm6S8I2xd6nYz2ZORd7X2v" target="_blank">
<img src="images/babot1.jpg" alt="bobat1">
</a>
</li>
</ul>
</div>
and this is my css code that I use
div.gallery{
border:2px solid #ddd;
margin:0 auto;
margin-top:100px;
margin-bottom:30px;
border-radius:3px;
width:98%;
}
div.gallery::before{
content: "";
clear: both;
display: table;
}
div.gallery ul{
list-style-type:none;
overflow:hidden;
margin:0 auto;
}
div.gallery li a img {
margin: 20px 20px 21px 20px;
width: 28.50%;
float:left;
padding-bottom:50px;
}
EDIT 1:
Here is the sample photo of what I got.
<figure> + <figcaption> have been designed for this.
To make it Polaroid like, here's what I'd do:
figure {
border: 1px solid #f5f5f5;
border-radius: 5px;
padding: 10px;
display: inline-block;
box-shadow: 0 4px 5px -2px rgba(0,0,0,.2), 0 7px 10px 1px rgba(0,0,0,.14), 0 2px 16px 1px rgba(0,0,0,.12);
}
figure img {
display: block;
}
figcaption {
display: block;
padding: 1rem 0 .5rem;
color: #777;
}
<figure>
<img src="http://placehold.it/350x250" />
<figcaption>This would be a caption</figcaption>
</figure>
<figure>
<img src="http://placehold.it/250x350" />
<figcaption>This would be another caption</figcaption>
</figure>
Please note you're currently floating the <img> tags. If you want the above to work, you need to remove the following from your current CSS:
div.gallery li a img {
margin: 20px 20px 21px 20px;
width: 28.50%;
float:left;
padding-bottom:50px;
}
You can float your <figure>s instead.
there is an html tag to do what you want:
<figure>
<img src="myImage.jpg" alt="my image">
<figcaption>This is my image</figcaption>
</figure>
Put your text inside a div, position it absolute and give it a z-index of 90 or higher.
<div id="txt">This is a title</div>
<style>
position: absolute;
z-index: 99;
</style>
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>
Im trying to display 4 pictures with a title, description and a delete link on it. I cannot get the link to float right in the box I have.
here's the html
<div id="container">
<div class="image-wrapper">
<div id="image-container">
<img src="gallery_traditional_1.jpg" width="200" height="100"><br>
<span class="img-info">Title:</span>
<span class="img-info">Description:</span>
<span class="img-info alignright">Delete</span>
</div>
</div>
</div><!--end container -->
here's the css
#container {
width: 50%;
}
.image-wrapper {
display: inline-block;
width:200px;
padding: 10px;
}
#image-container {
color: #898989;
background:#F9F9F9;
border: solid 1px #ddd;
border-radius:10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
box-shadow: 0px 0px 10px #888;
-moz-box-shadow: 0px 0px 10px #888;
-webkit-box-shadow: 0px 0px 10px #888;
margin:5px auto;
padding:5px;
width:200px;
}
.img-info {
display: block;
}
.alignleft {
float:left;
}
.alignright {
float:right;
}
The html of the picture box gets repeated 3 more times. How can I get the third span link float to the left? Any help would be great.
Adding margin-top: -29px; should achieve this.
DEMO http://jsfiddle.net/4RZJx/1
HTML:
<div id="container">
<div class="image-wrapper">
<div id="image-container">
<img src="gallery_traditional_1.jpg" width="200" height="100"><br>
<span class="img-info">Title:</span>
<span class="img-info">Description:</span>
<span class="img-info">Delete</span>
</div>
<span class="img-info alignright">Delete</span>
</div>
<div class="image-wrapper">
<div id="image-container">
<img src="gallery_traditional_1.jpg" width="200" height="100"><br>
<span class="img-info">Title:</span>
<span class="img-info">Description:</span>
<span class="img-info">Description:</span>
</div>
<span class="img-info alignright">Delete</span>
</div>
<div class="image-wrapper">
<div id="image-container">
<img src="gallery_traditional_1.jpg" width="200" height="100"><br>
<span class="img-info">Title:</span>
<span class="img-info">Description:</span>
</div>
<span class="img-info alignright">Delete</span>
</div>
<div class="image-wrapper">
<div id="image-container">
<img src="gallery_traditional_1.jpg" width="200" height="100"><br>
<span class="img-info">Title:</span>
<span class="img-info">Description:</span>
</div>
<span class="img-info alignright">Delete</span>
</div>
</div><!--end container -->
CSS:
#container {
width: 50%;
}
.image-wrapper {
display: inline-block;
width:200px;
padding: 10px;
}
#image-container {
color: #898989;
background:#F9F9F9;
border: solid 1px #ddd;
border-radius:10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
box-shadow: 0px 0px 10px #888;
-moz-box-shadow: 0px 0px 10px #888;
-webkit-box-shadow: 0px 0px 10px #888;
margin:5px auto;
padding:5px;
width:200px;
}
.img-info {
display: block;
}
.alignleft {
clear: both;
float:left;
}
.alignright {
float:right;
margin-top: -29px;
}
First of all, where are you using .alignleft in your code provided?
Secondly, the .alignright span has two classes: img-info and alignright. For img-info you have display-block. This is redundant, as the float property will make an element display-block.
All you need to do is add overflow: hidden to your main div (image-container). The float applied to the link makes it act as though it's not in the same "layer". Adding overflow-hidden will fix this problem. Jsfiddle - http://jsfiddle.net/piedoom/6jTyD/
Try this really quick fix, however, you may want to modify the widths and such:
DEMO: http://jsfiddle.net/4RZJx/
<div id="container">
<div class="image-wrapper">
<div id="image-container">
<img src="gallery_traditional_1.jpg" width="200" height="100"><br>
<div class="info-container">
<div class="alignleft">
<span class="img-info">Title:</span>
<span class="img-info">Description:</span>
</div>
<span class="img-info alignright">Delete
</span>
</div>
</div>
</div>
</div><!--end container -->
CSS:
#container {
width: 50%;
}
.image-wrapper {
display: inline-block;
width:200px;
padding: 10px;
}
#image-container {
color: #898989;
background:#F9F9F9;
border: solid 1px #ddd;
border-radius:10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
box-shadow: 0px 0px 10px #888;
-moz-box-shadow: 0px 0px 10px #888;
-webkit-box-shadow: 0px 0px 10px #888;
margin:5px auto;
padding:5px;
width:200px;
}
.info-container{
overflow: hidden;
}
.img-info {
display: block;
}
.alignleft {
float:left;
}
.alignright {
float:right;
}
Use text-align:
.alignleft {
text-align: left;
}
.alignright {
text-align: right;
}
float is better used for when you want a image to go to the right, and want text to flow around it etc. As it also cause other layout problems, you might as well try text-align.
http://jsfiddle.net/4RZJx/3/