I have six of my portfolio images (of kittens). How do I stack six of them on top of the lake wallpaper? I don't want there to be any white space, just the word "Portfolio" and six kittens on top of the lake, followed by the grey background section of the website.
Portfolio - How do I make six kitten photos on top of the lake img?
About - Grey background with white font and profile pic (Already done)
Contact - Contact form (Already done)
I've read about z-index, and tried background-size: cover and contain, but it doesn't seem to work... Can anyone explain all this to me?
HTML
<header id="portfolio" class="container-fluid">
<div class="container">
<h1 class="font-italic">Portfolio</h1>
<div class="row">
<div class="col-md-4">
<img src="http://placekitten.com/350/300" alt="Porfolio1" class="img-thumbnail">
</div>
<div class="col-md-4">
<img src="http://placekitten.com/350/300" alt="Porfolio2" class="img-thumbnail>
</div>
<div class="col-md-4">
<img src="http://placekitten.com/350/300" alt="Porfolio3" class="img-thumbnail">
</div>
</div>
<div class="row portfolio-buffer">
<div class="col-md-4">
<img src="http://placekitten.com/350/300" alt="Porfolio4" class="img-thumbnail">
</div>
<div class="col-md-4">
<img src="http://placekitten.com/350/300" alt="Porfolio5" class="img-thumbnail">
</div>
<div class="col-md-4">
<img src="http://placekitten.com/350/300" alt="Porfolio6" class="img-thumbnail">
</div>
</div>
</div>
</header>
CSS
.portfolio-buffer {
margin-top: 30px;
}
section {
padding: 85px 0;
}
footer {
padding: 40px 0;
}
#portfolio > img {
margin-left: -15px; /* Compensate for the container */
width: calc(100% + 30px); /* Compensate for the container */
}
https://codepen.io/jenlky/pen/GMENBL/
You have numerous problems with your fiddle:
Your .wallpaper selector doesn't actually have a matching element; you have no element with a class of wallpaper.
You are using Boostrap's container-fluid, but not using a column-based layout. Your elements in this container that are not in Bootstrap rows (such as this background) need to have margin-left and margin-right of -15px to accommodate for Boostrap.
You have rows that have combined columns counts other than 12.
Most elements overflow their container.
As for the background not working with background-size, that is because background-size requires a background to operate, added via a CSS property like background: url(background.jpg). You are simply using an <img> tag.
Having said that, all you need to do is make sure that your image has a max-width of 100%, to ensure that it stays within the bounds. You'll probably also want to make it fixed to the page, which can be done with position: fixed.
I've created a new selector based on your current structure, and added the relevant properties:
#portfolio > img {
margin-left: -15px; /* Compensate for the container */
margin-right: -15px; /* Compensate for the container */
max-width: 100%;
position: fixed; /* Optional */
}
This can be seen working here.
Note that you'll probably want to add max-width: 100%; and max-height: 100%; to all images, to ensure that they don't go outside of their container.
Update
In order to have the background only cover the portfolio section, you'll want to remove position: fixed (to give it the default position relative). You'll still want to keep the negative left margin, but you'll want to make it 100% of the width of the container plus 30 pixels in order to compensate for the padding and offset. That can be done with a CSS calculation:
#portfolio > img {
margin-left: -15px; /* Compensate for the container */
width: calc(100% + 30px); /* Compensate for the container */
}
I've created a new pen showcasing this here.
And again, note that you'll probably want to set a max-width of 100% on all images, and you should set margin-left (and technically margin-right) on all elements that are directly under a Bootstrap column. For example, the cats can be fixed with:
.col-md-4 > img.img-absolute {
margin-left: -15px;
margin-right: -15px;
max-width: 100%;
}
Hope this helps! :)
Ok thanks to Obsidian Age for giving me the idea of using background-image instead of img src="...". So I removed img src and added this in:
header {
background-image: url("https://wallpaperscraft.com/image/forest_lake_reflection_island_mist_97668_1920x1080.jpg");
padding: 85px 0;
background-repeat: no-repeat;
}
That works and solved the problem I had. I've updated in my codepen (https://codepen.io/jenlky/pen/GMENBL/). Cheers!
Related
I'm trying to position two images on top of each other with some level of precison.
The problem is, the top image (the circle) goes all over the place.
Both images are in a responsive grid and the base image is supposed to be centered all the time.
Let's say that, for example, I'm trying to target the hip.
Whenever I shrink the page, the right image goes below (which is exactly what I want), while the circle goes somewhere else (in this case, the hand).
Here's my code:
/* No-margins Class Rules */
.row.no-gutters {
margin-right: 0;
margin-left: 0;
}
.row.no-gutters>[class^="col-"],
.row.no-gutters>[class*=" col-"] {
padding-right: 0;
padding-left: 0;
}
/* Centers content */
.centered-img {
display: flex;
align-items: center;
justify-content: center;
min-width: 100px;
}
.img-container {
background-color: yellow;
position: relative;
width: 100%;
height: 100%;
display: flex;
}
.test {
position: absolute;
transform: translate(-50%, -50%);
left: 100px;
}
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
</head>
<body>
<div class="container">
<!-- global canvas -->
<div class="row no-gutters">
<div class="col-sm">
<div class="centered-img">
<img src="./images/fssFront.png" class="img-fluid" alt="Responsive image">
<img src="./images/circle.png" class="test" alt="Responsive image">
</div>
</div>
<div class="col-sm">
<div class="centered-img">
<img src="./images/fssBack.png" class="img-fluid" alt="Responsive image">
</div>
</div>
</div>
</div>
<!-- global canvas -->
</body>
</html>
How can I position the red circle on top of the man so it always stays on the same place whenever I stretch or shrink the page?
Thank you very much in advance.
I'm guessing that your two images are using different reference points to determine their location. Additionally, for it to be responsive you need everything in percentages.
The first part. By setting position:absolute on your circle, you're changing it's reference point to the next container up that has position:relative or position:absolute set on it. In your case there are none, so it's using the page, the entire document, as its reference point. If the circle has a reference point of the page, and the image has a reference point of its parent, when you resize, they are going to anchor to different points and you'll never get them lined up.
Additionally, since you want it to be responsive, all of your measurements will need to be in %. left:100px is set on your circle, which won't work when you start to resize. You need to either get the exact location with the transform property, or change your left property to a percentage.
I am having trouble with a few of my images. The Problem originally occurred when I resized my browser and my logo would be half cut, so you could only see half of it. Of course, it was frustratingly simple. I just had to remove margin-left{ negative value; } Now I am having problems moving my content a few pixels to the left without using the above. I could put it on JS fiddle, but I don't think that would help since the images won't show up. I also don't want to use any positioning. I want to keep it in normal flow.
Any help appreciated!
<div id="rainbow">
<img src="images/rainbow.png" alt="rainbow gradient">
</div>
<div id="header">
<p id="logo"><img src="images/logo.png" alt="Bethan Rainforth a comedic dancer" >
</p>
</div>
<div class="danceleft">
<img src="images/danceleft.png" alt="dancer to the left kicking">
</div>
I still have margin-left as you can see but plan on deleting it once I can figure out how to move the image to the left
#rainbow img {
width: 149.2%;
margin-left: -190px;
margin-right: 20%;
}
#logo img {
width: 320px;
margin-top: -60px;
}
div.danceleft img {
width: 20%;
margin-bottom: -56%;
}
for img display inline
text-align:left
for general
float:left
position:relative, absolute, fixed
padding-left
I would recommend using
position: relative;
left: -XXpx;
This will move the image to the left relative to the original position of the image.
I am trying to have 3 images aligned in one block. They have to stay in the same sized container and fit horizontally.
Here's the code:
<div class="container">
<img src="http://images2.webydo.com/31/313624/3958/21b785db-14ea-42f7-af0d-7e7a8d8019d9.jpg" />
<img src="http://images2.webydo.com/31/313624/3958/9657ddfd-81e8-4154-bc61-bbe30e4a8740.jpg" />
<img src="http://images2.webydo.com/31/313624/3958/909af36d-b941-4a20-9441-20505c035da3.jpg"/>
</div>
.container {
width: 300px;
height: 200px;
position:relative;
float: left;
text-align: center;
}
.container img {
width: 100%;
height: auto;
margin: 5px;
}
In my CSS solution, I divided the "container" class width by 3 (300px /3) and then subtracted 10px (which i got from padding-left and padding-right of each image). So a single image should have a width of 90px. However, I also wanted to subtract 5px more for browser spacing so the total width of each image should be 85px. Here is the code:
<html>
<head>
<style>
.container {
width: 300px;
height: 200px;
position:relative;
float: left;
text-align: center;
}
.container img {
width: 85px;
height: auto;
margin: 5px;
}
</style>
</head>
<body>
<div class="container">
<img src="http://images2.webydo.com/31/313624/3958/21b785db-14ea-42f7-af0d-7e7a8d8019d9.jpg" />
<img src="http://images2.webydo.com/31/313624/3958/9657ddfd-81e8-4154-bc61-bbe30e4a8740.jpg" />
<img src="http://images2.webydo.com/31/313624/3958/909af36d-b941-4a20-9441-20505c035da3.jpg"/>
</div>
</body>
</html>
Hm...I don't think you can have all three images in a horizontal line if you give them all a width:100%. That property would cause each image to take the full width of the container, meaning each image would be pushed to the next line.
You'll have to give the images a smaller width to fit them all on one line. 100% / 3 = 33.3% (rounded), so use that instead. Here's some modified CSS for .container img that seems to work:
.container img {
width: 33.3%;
height: auto;
padding:5px;
box-sizing:border-box;
-moz-box-sizing:border-box;
}
Note that in addition to changing the images' widths, I also changed the margin to padding, and made use of the box-sizing attribute (read more about it here). This lets you keep that same spacing of 5px around images, without bumping any images onto a second line.
Also, the HTML needs to be altered slightly. In this case, we're taking advantage of the <img> element's default display:inline-block to have them all display on the same line. However, any whitespace in between this kind of element will result in a space between the images, so that needs to be eliminated:
<div class="container">
<img src="http://images2.webydo.com/31/313624/3958/21b785db-14ea-42f7-af0d-7e7a8d8019d9.jpg" /><img src="http://images2.webydo.com/31/313624/3958/9657ddfd-81e8-4154-bc61-bbe30e4a8740.jpg" /><img src="http://images2.webydo.com/31/313624/3958/909af36d-b941-4a20-9441-20505c035da3.jpg"/>
</div>
If you don't understand what I mean by that, try formatting each <img> element onto its own line in the HTML, and see how that affects their positioning.
Here's a JSFiddle so you can see what this achieves. Let me know if you have any questions, and I'll be happy to help further!
EDIT: Alternatively, if you really want to keep the whitespace between your <img> elements in your HTML, you could compensate for the unwanted extra space with a negative margin. Just add margin-right:-4px; to your styles for .container img. Updated JSFiddle to show what this results in.
I am new to Bootstrap, responsive web design, and am trying to create a page for my band but I am running into a few issues. I will try to explain as best as I can my situation and I greatly appreciate any and all help...
I have a div that has a background image of the band and I need it centered in the screen (regardless of the size of the screen) inside of one of Bootstrap's container DIV's. On top of that image, I have another image that I want to include. I am able to get that result so far. The problem I am running into is when I try to position the child DIV inside of the parent DIV. I have tried to set the parent DIV with a position: relative and the child DIV with a position: absolute, but as I begin to resize the screen, the inside image suddenly enlargens and stretches outside of the parent DIV. Also, when using this method and trying to position the child DIV 75% from the top of the parent DIV by using top: 75%;, it makes the image jump out of the parent again and puts it down at the bottom of the screen.
Here is the code that I have used so far but cannot get to work. Again, any help at all would be greatly appreciated as I am new to Bootstrap and responsive design but I would love to figure this stuff out. Thanks in advance!
MY HTML:
<div class="container">
<div class="row">
<div class="col-md-12 bandphoto">
<div class="row">
<div class="col-md-6 col-md-offset-3 theband-title">
<img src="images/theband.png" class="img-responsive ">
</div>
</div>
</div>
</div>
MY CSS:
.bandphoto {
position: relative;
max-width: 2000px;
min-height: 999px;
background: url(images/bandphoto.png);
background-size: 100%;
background-repeat: no-repeat;
}
.theband-title {
position: absolute;
top: 75%;
}
http://jsfiddle.net/isherwood/w3mgQ
Am I doing something wrong here? If so, please advise with and feel free to educate me as well so that I can better understand this stuff.
I think you want to avoid using absolute positioning (because it's very difficult to keep centered), and don't try to force Bootstrap elements when they're not needed. It's not clear to me how you want to position the inner image because I have no size reference, but maybe this gets you closer:
http://jsfiddle.net/isherwood/w3mgQ/3/
.bandphoto {
position: relative;
max-width: 2000px;
min-height: 999px;
background: url(http://placehold.it/600x600/333333);
background-size: 100%;
background-repeat: no-repeat;
}
.theband-title {
margin: 0 auto 0;
}
<div class="container">
<div class="row">
<div class="col-md-12 bandphoto">
<img src="http://placehold.it/500x500" class="theband-title img-responsive" />
</div>
</div>
</div>
I believe what you're looking for is display:table and his friends. Here's a JSFiddle demonstrating:
http://jsfiddle.net/VcFf9/4/
I've set the container to be 100% height, and then vertically aligned the background and the content of the cell. Bootstrap's grid lends itself quite well to display:table, so try it out! :D
I'm making a responsive web design. But my CSS knowledge could have been better. I want a padding on a div, but I don't want it to affect the title.
See this example:
I want the title to be were it is, but the little squares to have a margin at the left side.
I've tried to set a padding and then reset the title position with relative positioning. But I don't like that solution because the title is pushing the squares more than necessary.
I've also tried to set a div where the cross is, but I can't manage to get it under the title and on the left side of all squares since the title is floated left and the squares right.
Here is a fiddle
HTML
<div id="siteContainer">
<div id="titleContainer">
<h1 id="title">This is the long title</h1>
</div>
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
// more...
</div>
CSS
#siteContainer {
max-width: 800px;
margin: auto;
}
#title {
display: inline-block;
}
#titleContainer {
height: 100px;
margin: 10px;
float: left;
}
.image {
width: 100px;
height: 100px;
margin: 10px;
background: #DDCCAA;
float: right;
}
Whatever you want the padding on the left of the container to be (100px), you can set as a negative text-indent value on the title (-100px).
Did you think about the box model? Do some research on CSS box model and you will see where your problem is.
Let me give you an example:
If you have a div with the width of 100px and add a padding of 10px, the width of your div will be 120px, both sides will take 10px from the padding, you can solve this in two ways, one is to make the div width smaller "80px" and the second is to use box-sizing: border-box;
Hope this helped.