I'm a beginner and I tried to make one page by myself, however, the result is not good. I will try to explain what I need: Full-screen page with two images, one image will cover 50% of horizontal space of browser window, and second image will be on right side covering the rest of this page. I need both images to be responsive and to always keep 100% height. When the window is resized, left and right sides of both images will be cropped.
Very similar to this: http://www.gt3themes.com/website-templates/soho/striped_landing.html
Is this difficult to make? I tried to follow some guides on the web, but the result was that my images were stretched and not cropped. Maybe I am completely wrong and I need to create two columns and then put images inside?
I will appreciate any help.
My current code is:
.photo{
size: 100%;
position: relative;
overflow: hidden;
}
.photo img{
max-width: 50%;
height: 100%;
}
The site you linked more or less did something like this:
http://jsfiddle.net/xnLn6s5o/
HTML
<div id="container">
<div id="left" class="halfwidthcontainer">
<div id="left-image" class="image"></div>
</div>
<div id="right" class="halfwidthcontainer">
<div id="right-image" class="image"></div>
</div>
</div>
CSS
html, body, #container, #left, #right, #left-image, #right-image {
height:100%;
}
.halfwidthcontainer {
float: left;
width: 50%;
}
.image {
background-size: container;
background-repeat: no-repeat;
background-position: 50% 50%;
}
#left-image {
background-color: red;
background-image: url('');
}
#right-image {
background-color: blue;
background-image: url('');
}
The general idea is that two containers sit side by side, floated (see this answer as why to use floats to position containers side by side instead of inline-block).
The idea thereafter is to explot the CSS background property which will allow you to get the overflow/positioning effects you want. You can read more about that here.
You're going to want to fill in the background-image properties of the #left-image and #right-image IDs to add the images you want.
Related
I have code something like this:
<div class='image-holder' style='width:128px; height:128px'>
<img class='thumbnail' src='image1.png'>
</div>
The actual size of .thumbnail is unknown, and can potentially be not an exact square.
So what I am trying to do is not change the dimensions of the image (.thumbnail) at all, but instead show just the center (both horizontally and vertically) of the image inside the .image-holder element.
For example, if the image (.thumbnail) was 256x256, the inner 128x128 section of the image should appear inside .image-holder.
I am open to using an actual img element, or, using background-image for the div. I have experimented with both with no success.
I am fairly certain I can write some javascript to do the work if necessary, but I was looking to see if there is a pure CSS solution before I go down that road.
You should use background-image for this. Just remove the default repeating from it, and set the background-position: center;
See it here:
.image-holder {
width:128px;
height:128px;
border: 1px solid red;
margin: 10px;
background-repeat: no-repeat;
background-position: center;
}
#holder-1 {
background-image: url('http://via.placeholder.com/350x150');
}
#holder-2 {
background-image: url('http://via.placeholder.com/100x100');
}
<div id="holder-1" class='image-holder'></div>
<div id="holder-2" class='image-holder'></div>
So I want to decrease the size of the img on the header so it looks cleaner and a more sharp img , however i am unsure how to do it?
Here is the code
CSS:
.header {
background: #000000 url (C:/website/logo final.svg) no-repeat;
background-size: 80px 60px;
}
HTML:
<header>
<div id="header" align="center">
<img name="Antique Picture" src="C:\website\logo.jpg
" alt="logo" width="100%" height="100%">
</header>
all help would be rly appreciated thankyou
I'm going to tackle this one. As Michael Coker said, there are a number of flaws that need fixing in your HTML structure:
1) The align attribute is deprecated. We'll cover that with CSS.
2) Image widths must either be pixel-based, or covered in CSS.
3) The header div isn't closed.
4) You provided local images, so we can't access them, meaning we can't check if they're blurry.
Additionally, the img tag has no attribute name, and the background-image URL must have no space and quotes around the file path. I'll ignore the fact that it's bad practise to have a space in the filename, as it will work with the space.
Fixing up those problems, your new structure looks like this:
HTML
<header>
<div id="header">
<img src="C:\website\logo.jpg" alt="logo">
</div>
</header>
CSS
.header {
background: #000000 url('C:/website/logo final.svg') no-repeat;
background-size: 80px 60px;
}
To centralise the header, you need to add text-align: center to it in the CSS:
.header {
background: #000000 url('C:/website/logo final.svg') no-repeat;
background-size: 80px 60px;
text-align: center;
}
To adjust the image widths properly, you should use CSS for this as well:
.header img {
width: 100%;
height: 100%;
}
Keep in mind that percentage-based widths are relative to the parent element. The header parent element will need a height and width in order for the image child to adapt. If you'd prefer a fixed image width, these values should be specified in pixels:
.header img {
width: 100px;
height: 100px;
}
Then if you find it is stretched, you can adjust the pixel values above (or the image itself, if that is easier).
Hope this helps!
I try to use two repeat background image in x direction for my div.But i can't.How can i use two repeat image in X direction in my div(i.e,i need to divide my singe div into two equal parts.For my first part i need to use my first image with background repeat-x and then rest part should be fill with my second image in repeat-x direction).Please help me
Without your code can't really know what your going for but I would do this:
<div class="outer_div">
<div class="left_half"></div>
<div class="right_half"></div>
</div>
<style>
.outer_div{
width: 500px; /*or whatever you need the width to be */
}
.left_half{
background-image: url("your image here") repeat-x;
width: 50%;
float:left;
}
.right_half{
background-image:url("your image here") repeat-x;
width: 50%;
float:right;
}
</style>
You will need to use CSS3 for multiple backgrounds for a single div.
HTML:
<div class="backgrounds"></div>
CSS:
.backgrounds {
background: url(http://userlogos.org/files/logos/pek/stackoverflow2.png),
url(http://www.gravatar.com/avatar/3807b3e7ad69d363d4490540c663af5f?s=128&d=identicon&r=PG);
background-repeat: no-repeat, repeat;
background-position: center, left;
width: 700px;
height: 300px;
}
jsFiddle DEMO: Multiple Background For Single Div
EDIT: Revised jsFiddle for repeat-x Read more about CSS3 multiple-backgrounds HERE.
as an excercise i decided to delve in to css layout styling and am already failing to see why my layout is not aligning correctly. also why is the container div only appearing when there some text in there. i thought it would display and grow based on the background property in css statement. i have done screengrab to show problem. can someone show my error. thanks
screen grab: http://imageshack.us/photo/my-images/21/containergrabnew.png/
css
#container {
width: 800px;
margin: 0 auto;
background-image: url(../images/container-bg.gif);
background-position: center center;
background-repeat: repeat-y;
}
#containerLeft {
width: 475px;
float:left;
background-image: url(../images/container-left-bg.gif);
background-position: center center;
background-repeat: repeat-y;
}
#containerRight {
width: 300px;
float:right;
background-image: url(../images/container-right-bg.gif);
background-position: center center;
background-repeat: repeat-y;
}
html
<div id="container">
This is the container
<div id="containerLeft">
This is the left container
<div id="containerRight">
This is the right container
</div></div>
</div>
am already failing to see why my
layout is not aligning correctly
Your HTML is not nested correctly. Change it to this:
<div id="container">
<div id="containerLeft">
This is the left container
</div>
<div id="containerRight">
This is the right container
</div>
</div>
also why is the container div only
appearing when there some text in
there. i thought it would display and
grow based on the background property
in css statement.
You need to clear your floated elements.
You can do this by adding overflow: hidden to #container.
You should read this article for more information: http://css-tricks.com/all-about-floats/
It discusses why this happens, various ways to fix it, and includes useful and relevant information about floats in general.
I have the following HTML and CSS:
<div class="content">
<div class="leftbg"></div>
<div class="innercontent"><p>Some content goes here</p></div>
<div class="rightbg"></div>
</div>
.content {
overflow: hidden;
}
.leftbg {
background: url("./leftbg.png") repeat-y scroll top left transparent;
margin-left: 0;
float: left;
width: 10px;
}
.innercontent {
width: 600px;
float: left;
margin-left: 0;
}
.rightbg { /* similar to left bg except for the right side */ }
The problem that I am having is the leftbg image is only repeating until it reaches the height of the paragraph in the innercontent div. I am accessing a database to grab the content for the innercontent div and hence the content will be of variable height. Is there any way to make it so that it repeats until it reaches the bottom of the leftbg (and rightbg) div? What I mean by that is for it to repeat until it is at the bottom of the innercontent div without setting the height as static (e.g. height: 200px;) because the height will be variable.
This equal height column layout tutorial from smashing magazine might help you. With lot of explanation of all the whys.
I think the problem you are facing is that leftbg and rightbg don't have any content. The height of the <div class="content"> element equals the height of it's "tallest" child (innercontent in this case).
Maybe if you post a mockup of what you want as a final result I can help you further. Also, the markup would be helpful.