Why i can not split screen in two div in html? - html

I want split screen only two div's for that purpose write this html code:
<div class="box">
<div class="div1">
<img src="../Content/45.png" style="width:auto;" />
</div>
<div class="div2">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<div class="clear"></div>
</div>
and this is css style:
<style>
div.box {
background: #EEE;
height: 100px;
width: 600px;
}
div.div1 {
background: #999;
float: left;
height: 100%;
width: 50%;
}
div.div2 {
background: #666;
height: 100%;
width:50%;
left:100px;
float:right;
}
div.clear {
clear: both;
height: 1px;
overflow: hidden;
font-size: 0pt;
margin-top: -1px;
}
</style>
but when i run that page,i see this output:
Why i can not split screen?what is correct css?thanks.

Its working fine..
Check
https://jsfiddle.net/3d5mq1tf/
Please update the fiddle .. If you find something missing..
div.box {
background: #EEE;
height: 100px;
width: 600px;
}
div.div1 {
background: #999;
float: left;
height: 100%;
width: 50%;
}
div.div2 {
background: #666;
height: 100%;
width:50%;
left:100px;
float:right;
}
div.clear {
clear: both;
height: 1px;
overflow: hidden;
font-size: 0pt;
margin-top: -1px;
}
<div class="box">
<div class="div1">
<img src="../Content/45.png" style="width:auto;" />
</div>
<div class="div2">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<div class="clear"></div>
</div>

Your code is working up to the point where the image gets rendered, which will stretch over the bounds of your div because you don't tell it otherwise.
While the only parts you need to add are the image width ones, I took the liberty and turned this from a float-based arrangement to in inline-based one, giving you reduced markup as well as CSS, and better control over what you're doing.
div.box {
background: #EEE;
height: 100px;
width: 600px;
white-space: nowrap;
}
div.box > div {
display: inline-block;
height: 100%;
vertical-align: top;
width: 50%;
}
div.box > div img {
width: 100%;
}
.div1 {
background-color: #999;
}
.div2 {
background-color: #666;
}
<div class="box">
<div class="div1">
<img src="http://i.imgur.com/k8BtMvj.jpg" alt="test image" />
</div><div class="div2"></div>
</div>
I suspect that you also want the image to have a maximum height of 100px, as the parent container has. If you do, you could use overflow: hidden on the parent container, but you would be better off rendering it as a background image, like this:
div.box {
background: #EEE;
height: 100px;
width: 600px;
}
div.box > div {
display: inline-block;
height: 100%;
vertical-align: top;
width: 50%;
}
div.box > div img {
width: 100%;
}
.div1 {
background: #999 url('http://i.imgur.com/k8BtMvj.jpg') left top no-repeat;
background-size: cover;
}
.div2 {
background-color: #666;
}
<div class="box">
<div class="div1"></div><div class="div2"></div>
</div>
This also shows the differences in where you should use background vs background-color

Related

How to set divs with images in one line?

Hello i have a problem with my images in divs.
jsFiddle
.navbar {
position: fixed;
z-index: 1000;
height: 100%;
width: 60px;
left: 0px;
top: 0px;
background-color: #2e2d2d;
border-right: 1px solid #c6c5c5;
}
#works {
position: relative;
margin-left: 60px;
height: 100%;
}
.left {
position: relative;
width: 50%;
float: left;
}
.right {
position: relative;
height: 100%;
width: 50%;
float: left;
}
#works .up {
width: 100%;
height: 50%;
}
.up h1 {
font-family: ralewayregular;
text-transform: uppercase;
text-decoration: none;
font-size: 10px;
padding: 10px 15px;
}
.up h2 {
font-family: ralewayregular;
font-size: 5pt;
padding: 1px 15px;
}
.down_1 {
float: left;
width: 50%;
height: 50%;
}
.down_2 {
float: left;
width: 50%;
}
<div class="navbar">
<a class="menu-trigger"></a>
</div>
<section id="works">
<div class="all">
<div class="left">
<img src="http://i.telegraph.co.uk/multimedia/archive/02194/Bank2_2194348b.jpg" width="100%">
</div>
<div class="right">
<div class="up">
<h1>bl bla</h1>
<h2>/asdasda <br /> as : VENEZIA
/ SELLEKTOR / SUGARPILLS / NIKKI LISSONI</h2>
<div class="arrow"></div>
</div>
<div class="down_1">
<img src="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg" width="100%" height="100%" />
</div>
<div class="down_2">
<img src="http://cutebabywallpapers.com/wp-content/uploads/2014/09/cute-a-little-baby-and-cat-pictures.jpg" width="100%" />
</div>
</div>
</div>
</section>
Div left must have the same hight like div right. Both should end in one line.
How to do this without giving them hight, to not strech my images? Div up and down should have 50% height but its not working.
Someone can help me solve it?
For them to to be the same height, there most be some measure, strict height or min-height.
For the height to measure, do something like:
.left, .right {
width: 100%; /* Adjust as needed */
min-height 50%; /* best to be the same as what you assume would
be the height of the taller both DIV's so that nothing will be cut off */
}
For your image not to be distorted, do something like:
.right img, .right img, {
width: 100%;
height: auto; /* Set the height to auto to give the
image a breathing space to reduce distortion */
}

