How to make images go inline vs break to a new line? - html

http://jsfiddle.net/KuFbH/
I am trying to get these 4 images to all be displayed in one line without breaking to the next line. For some reason I can't get it to work although if I zoom out on the page it appears exactly how I want it. What can I do?
I want to be able to scroll horizontally to view them.
HTML
<div id="main">
<div id="scroll">
<div class="Wrapper">
<div class="scrollArea">
<img src="">
<img src="">
<img src="">
<img src="">
</div>
</div>
</div>
</div>
CSS
*{
font-size:100%;
margin: 0px;
padding: 0px;
}
body{
width: 100%;
height: 100%;
}
#main{
position: absolute;
top:100px;
bottom:100px;
left:0;
width: 100%;
background: black;
}
#scroll{
position: relative;
width: 100%;
height: 100%;
}
div.Wrapper{
position: relative;
overflow: auto;
width: 100%;
height: 100%;
}
div.scrollArea{
position: relative;
width: auto;
height: 100%;
}
.scrollArea img{
max-width: 100%;
max-height: 100%;
}
Jquery
var totalWidth = 0;
$('.scrollArea img').each(function(){
totalWidth += parseInt($(this).width(), 10);
});
$('.scrollArea').css("width", totalWidth);

Your images wrap because that's the default behavior for inline elements. If you don't want them to wrap, specify the appropriate behavior on the parent element:
.scrollArea {
white-space: nowrap;
}

try this:
.Wrapper {white-space:nowrap;}
demo here:
http://jsfiddle.net/FEb9L/

Set your image to display: inline-block; in your css stylesheet.

Related

how to set image height to be equal to window's height in CSS

https://codepen.io/Krimlen/pen/zwBmjV
how to make the two images' height equal to the window and the width to automatically adjust wth height? I've really searched a lot and I can't find the answer.
<body>
<div id="container">
<img src="https://s-media-cache-ak0.pinimg.com/originals/36/ef/af/36efafe91fddde518cba85e974c7e8c8.jpg" class="home" alt="Makeup Artists"
class="home"/><img src="https://s-media-cache-ak0.pinimg.com/originals/36/ef/af/36efafe91fddde518cba85e974c7e8c8.jpg" alt="Photographers" class="home"/>
</div>
<img src="images/logo.png" alt="Satch" id="logo"/>
</body>
<style>
html, body{
margin: 0;
padding: 0;
}
#container{
text-align: center;
}
</style>
Remove src=".." from <img> and apply it in css
img.home {
background-image: url('https://s-media-cache-ak0.pinimg.com/originals/36/ef/af/36efafe91fddde518cba85e974c7e8c8.jpg');
background-size: 100% 100%;
position: absolute;
}
You can use viewport height but you will also need to display it as flex. See the example below
img {
height: 100vh;
display: flex;
flex-direction: row;
}
That should work, you may also want to add z-index to your container so the image is behind it. Like this.
#container {
text-align: center;
position: relative;
z-index: 100;
}
img {
height: 100vh;
display: flex;
flex-direction: row;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 0;
}
Please try the following:
html, body {
height: 100%;
}
.img_wrap {
height: 100%;
text-align: center;
}
.img_wrap img {
width: auto;
height: auto;
max-height: 100%;
}
<div class="img_wrap">
<img src="https://s-media-cache-ak0.pinimg.com/originals/36/ef/af/36efafe91fddde518cba85e974c7e8c8.jpg" class="home" alt="Makeup Artists"
class="home"/><img src="https://s-media-cache-ak0.pinimg.com/originals/36/ef/af/36efafe91fddde518cba85e974c7e8c8.jpg" alt="Photographers" class="home"/>
</div>
<div id="container"><img src="https://s-media-cache-ak0.pinimg.com/originals/36/ef/af/36efafe91fddde518cba85e974c7e8c8.jpg" alt="Photographers" class="home"/>
</div>
<img src="images/logo.png" alt="Satch" id="logo"/>
The only way i know how it works is
img { height:100% }
or
img { height:100%; width:auto; }
let me know if this helped.

Getting text over a image

