I'm really sorry to post this. I've read dozens of posts on this same issue, but I just can't solve this. How do I place the blue and green boxes side-by-side? I've got plenty of space in my wrapping div, and I think that I am dealing with float correctly, but still incorrect results. What gives?
<div class="titleframe" >
<div class="image" >
<img id="thief" src="thief.png">
</div>
<div class="titletext">
<h1>My Title</h1>
<p>Line1<br>Line2<br>Line3</p>
</div>
</div>
.titleframe {
margin:0 auto;
width:750px;
clear:left;
height:300px;
border: 1px solid red;
}
.image {
width:100px;
height:250px;
border: 1px solid blue;
}
.titletext{
position:relative;
float:left;
padding-left:25px;
padding-top:0px;
height:150px;
width:250px;
border: 1px solid green;
}
Add float:left; to your .image class. Here is a fiddle: http://jsfiddle.net/36KP5/
.image {
width:100px;
height:250px;
border: 1px solid blue;
float:left;
}
Fiddle
You can either float the first one left, and add margin-left to the second one:
.titleframe {
margin:0 auto;
width:750px;
clear:left;
height:300px;
border: 1px solid red;
}
.image {
width:100px;
height:250px;
border: 1px solid blue;
float:left;
}
.titletext{
position:relative;
margin-left: 101px;
padding-left:25px;
padding-top:0px;
height:150px;
width:250px;
border: 1px solid green;
}
Or you can float them both left.
Related
I need two column layout for mobile portrait view for max width 480 pixels, for landscape view I need to display three columns. Here is my css code for two columns layout working, but I have no idea how to display three columns for landscape view. Please give an idea.
html
<div id="sides">
<div id="left"></div>
<div id="right"></div>
</div>
css
#sides{
margin:0;
}
#left{
float:left;
margin-left: 5%;
width:40%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#right{
float:left;
margin-left: 5%;
width:40%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#media screen and (max-width: 300px) {
#left {
width:100%;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
#right {
width:100%;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
}
I have created demo in jsfiddle click here
Try below code :
<div id="sides">
<div id="left"></div>
<div id="centre"></div>
<div id="right"></div>
</div>
#sides {
margin:0;
}
#left {
float:left;
margin-left: 5%;
width:25%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#right {
float:left;
margin-left: 5%;
width:25%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#centre {
float:left;
margin-left: 5%;
width:25%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#media screen and (max-width: 300px) {
#left {
width:50%;
float: left;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
#right {
width:50%;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
#centre {
width:100%;
float: right;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
}
JSFiddle : https://jsfiddle.net/0yugy4s2/
_______________________________________________
| |
| Image |
| |
|_______________________________________________|
I want set a above rectangle is in center in a page i created that using div tag as code is
.rectangle
{
width: 73.3%;
margin:0 50 0 0;
border-top:1px solid #46464f;
border-bottom:1px solid #282832;
border-left:1px solid #282832;
border-right:1px solid #282832;
border-bottom-width:medium;
border-left-width:medium;
border-right-width:medium;
border-top-width:medium;
}
I set <div class="rectangle" align="center"> this code not working
HTML:
<div class="setCenter">Content inside a div tag</div>
CSS:
body {
width: 100%;
height: 100%;
margin:auto;
}
.setCenter {
margin:auto;
width:90%;
height:auto;
border:1px solid #000;
color:Green;
}
Here is the DEMO
Try this:
HTML:
<div align="center">
<img src="http://fin6.com/wp-content/uploads/2013/07/fb81531cc9cf1512dce7f0e5f36e40fe.jpg" alt="nature"/>
</div>
CSS:
div{
width: 300px;
background:red;
margin:0 auto;
}
img{
width:150px;
margin:0 auto;
}
Here is a DEMO
UPDATE
As per your updated question, use margin:0 auto; to center div.
.rectangle
{
width: 73.3%;
margin:0 auto;
border-top:1px solid #46464f;
border-bottom:1px solid #282832;
border-left:1px solid #282832;
border-right:1px solid #282832;
border-bottom-width:medium;
border-left-width:medium;
border-right-width:medium;
border-top-width:medium;
}
Updated DEMO
Try this CSS code:
.rectangle
{
width: 73.3%; margin:0 50 0 0;
border-top:1px solid #46464f;
border-bottom:1px solid #282832;
border-left:1px solid #282832;
border-right:1px solid #282832;
border-bottom-width:medium;
border-left-width:medium;
border-right-width:medium;
border-top-width:medium;
text-align:center;
}
I have some html:
<div id="content">
<div id="leftCol"></div>
<div id="rightCol"></div>
</div>
css like:
#content {
position:absolute;
width:98%;
margin-left:1%;
margin-right:1%;
min-height: 100%;
height: 100%;
padding:0;
}
#leftCol {
position:absolute;
min-height:100%;
float:left;
width:60%;
overflow: hidden;
border-top:1px solid #acacac;
border-left:1px solid #dfdfdf;
border-right:1px solid #dfdfdf;
}
#rightCol {
float:right;
width:40%;
min-height:100%;
border-right:1px solid #dfdfdf;
border-top:1px solid #acacac;
}
When content is added to #leftCol the height 100% is only applied to the 100% when document is loaded. I have a system the dynamically inserts content into #rightContent.
I want to "syncronize" so #leftCol is same height #rightCol after insertion of content. Is this possible with pure css? I could of course use js to achieve this, but css would be nicer :-)
demo
#main {
display: table;
width: 500px;
}
#left, #right {
display: table-cell;
padding: 5px;
}
#left {
background: none repeat scroll 0 0 red;
width: 250px;
}
#right {
background: none repeat scroll 0 0 green;
}
Try this:
#content {
position:absolute;
width:98%;
margin-left:1%;
margin-right:1%;
min-height: 100%;
height: 100%;
padding:0;
display: table;
}
#leftCol {
display: table-cell;
width:60%;
overflow: hidden;
border-top:1px solid #acacac;
border-left:1px solid #dfdfdf;
border-right:1px solid #dfdfdf;
}
#rightCol {
display: table-cell;
width:40%;
min-height:100%;
border-right:1px solid #dfdfdf;
border-top:1px solid #acacac;
}
Fiddle link with css and HTML. In your css file you are using id but in html you are adding class.
*{
padding:0;
margin:0;
}
#content {
width:98%;
margin:1% 1%;
padding:0;
border:1px solid #999999;
display:table;
}
#leftCol {
width:58%;
padding:1%;
background-color:#99FFCC;
display:table-cell;
}
#rightCol {
width:38%;
padding:1%;
background-color:#CCCCCC;
display:table-cell;
}
<div id="content">
<div id="leftCol">
<p>Whether you're preparing a romantic valentine's dinner or having friends over to watch the big game, our meal planning guide can help.</p>
</div>
<div id="rightCol"><p>The right glass of wine or beer can turn a good meal into a great one. Let us help you take the mystery out of beer and wine shopping.</p></div>
</div>
I want to add two extra bottom borders in a div so that it looks as attached image:
Do I need to add two additional empty div's for that? I have very basic markup:
<div class="box">
main div
</div>
Here's the basic demo:
http://jsfiddle.net/3TWtF/
Yes, you'll need to add two <div/>s like so: http://jsfiddle.net/UUDd3/ This will provide the most compatible solution.
Add the following HTML:
<div class="box2">
</div>
<div class="box3">
</div>
And the following CSS:
.box2{
border-left: 1px solid brown;
border-bottom: 1px solid brown;
border-right: 1px solid brown;
width: 480px;
height: 10px;
margin:0 10px;
}
.box3{
border-left: 1px solid brown;
border-bottom: 1px solid brown;
border-right: 1px solid brown;
width: 460px;
height: 10px;
margin:0 20px;
}
You can do it without two extra divs but it will require dropping support for IE7 as you will need to use pseudo-elements.
jsFiddle
.box{
border: 1px solid brown;
width: 500px;
height: 100px;
position:relative;
}
.box:after {
display:block;
content:"";
position:absolute;
border:1px solid brown;
width:400px;
left:50px;
top:100px;
height:15px;
}
.box:before {
display:block;
content:"";
position:absolute;
border:1px solid brown;
width:300px;
left:100px;
top:116px;
height:15px;
}
Demo
Basically, I'm trying to setup something that looks like this:
However, my code for some reason isn't working. Fist of all, in teh tinkerbin, my arrow image isn't even showing. It works fine on my computer though, so I'm not sure why this is. I also tried jsfiddle and it didn't work there either.
I can get the arrow to be there just fine, but I can't get the text to be centered vertically, let alone even go insie the gray box when the image is there. That is what is confusing me here.
HTML:
<div id="answers">
<div id="arrowcenter"></div><div id="answerstext">Text Next To Arrow</div>
</div><!-- end grayAnswer -->
CsS:
#answers {
width:220px;
height:50px;
background-color:#DDDDDD;
border-top:1px solid black;
border-bottom:1px solid black;
margin-top:20px;
}
#arrowcenter {
width:71px;
height:31px;
background-image:url('http://fortmovies.com/brazil/arrow.png');
background-position:0 50%;
background-repeat:no-repeat;
height:100%;
margin-left:-140px; }
#answerstext {
margin-top:0;
}
1st of all your arrow was isn't showing because you were using margin-left:140px; in #arrow_center
See my Fiddle
Just with 1 <div> Fiddle
This answer is inspired by Mr. Alien's answer of using less markup (id optional).
Reference: jsFiddle
HTML:
<span>Masculino</span>
CSS:
span {
background-image:url('http://fortmovies.com/brazil/arrow.png'); /* 70px x 31px */
background-position: 3px 10px;
background-repeat: no-repeat;
background-color: #DDDDDD;
border-top: 1px solid black;
border-bottom: 1px solid black;
font-family: Arial;
font-weight: bold;
font-size: 30px;
padding: 8px 10px 8px 80px;
}
Status Update: jsFiddle with Div for Navbar method
Just remove margin-left:-140px; and add float:left; to #arrowcenter
Working Demo
Use the tag instead of the tag.
The tag defaults to display: block, which prevents the content of different s to be aligned next to each other. tags default to display:inline; which suits your ideas better. As analternative you could also set those display rules in your css.
#answers {
width:220px;
height:50px;
background-color:#DDDDDD;
border-top:1px solid black;
border-bottom:1px solid black;
margin-top:20px;
}
#arrowcenter {
width:75px;
height:31px;
background-image:url('http://fortmovies.com/brazil/arrow.png');
background-position:0 50%;
background-repeat:no-repeat;
height:100%;
float: left;
}
#answerstext {
margin-top: 16px;
}
Little bit changes that i made in just in your css as follow, and it is working...
#answers {
width:220px;
height:50px;
background-color:#DDDDDD;
border-top:1px solid black;
border-bottom:1px solid black;
margin-top:20px;
}
#arrowcenter {
width:120px;
height:31px; float:left;
background-image:url('http://fortmovies.com/brazil/arrow.png');
background-position:0 50%;
background-repeat:no-repeat;
height:100%;
}
#answerstext {
margin-top:0; float:left; height:50px; line-height:50px;
}
Working Demo
OR
Use this CSS
#answers
{
width: 220px;
height: 50px;
background-color: #DDDDDD;
border-top: 1px solid black;
border-bottom: 1px solid black;
margin-top: 20px;
}
#arrowcenter
{
width: 100px;
height: 50px;
background-image: url('http://fortmovies.com/brazil/arrow.png');
background-position: left center;
background-repeat: no-repeat;
float:left;
}
#answerstext
{
line-height:50px;
margin-left:10px;
font-size:20px;
font-family:Arial;
font-weight:bolder;
}
Use this in HTML :-
<div id="answers">
<div id="arrowcenter">
 </div>
<div id="answerstext">
Masculino</div>
</div>
I hope it'll helps!! :)
What's the purpose of margin-left:-140px; it moves #arrowcenter off-screen remove it and you'll be fine.
Also set both divs to display:inline-block and vertical align appropriately
#arrowcenter {
...
display:inline-block;
vertical-align:middle;
}
#answerstext {
...
display:inline-block;
vertical-align:middle;
}
http://jsfiddle.net/XEk5d/