fill remaining space with div width auto

hey guys thanks for the upcoming support how do I set the blue to fill up the remaining width of the whole maininfo div? I tried setting the width:auto
<div class="maininfo">
<div class="large">2</div>
<div class="smallblock">
<div class="smalltop">3</div>
<div class="small">4</div>
</div>
<div class="smallblock">
<div class="smalltop">5</div>
<div class="small">6</div>
</div>
</div>
.maininfo {
width: 600px;
}
.large {
float: left;
height: 95px;
background-color: blue;
width:auto;
}
.smallblock {
float: right;
height: 90px;
margin: 0 0 0 5px;
width: 20%;
}
.small {
background-color: red;
height: 50%;
width: 100%;
}
.smalltop {
background-color: red;
height: 50%;
width: 100%;
margin-bottom:5px;
}
UPDATED MY JFIDDLE BUT NOW IT MAKES 2 LINES: http://jsfiddle.net/4ykf5frk/11/
If just .maininfo, merely add a 'background: blue;' property to your style declaration:
.maininfo {
background-color: blue;
width: 600px;
}
Otherwise, just add a 'background: blue;' property for the 'body' element:
body {
background-color: blue;
}

how to change background on mouse hover?

i have a div that contains an image fills all the div,
positioned on it a text.
when the mouse is over the container div the mouse will change to pointer(no problem),but and the image changed to look like pressed one.
But this wont happened thus the text represents other layer.
so could any one help me to resolve this problem in html and css?
<div style="float: right; width: 127px; height: 35px; background-color: rgba(139, 84, 164,.44); background-color: rgb(229, 230, 218);
cursor:pointer; position:absolute;">
<div style="overflow: hidden; width: 87px; height: 100%; float: right; position:absolute; z-index:2; background-color:#FF0099;
margin-left: 40px;">
<p class="para" style="color: rgb(0,178,192); padding-top: 8px; padding-right: 5px;">اسم الملف</p>
</div>
<div style="position:absolute; z-index:1; ">
<img src="saba/playa.png" onMouseOver="this.src='saba/playao.png'" onMouseOut="this.src='saba/playa.png'"style="float: left;">
</div>
</div>
I'm not sure if I understand well..
But I think this shows what you want to create...
<div class="wrapper">
<div class="text-div">
some text
</div>
<div class="colored-button-on-hover"></div>
<div class="clear"></div>
</div>
css:
.wrapper {
width: 200px;
height: 100px;
background: #999;
position: relative;
}
.wrapper .text-div {
float: right;
color: #000;
}
.wrapper .colored-button-on-hover {
float: left;
width: 30px;
height: 25px;
background: red;
}
/*on wrapper div hovered*/
.wrapper:hover {
background: blue;
cursor: pointer;
}
.wrapper:hover .text-div {
color: #FFF;
}
.wrapper:hover .colored-button-on-hover {
background: yellow;
}
.clear {
clear: both;
}
Here is jsfiddle sample: http://jsfiddle.net/AYjmF/

Page layout with HTML and CSS