Have created a full screen image, that is filling the full site when you enter my website. But I can't make text over the image so that I can have a read more button and a welcome to name.
This is my code:
<div class="row">
<div class="col-md-12-">
<img class="img-responsive" style="min-height: 100%; min-width: 1024px; width: 100%; height: auto; position: fixed; top: 0; left: 0; " src="~/Content/img/maxresdefault%20(1).jpg" />
</div>
</div>
Any suggestions on how I add text over an image?
It needs to look like this:
There are a few ways:
div with text inside and style="background: url('my_img.png');".
a div with 'position: absolute; z-index: -1;' behind it that contains the img or background img.
Just add position property value of absolute, and a positive z-index property value to the text container only. See the example below and adjust as needed.
.row {
position: relative;
width: 100%;
height: 200px;
overflow: hidden;
}
.col-md-12 {
width: 100%;
height: 100%;
}
.col-md-12 img {
width: 100%;
height: auto;
}
.text {
position: absolute; /* Make stack-ability possible */
z-index: 3;
top: 100px;
left: 50px;
color: white;
font-size: 36px;
font-weight: bold;
background: black;
opacity: 0.70;
padding: 10px;
;
<div class="row">
<div class="col-md-12">
<img src="http://i.stack.imgur.com/xvCoo.jpg">
</div>
<div class="text"> Whatever your text is goes here </div>
<div>
There are a couple of ways to do it, the second option IMO is the simplest.
Positioned absolute
Offset from top with margin and center aligned button/content
http://codepen.io/anon/pen/jbBVeB
body{
background: url(http://placehold.it/1600x900);
}
.welcome{
margin-top: 50px;
text-align: center;
}
with the background-image method your CSS code would be:
body{
background-image: url('~/Content/img/maxresdefault%20(1).jpg');
background-position: center;
background-attachment: fixed;
}
put that on CSS and you're done!

css align footer bottom without using position:absolute

I have a website made of "pages" (100% height on visible area). Please look at the following css:
html {
height: 100%;
}
body{
height:100%;
margin: 0 auto;
}
.page{
height: 100%;
margin: 0 auto;
min-height: 700px;
min-width: 1024px;
}
.content {
margin: 0 auto;
text-align: center;
height: 100%;
min-height: 800px;
min-width: 1024px;
}
.footer {
width: 100%;
min-height: 200px;
background-color:red;
}
.hidden{
width: 100%;
height: 500px;
background-color:blue;
}
.image {
display:block;
height: 100px;
width: 100px;
}
And this is the code:
<div class="page">
<div class="content">
<img class="image" src="img/image.png1">
<img class="image" src="img/image.png2">
<img class="image" src="img/image.png3">
<div class="hidden" style="visibility:hidden">
</div>
</div>
<div class="footer">
</div>
</div>
I need:
1) the footer to be aligned bottom when the page loads
2) after some seconds, with javascript I show the hidden div, and the footer must slide down.
I can't obtain these two things at the same time, because I can obtain 1) with
footer {
position: absolute;
bottom: 0;
}
but in this way when I show the hidden div it overlaps the footer.
Otherwise if I remove this last code, when the hidden div appears the footer slides down correctly, but when I load the page the footer is not at the bottom.
Does someone have any advice?
How about;
position: relative;
bottom: -100%;
What worked for me is the following code:
.footer {
width: 100%;
min-height: 200px;
background-color:red;
margin-top: 100vp;
}
The thing is that the footer is not seen until the user scrolls, you could
give it a less than a 100vp margin-top but it depends on the footer height which can change.
NOTE: vp means viewport height
You should try with this code:
html {
position: relative;
min-height: 100%;
}
footer {
position: absolute;
left: 0;
bottom: 0;
height: 100px;
width: 100%;
}

How do I center my logo image to another div in CSS horizontally and vertically?

