I am creating a website that has 3 images side by side with a bit of space in between.
I have made the images stay in the centre on my laptop but when I view it on another computer with a larger screen, the images move to the left rather than staying in the middle.
My code is as below
HTML:
<img alt="" src="Image/Mathsgames.png" /> </a>
<img alt="" src="Image/informationbooklet.png" /></a>
<img alt="" src="Image/Quizzes.png" /></a>
CSS:
#rotator {
display: inline-block;
margin-left: auto;
margin-right: auto;
height: 200px;
padding: 85px;
text-align: center;
}
Any help would be appreciated. If anybody knows any other way to centre 3 images together with a bit of padding in between that would be appreciated.
You're using the ID #rotator on all of the images. An ID can only be on the page once, so those should be classes instead. You're also closing the <a> tags twice, and no need for the trailing /> on <img> tags in html5.
To center them, since they are inline content, you apply text-align: center; to the parent. I don't see a parent in your code, so I added one called .images
To create space between the images, you can use left/right margin, which I've specified as margin: 0 1em where 1em is the left/right margin, so there will be 2em space between images. Adjust that as you see fit. You could also apply margin to just the center image with .rotator:nth-child(2) { margin: 0 1em; } or give the center image a class and use the class in the selector instead of :nth-child(2)
.images {
text-align: center;
}
.rotator {
display: inline-block;
height: 200px;
padding: 85px;
margin: 0 1em;
}
<div class="images">
<img alt="" src="Image/Mathsgames.png">
<img alt="" src="Image/informationbooklet.png">
<img alt="" src="Image/Quizzes.png">
</div>
They are left aligned, your laptop screen is just too narrow to show it. Wrap them in a container with text-align:center:
.container{
text-align:center;
}
https://jsfiddle.net/58fwtu3c/
Related
I'm trying to learn flex and still a beginner to CSS.
I'm trying to make a flex that shows 4 images next to each other, all images are the same size. When I add an anchor element around the img, it does this weird overlapping instead of changing the image size, I think it's changing the size of the anchor but leaving the images at full size. How can I fix this? also, using scss not css.
HTML:
<div class="row">
<a href="#"
><img src="images/restaurants/logo1.png" alt="Branch 1 logo"
/></a>
<img src="images/icons/menu.png" alt="Menu icon" />
<img src="images/icons/map.png" alt="Map icon" />
<img src="images/icons/call now.png" alt="Call Now" />
</div>
(scss):
.card {
.row {
display: flex;
max-width: 100%;
padding: 0% 0.2rem 0 0.2rem;
padding-top: 0.5rem;
}
.row > * {
width: 23.5%;
flex-basis: 1;
margin: auto;
}
Thanks
add CSS below style in CSS file
img{
width:100%;
}
I am a beginner and trying to to my own wordpress theme from scratch (using bootstrap, stripping away everything and adding my own). Now I have got stuck on an annoying problem.
I have a div containing 3 smaller divs which gonna be menu-items as images. I have gotten the 3 to be horizontally centered in comparison to the outer div but not vertically.
I have set the inner divs to be as high as the outer but im not able to get the inner contents to also be vertically centered.
This is my code:
HTML
#menu {
margin: 0 auto;
width: 60%;
height: 300px;
}
div.menu_item {
display: inline-block;
height: 100%;
}
div.menu_item img {
-webkit-border-radius: 15px;
border: 1px solid #CCC;
border-radius: 15px;
clear: both;
height: 150px;
margin: 4px 15px;
padding: 10px;
width: 150px;
}
<div id="menu">
<div class="menu_item">
<p>
<a title="" href="myimg"><img alt="" src="/myimg.png" width="125" height="125" /></a>
</p>
</div>
<div class="menu_item">
<p>
<a title="" href="myimg"><img alt="" src="/myimg.png" width="125" height="125" </a></p>
</div>
<div class="menu_item">
<p>
<a title="" href="myimg"><img alt="" src="/myimg.png" width="125" height="125" </a></p>
</div>
</div>
Im aware of that this might be very messy and almost certain some things arent needed and could be stripped away but I have tried to figure it out for myself and this is what Ive came to this far.
Screenshots of it is here:
outer div
one of the inner divs
The first shows the outer div, the second shows one of the inner divs.
UPDATE: Solution was fiddling around with flexbox and it was quite easy even for me. Also, I tried to strip away as much as I could from the CSS and still have the same result and apparently almost no code is required.
This is my CSS now
#menu
{
margin:0 auto;
width:60%;
height:300px;
display: flex;
justify-content: center;
align-items: center;
}
This makes the content of #menu to be centered both vertically and horizontally.
This should work:
div.menu_item
{
width: X%; /*change to display: table; if you're targeting IE8 or greater, requires !DOCTYPE */
margin: 0 auto;
...
}
The width just must be less than the outer div, I put X to represent the percentage.
The same can be done with height:
...
height: X%;
...
I'm creating a photo gallery in HTML and adding space between the thumbnails with CSS. The problem I'm running into is that when I go to click on the thumbnail image the "a" tag hyperlink hangs below, above or to the side of the image depending on the margins or padding. How can I get rid of this and have the hyperlink stay within the confines of the thumbnail image only?
HTML
<html>
<head>
<title>Photo Gallery</title>
</head>
<body>
<div class="gallery">
<img src="../images/EastAsia/1.jpg" alt=" ">
<img src="../images/EastAsia/1.jpg" alt=" ">
<img src="../images/EastAsia/1.jpg" alt=" ">
<img src="../images/EastAsia/1.jpg" alt=" ">
</div>
</body>
</html>
CSS
body {
margin: 0 auto;
background-color: #ffffff;
font-family: Arial, Helvetica, sans-serif;
font-size: 1em;
padding: 0;
width: 960px;
}
img {
display: inline-block;
margin: 15px;
width: 150px;
height: 100px;
}
Thanks everyone. I ended up putting each image into a Div class and then set the margin on that class which eliminated the problem!
Add the styles to the a tag:
display:inline-block;
font-size:1px;
See here: http://jsfiddle.net/XRhWe/
The second object from the left.
You can remove the padding from a, and move the margin from the image to a. Since the a wrapps the image, and the image has margin, the a is also wrapped in the margin. If you actually want the margin on the a block, so that clicking it does nothing:
.gallery a { margin: 0; padding: 0; }
img {
display: inline-block;
width: 150px;
height: 100px;
}
I'm using twitter bootstrap 2.1.1 with a responsive layout and I'd like to float a label in the bottom right hand corner of the image. One of the problems i'm having is because it's responsive when the thumbnail is wider then the image it floats too far. The other issue is I can't seem to get it to float to the right. I should also add that although I want it in the right hand bottom corner I do want it offset by a few pixels to it isn't right on the edge of the image. Also the text might always be photo missing, that is just when a default image is shown.
Here is my html so far
<li class="span4">
<div class="photo-group thumbnail">
<a href="/recipes/50500235aa113eb1870001d8" class="photo-wrapper">
<img alt="300x200&text=photo" src="http://www.placehold.it/300x200&text=Photo">
<span class="label label-inverse photo-label">Photo Missing</span>
</a>
<div class="caption">
<div class="pull-right">
by <a href="/users/50494983aa113ebd5c000001">
hadees
</a>
</div>
Chocolate Crackle Cookies
</div>
</div>
</li>
and here is my css
.content-header {
padding-bottom: 10px;
}
.thumbnail > a > img {
display: block;
margin-left: auto;
margin-right: auto;
max-width: 100%;
}
.photo-group .photo-wrapper {
position: relative;
}
.photo-group .photo-wrapper .photo-label {
position: absolute;
bottom: 0;
}
.photo-group .photo-wrapper .photo-label {
float: right;
}
I've also got a jsfiddle for a better example.
Maybe the right way to handle this is to just make the photogroup's max width 300 but I think that kind of looks funny on a desktop full screen.
Here's my version of the fiddle: http://jsfiddle.net/AdVCT/9/
Essentially, you need to put a wrapper around both the image and the label, so that you can absolutely position the label within this wrapper:
<div class="photo">
<img alt="..." src="..." />
<span class="label label-inverse photo-label">Photo Missing</span>
</div>
And then with some CSS, you can alter the .photo to be centered but also only as large as the image inside it (the caption is absolutely positioned, so it is effectively taken out of the page flow and doesn't affect width of parents etc.):
.photo-group .photo-wrapper .photo {
position: relative;
margin: 0 auto;
display: table;
}
And remove margin-left: auto/margin-right: auto from the .thumbnail > a > img rule. Finally, to offset the label slightly from the sides of the image, use:
.photo-group .photo-wrapper .photo-label {
position: absolute;
bottom: 5px;
right: 5px;
}
And set 5px to whatever you want the offsets to be.
I've got 2 divs on top of another div, but when I resize the window they stay put, instead of moving with the div behind them. I thought that if there position is relative they move along with the previous div, but it doesn't seem to work like this. What am I missing?
CSS and HTML below, simplified.
<div class="wrapper" style="margin: 0 auto; text-align: center;">
<div id="0">
<img src="0.gif" width="960px" alt="" />
<div class="top">
<div id="tag" ><img src="tag.png" alt="" /></div>
<div id="tag2"><img src="5500.png" alt="" /></div>
</div>
</div>
</div>
And CSS like this:
#0 {
clear: right;
z-index: 0;
}
.top {
float: left;
z-index: 1;
clear: left;
position: relative;
}
#tag {
margin-top: -500px;
margin-left: -600px;
}
#tag2{
margin-left: 750px;
}
It seems like you're expecting the top div, with its associated tag divs, to move with the 0.gif image when you resize the page. Instead, it's moving relative to the left edge of the wrapper div, which is pegged to the left-hand side of the screen. You will probably get the result you want by adding width: 960px to the style of your .wrapper div.
For further enlightenment, check the bounding boxes on each of your divs. You may find that a temporary border: 2px solid green style helps clear things up.