I am trying to create a page layout something like this.
This is my HMTL structure -
<div id="content-three-cols">
<div class="leftcol">
</div>
<div class="cols-content">
<div class="banner">
</div>
<div class="two-cols">
<div class="rightcol">
</div>
<div class="middlecol">
</div>
</div>
</div>
</div>
This is my CSS code so far -
.leftcol {
display: inline;
float: left;
min-height: 500px;
width: 180px;
background: #34ab2b;
}
.banner {
background: #ffe400;
border-bottom: 1px solid #DDDDDD;
float: left;
width: 750px;
height: 150px;
}
.middlecol {
width: 600px;
min-height: 600px;
background: #2b73ab;
}
.rightcol {
width: 150px;
min-height: 500px;
background: #b2540f;
float: right;
}
Adding this styles I couldn't get my expecting output. Instead my desire result this code create a mess layout for me. Can anybody tell my how can I figure this out.
This is JsFiddle
Thank you.
Quite simple really, here is a quick demo i made, i will explain everything in a second.
Demo
HTML:
<div class="left"></div>
<div class="head"></div>
<div class="center"></div>
<div class="right"></div>
CSS:
body, html{
height:100%;
}
.left, .right, .head, .center{
float:left; // Float all the containers to the left so have a `inline` effect
}
.left{
height:100%;
width:25%; // Full width minus right and center width
background:orange;
}
.head{
background:red;
height:10%; // Height of header
width:75%; // Full width minus left sidebar
}
.center{
width:50%; // Full width minus both sidebar's width
background:skyblue;
height: 90%; // Full height minus header height
}
.right{
width:25%; // Full width minus center and left width
background:green;
height:90%; // Full height minus header height
}
also note, you may need to have a Clearfix handy seeing as a lot of elements are floating in thin air.
Happy coding :)
Clearfix...
Well take a look at this fiddle, everything is working fine
http://jsfiddle.net/mqzJN/
Now if we add a float to the link like this
http://jsfiddle.net/mqzJN/1
Then you can see the background is gone, because the <div> doesn't have any height any more because the link is floating in thin air.
So you use a clearfix to fix this, like in this fiddle
http://jsfiddle.net/mqzJN/2/
So any element that has a float you might wan't to add the clearfix class to the container of that element like in the last fiddle example.
There you go! (http://jsfiddle.net/aV2Dn/)
<div id="wrapper">
<div id="left_column"></div>
<div id="top_bar"></div>
<div id="middle"></div>
<div id="right_column"></div>
</div>
#wrapper{
width:500px
height:500px;
margin: auto;
}
#left_column{
width: 100px;
height:500px;
background: #34ab2b;
position:absolute;
left:0px;
top: 0px;
}
#top_bar{
position: absolute;
left: 100px;
top: 0px;
width: 400px;
height:100px;
background-color: #ffe400;
}
#middle{
position: absolute;
left: 100px;
top: 100px;
width: 300px;
height:400px;
background: #2b73ab;
}
#right_column{
position: absolute;
left: 400px;
top: 100px;
width: 100px;
height:400px;
background: #b2540f;
}
here
The HTML:
<body>
<div class="left">
</div>
<div class="right">
<div class="upper"></div>
<div class="lower">
<div class="innerLeft"></div>
<div class="innerRight"></div>
</div>
</div>
</body>
The CSS:
body {
width: 100%;
}
.left {
width: 25%;
height: 450px;
float: left;
background-color: #f00;
}
.right {
width: 75%;
height: 450px;
float: right;
background-color: #4cff00;
}
.upper {
width: 100%;
float: left;
height: 100px;
background-color: blue;
}
.lower {
width: 100%;
height: 100px;
background-color: grey;
}
.innerLeft {
width: 65%;
float: left;
height: 350px;
background-color: fff;
}
.innerRight {
width: 35%;
float: right;
height: 350px;
background-color: #000;
}

Expand width to take remaining width of parent div

An example of my code can be found on JSFiddle http://jsfiddle.net/WdZgV/
CSS
<style type="text/css">
body {
margin: 0;
padding: 0;
}
.header_div {
display: inline-block;
width: 100%;
text-align: center;
}
.header {
display: inline-block;
height: 100px;
width: 100%;
max-width: 1000px;
background: #ddd;
}
.logo {
float: left;
width: 200px;
height: 100px;
background: #bbb;
}
.menu {
float: left;
width: 800px;
height: 100px;
background: #999;
}
</style>
HTML
<div class="header_div">
<div class="header">
<div class="logo"></div>
<div class="menu"></div>
</div>
</div>
What i want is that when you resize the window width to less than 1000px the .menu div resize to the size of the parent div.
So as an example:
If you have your window width as 900px, the .logo div has 200px and the .menu div has 700px.
Is there anyway i can do this with CSS, or i need to use Javascript?
Yes — remove the float, don't specify width, and set overflow to hidden. Example here; .menu becomes:
.menu {
height: 100px;
background: #999;
overflow: hidden;
}
#Andoni Roy Use this
.logo {
float: left;
width: 200px;
height: 100px;
background: #bbb;
}
.menu {
float:right;
overflow:hidden;
height: 100px;
background: #999;
}
You may not want to play with floating properties but specifying the parent width and display to table.
Like in the following example: http://jsfiddle.net/A8zLY/745/
You would end up having something like:
HTML
<div class="header_div">
<div class="header">
<div class="logo"></div>
<div class="menu"></div>
</div>
</div>
CSS
.header_div {
width: 1280px;
}
.header {
display: table;
}
.logo {
display: table-cell;
width: 280px;
}
.menu {
display: table-cell;
width: 1000px;
}
You could specify width in percentages.