I need help positioning a logo horizontally center. It also needs to be centered vertically to the top of my links div. Can someone help me?
I'd like my logo to look like this:
Below is my HTML and CSS:
HTML - http://codebin.org/view/199faa14
<div id="container">
<div id="logo">
<img src="images/images/logo.gif" />
</div>
<div id="navigation">
navigation
</div>
<div id="header">
</div>
<div id="line">
</div>
<div id="content">
content
</div>
</div>
CSS - http://codebin.org/view/dda88d94
body {
background: url(../images/images/bg_page.gif) center center;
}
#container {
width: 940px;
margin: 0 auto;
}
#header {
height: 281px;
background: url(../images/home/header.gif) top center;
position: relative;
}
#logo {
position: absolute;
z-index: 2;
top: 0px
height: 214px;
margin: 10px auto 0 auto;
}
#navigation {
position: relative;
height: 40px;
background: #fff;
margin-top: 100px
}
#content {
height: 541px;
background: url(../images/home/bg_body.png) top center;
position: relative;
}
#line {
height: 4px;
background: url(../images/home/line.gif) top center;
position: relative;
}
try something like this before using javascript!
.center {
width: 300px;
height: 300px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -150px;
}
or this!
.image_container {
width: 300px;
height: 300px;
background: #eee;
text-align: center;
line-height: 300px;
}
.image_container img {
vertical-align: middle;
}
I think I understand your question. Since you are calling out your logo img in the html, try this.
<div id="logo">
<img src="images/images/logo.gif" alt="logo" align="center"/>
</div>
You could achieve this with:
display:inline-block;
line-height;
negative margin
text-align:justify (you have 5 items 4 links & 1 img in middle)
:after
Demo made in a similar context for someone else :
http://dabblet.com/gist/5375725
Some people will facing some problems while using the vertical-align: middle; styling attribute. CSS needs to be written in the prober way. For people looking for a quick fix.
.logo { left:0; top:0; height:100%; width:100px; }
<div class="logo" style="background:url('/assets/images/site-logo.png') center center no-repeat;">
<img src="/site/logo.png" style="display:none;" />
</div>
*make sure the container has the position:relative; css attribute.
It's easy handeling retina and compatible with all kind of CSS markups. hope this simple technique can save some time for people :)

how to center absolute positioned <img> in <div> but keep original aspect ratio

I have this image, with this CSS:
.containerImg {
height: 420px;
margin-top: 0;
position: relative;
width: 100%;
}
.img {
margin: 0 auto;
position: absolute; /*unfortunately i can’t remove the position:absolute*/
}
And the markup:
<div class="containerImg">
<img class="img" alt="" src="img//section_es_2442.jpg">
<div class="info">
…
</div>
<div class="clear"></div>
</div>
And I post it so you can see that the img is not the only thing in the .container
So behavior is that image should use all .container dimensions and crop de image but keep the original ratio, images are 1600x500 (3,2:1)
So, how can i achieve this?
If I were you, I would to use background-image instead of img using this code:
.containerImg {
height: 420px;
margin-top: 0;
position: relative;
width: 100%;
}
.img {
margin: 0;
/*position: absolute; I'll remove this */
height: 420px;
width: 100%; /*or use pixels*/
background: transparent url('') no-repeat center top;
overflow: hidden; /* not sure about you really need this */
}
with :
<div class="containerImg">
<div class="img" style="background-image: url('img/section_es_2442.jpg')"></div>
<div class="info">
…
</div>
<div class="clear"></div>
</div>
The idea is you have a div like view port, and the image with same ratio and size will be background, if the image is bigger, the additional size will "like" cropped :)
.containerImg {
width: 120px;
height: 120px;
position: relative;
overflow: hidden;
}
.cutImg {
position: absolute;
max-width: 120px;
width: expression(this.width > 120 ? "120px" : true);
max-height: 120px;
height: expression(this.height > 120 ? "120px" : true);
}
jQuery(window).load(function(){
jQuery.each($(".cutImg"), function() {
$(this).css("margin-left",(($(".containerImg").width()-$(this).width())/2));
$(this).css("margin-top",(($(".containerImg").height()-$(this).height())/2));
});
});
<div class="containerImg"><img class="cutImg" src="images/sample1.jpg"/></div>
<div class="containerImg"><img class="cutImg" src="images/sample2.jpg"/></div>
Not sure if I understand what you mean, but can't you set the image as background:
.containerImg {
height: 420px;
margin-top: 0;
position: relative;
width: 100%;
background-image: url("img/section_es_2442.jpg");
background-position: center;
}
Or if it is dynamically build in the style attribute of <div class="containerImg">
.img {
margin: 0 auto;
position: absolute;
max-height: 420px; /* Same height as container's */
height: expression(this.height > 420 ? "420px" : true;
}
And if you want to check the width, you have to set the width of the container to a fixed value...
Happy coding ^^