how to hide image left part of image when using overflow hidden - css

I am new to CSS programming . Using overflow:hidden for hiding image greater than DIV area. Perhaps I want hidden part of image should be in the left part, but currently its taking right part. My code follows as below.
Html code:
<div class="a1">
<img src="img/image4.jpg">
</div>
CSS:
.a1{height:200px;width:100px; overflow:hidden;}

Try this (notice the direction: rtl;):
.a1 {
height:200px;
width:100px;
overflow:hidden;
direction: rtl;
}
<div class="a1">
<img src="http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b">
</div>

.a1 {
height:200px;
width:100px;
overflow:hidden;
background:#ff0;
}
<div class="a1">
<img src="http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b">
</div>
Seems to work fine for me. I added the yellow background to show where the DIV is at and linked to an SO sprite.
If you're getting a different effect, then it's quite likely the CSS on your page elsewhere which is cascading and causing the conflict.
Side note: Writing a stylesheet in CSS is not really called "programming". :)
Click Run code snippet to see this in action.
Or, for the converse:
.a1 {
height:200px;
width:100px;
overflow:hidden;
background:#ff0;
}
<div class="a1">
<img src="http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b" align="right">
</div>

.a1 {
height:200px;
width:100px;
overflow:hidden;
direction: rtl;
}
<div class="a1">
<img src="https://www.google.com.pk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
</div>

use float:right for image element
<div style="width:200px; height:200px; overflow:hidden">
<img style="float:right" src="url" />
</div>

Related

How would I show text inside a span tag when hovering over a different element?

I have a webpage set up that has multiple DIV tags in a grid like table. I would like to know if it's possible by using CSS to show text when mousing over a DIV or IMG or A tag. I could use any of those 3 to make it happen since one of my DIV tags holds just the IMG which is also a hyperlink to a new page. A sample of one of my rows in my page is setup kinda like this:
<div class="Home-06">
<a href="image1link.html">
<img src="images/image1.jpg" width="250" height="250" alt=""
style="border-width: 0px"></a>
</div>
<div class="Home-07">
<span>Text for Image 1</span><span>Text for Image 2</span>
</div>
<div class="Home-08">
<a href="image2link.html">
<img src="images/image2.jpg" width="250" height="250" alt=""
style="border-width: 0px"></a>
</div>
I'd like to make the middle DIV "Home-07" with my span tags display different text when hovering over "Home-06" and "Home-08".
My CSS:
div.Home-06 {
position:absolute;
left:102px;
top:450px;
width:250px;
height:250px;
}
div.Home-07 {
position:absolute;
left:352px;
top:450px;
width:320px;
height:250px;
background-color:#000000;
}
div.Home-08 {
position:absolute;
left:672px;
top:450px;
width:250px;
height:250px;
}
The easiest way to do this is if the span is contained within the element that you are hovering over, so for example:
<div class="alwaysshowme">
<p>
I can always be seen [hover over me!]
<span class="showmeonhover"><br />I can only be seen on hover...</span>
</p>
</div>
Then the CSS would be:
.showmeonhover { display: none; }
.alwaysshowme:hover .showmeonhover {
display: inline;
}
Here's a fiddle: http://jsfiddle.net/Niffler/d2kYq/
Use JQuery, with hover : http://api.jquery.com/hover/ Look for the demo.

how to align multiple div horizontaly

This is what I have done till now.
<div style="overflow:visible;width:1050px;border:1px solid green;height:50px;margin-left:115px">
<div style="border:1px solid red;position:absolute;width:730px;">
<br/><br/><br/>
<div class=''><div class='tagstyle'>FRESHER</div><div class='tagstyle'>IT JOBS</div><div class='tagstyle'>2013</div><div class='tagstyle'>BANGALORE</div></div>
<!----- left --->
<div>
<div style="border:1px solid blue;height:900px;position:absolute;width:340px;margin-left:735px;">
<!------ right --->
<div>
</div>
Problem is, right side div going downward, when left side div has any content.
Aha! Saw your edit now! It's really simple with some css3 table display properties, but that doesn't work in old browsers.
However, you could use some simple css to make a standard blog template with sidebar, header and main content:
<style>
.body-wrapper {
position:absolute;
top:20px;
left:50%;
width:900px;
margin-left:-450px; /* Half the width (negative) */
background:red;
}
.header {
position:relative;
width:100%;
height:100px;
margin-bottom:10px;
background:blue;
}
.main {
float:left;
width:70%;
background:green;
}
.sidebar {
float:right;
width:30%;
background:yellow;
}
</style>
<div class="body-wrapper">
<div class="header">
Header!
</div>
<div class="main">
Content!
</div>
<div class="sidebar">
Sidebar!
</div>
</div>
Here is a jsFiddle as proof: http://jsfiddle.net/Kepk9/
Hope it helps!
Another answer!
If you just would like to position divs after each other, you could set them to display:inline-block, like this:
<style>
.inline {
display:inline-block;
}
</style>
<div class="inline">
Labalodado
<br/>multiline content
</div>
<div class="inline">
Less content
</div>
<div class="inline">
Another div
<br/>with
<br/>multiline content
</div>
The reason why your code doesn't work is really simple actually. I made some other answers first because I think that they are a better approach.
position:absolute doesn't automatically move the item to {0,0}
You have to set top:0px by yourself.
Oh.. and there are some mistakes in your code too, but just go with one of my other too answers and you'll be fine :)

CSS IE issue with having two divs in one line

I have got the following code working fine on FF. As you can guess, I want the following two divs stays on one line without breaking when browser resize.
<div style="float: left; margin-right: 10px; ">
</div>
<div style="overflow: hidden;">
</div>
But as per usual, when I tested the page with IE 9, the right div was already below the left one.
Can someone pls help me out here, thanks,
Either add "float:right" in your second div or
add "width:XXpx" into your first div.
Wrap it with another div
<div>
<div style="float: left; margin-right: 10px; ">
</div>
<div style="float:right; overflow: hidden;">
</div>
</div>
you also float the other div
<div style="float: left; margin-right: 10px; ">
</div>
<div style="float:right; overflow: hidden;">
</div>
==========================================================>>>
UPDATE
HTML
<div class="marginRight"></div>
<div></div>
CSS
div {
float:left;
border:1px solid red;
width:45%;
height:100px;
}
.marginRight {margin-right: 10px;}
WORKING DEMO
it is working fine
if you want more configuring
<div style="display:table-row;">
<div style="width:49%; margin-right:2%; height:100px; float:left; display:table-cell;"> any thing you wanted </div>
<div style="width:49%; height:100px; float:left; display:table-cell;"> any thing you wanted </div>
</div>
Use a container div and set the two divs to either % of total width or total px of the page.
#containerdiv {
width:100%;
overflow:hidden;
}
#leftdiv {
width:20%;
overflow:hidden;
float:left;
#rightdiv {
width:80%;
overflow:hidden;
float:left;
}
<div id="containerdiv">
<div id="leftdiv"> TEST </div>
<div id="rightdiv"> TEST </div>
</div>
Remember if you use margins and paddings you will need to adjust the percentages or pixels for it to line up next.
For example. If you add padding 1% to left div, it will push the right div down to second line since you are now at a total of 101% of the container divs width.

Have child div stretch to remaining width of parent div who has variable width

I tried searching for this exact issue I'm having and I couldn't really find any solutions. So currently this is where I'm at:
<div style="min-width:800px; max-width:1280px;">
<img style="width:300px; height:300px; display:block; float:left;"/>
<div style="float:left;">
</div>
</div>
And this is what I'm trying to achieve:
Currently the div with text in it just pops it right below the image, which is what it's supposed to do. I just don't know how to get how I want it. I've been trying to avoid table display...
Anyways, thanks in advance.
You can also try this:
<div style="min-width:800px; max-width:1280px; position:relative;">
<img style="width:300px; height:300px; display:block; float:left; position:absolute; top:0; left:0;"/>
<div style="margin-left:300px;">
<!-- Now this content will grow as much as it can without disturbing the column of the image -->
</div>
</div>
Use Positioning!
<div style="min-width:800px; max-width:1280px; position: relative; padding-left: 305px;">
<img style="width:300px; height:300px; display:block; position: absolute; top: 0px; left: 0px;"/>
<div style="background: white;">
</div>
</div>
Screenshot:
Fiddle: http://jsfiddle.net/dsRVc/
Longer Text Preview
Fiddle: http://jsfiddle.net/dsRVc/1/

Stick div to the bottom of the page

I have div with position absolute and I want to put another div under.
The two divs have diffrent widths.
The div above is with position absolute and is centered. The div that should be at the bottom has 100% width.
How to make that?
Thanks!
make one div that contains both
use float:right
example:
div#p8015buttons {
position:absolute;
bottom:0.5em;
right:0.5em;
width:90px;
}
div.p8015 {
float:right;
margin:1px;
}
Wrap both DIVs in a third one and position that one absolute instead of the original one.
Not tested, but this should do it.
HTML:
<div class="wrapper">
<div class="one">
Content
</div>
<div class="two">
More content
</div>
</div>
And the CSS:
.wrapper
{
position:absolute;
width: 500px;
height: 400px;/*whatever you want*/
}
.one,
.two
{
position:relative; /*or static*/
}
Hope it helps :)
Tested
HTML MARKUP
<div class="wrapper">
<div class="left-ontent>
</div>
<div class="right-ontent>
</div>
</div>
CSS
.wrapper{width:980px;margin:0 auto;position:absolute;}
.left-content{float:left;width:630px;}
.right-content{float:right;width:320px;}
Try this one, you can then move style to your css
<div style="width:500px; margin: auto; height:200px; background-color:black;">
</div>
<div style="width:100%; height:200px; background-color:green;">
</div>

Resources