All
this is my first stack overflow post, thanks in advance for any help
I am putting together a page with content and divs with image background, when I try to float two divs on the right one on top of each other, having trouble flow content to the left, I have used clear so one div is on top of the other one on the right, but the content I am trying to put on the left is align with the second image where the clear was applied then there is a big gap for the first div, any suggestions?
I have enclosed code here
.img1 {
float: right;
width: 250px;
box-shadow: 7px 7px 5px #cccccc;
border-radius: 10px;
border: 1px solid #f5aca6;
background: url("url") no-repeat 50% 10px;
background-color: #ffecec;
padding: 70px 5px 10px 5px;
}
.img2 {
float: right;
background: url("url")no-repeat 100% 100%;
margin-top: -20px;
margin-bottom: 10px;
margin-left: 30px;
background-color: #006534;
color: #d2d2d2;
line-height: 20px;
font-size: 13px;
width: 250px;
border: thin silver solid;
box-shadow: 7px 7px 5px #cccccc;
padding: 5px 5px 0px 5px;
}
HTML
<div class="img1">content</div>
<p class="clear"></p>
<div class="img2">content</div>
<div>Content.........</div>
Try this, I believe it's what you asked for:
HTML:
<div style="float: left;">
<div>Content.........</div>
</div>
<div style="float: right;">
<div class="img1">content</div>
<br>
<div class="img2">content</div>
</div>
CSS:
.img1 {
width: 250px;
box-shadow: 7px 7px 5px #cccccc;
border-radius: 10px;
border: 1px solid #f5aca6;
background: url("url") no-repeat 50% 10px;
background-color: #ffecec;
}
.img2 {
background: url("url")no-repeat 100% 100%;
background-color: #006534;
color: #d2d2d2;
line-height: 20px;
font-size: 13px;
width: 250px;
border: thin silver solid;
box-shadow: 7px 7px 5px #cccccc;
}
JsFiddle: https://jsfiddle.net/nmzwLn2q/1/
Related
This question already has answers here:
How can I make a div not larger than its contents?
(43 answers)
Closed 1 year ago.
I am trying to make a simple chat application and can't seem to display the chat text belonging to one user stick to the left while the other user's message sticks to the right.
Here is a sample of the code:
.chat-session {
width: 400px;
height: 400px;
border: 1px solid #aaaaaa;
padding: 1%;
}
.user1 {
padding: 0 2px 2px 2px;
border: 1px solid #09aedc4f;
border-radius: 3px;
background-color: #09aedc4f;
margin-bottom: 2px;
}
.user2 {
padding: 0 2px 2px 2px;
text-align: right;
border: 1px solid rgba(0, 128, 0, 0.493);
background-color: rgba(0, 128, 0, 0.493);
margin-bottom: 2px;
border-radius: 3px;
}
<div class="chat-session">
<div class="user1">Hello</div>
<div class="user2">Hi</div>
<div class="user1">What's up?</div>
<div class="user2">Not much</div>
</div>
I would like the divs to fit the text size and user2's div to align right. I have tried display: inline-block; to fit the divs, but that just displays them all on the same line. I have also tried float: right; and float: left; but that also displays them on the same line.
Can someone help?
you could use display with the table-layout algorithm to shrink element to its content, then max-width and margin-left:auto
.chat-session {
width: 400px;
height: 400px;
border: 1px solid #aaaaaa;
padding: 1%;
}
.chat-session>* {/* Update */
display: table;/* for infos : okay with any browser for ages and only from IE8 for MSIE */
max-width: 100%;
}
.user1 {
padding: 0 2px 2px 2px;
border: 1px solid #09aedc4f;
border-radius: 3px;
background-color: #09aedc4f;
margin-bottom: 2px;
}
.user2 {
padding: 0 2px 2px 2px;
text-align: right;
border: 1px solid rgba(0, 128, 0, 0.493);
background-color: rgba(0, 128, 0, 0.493);
margin-bottom: 2px;
border-radius: 3px;
margin-left: auto/* Update */
}
<div class="chat-session">
<div class="user1">Hello</div>
<div class="user2">Hi</div>
<div class="user1">What's up?</div>
<div class="user2">Not much</div>
<div class="user1">What's up? What's up? What's up? What's up? What's up if there a long text here?</div>
<div class="user2">Not much</div>
</div>
Your can put your message tag in another tag with text-align property
.chat-session {
width: 400px;
height: 400px;
border: 1px solid #aaaaaa;
padding: 1%;
}
.user1 {
display:inline;
padding: 0 2px 2px 2px;
border: 1px solid #09aedc4f;
border-radius: 3px;
background-color: #09aedc4f;
margin-bottom: 2px;
}
.user2 {
display:inline;
padding: 0 2px 2px 2px;
border: 1px solid rgba(0, 128, 0, 0.493);
background-color: rgba(0, 128, 0, 0.493);
margin-bottom: 2px;
border-radius: 3px;
}
.message-right{
position: relative;
width: 100%;
text-align: right;
}
.message-left{
position: relative;
width: 100%;
text-align:left;
}
<div class="chat-session">
<div class="message-left"><div class="user1">Hello</div></div>
<div class="message-right"><div class="user2">Hi</div></div>
<div class="message-left"><div class="user1">What's up?</div></div>
<div class="message-right"><div class="user2">Not much</div></div>
</div>
So i'm butting a border around a div like so
#menu{
margin: 0px;
padding: 100px 0px 0px 20px;
float: left;
border-bottom: 1px solid black;
border-right: 1px solid black;
border-top: 1px solid black;
border-radius: 0px 10px 10px 0px;
}
<div id="menu">
<p>Hello</p>
</div>
But the border ignores the padding or something as can be seen on the image
Image
According to CSS Box Model Border is right in between margin and padding.
CSS Box Model
I am not sure exactly how do you want your design to be but, you can try that shorthand property you used in padding, in margin, Like this:
#menu{
margin: 100px 0px 0px 20px;
padding: 5px;
float: left;
border-bottom: 1px solid black;
border-right: 1px solid black;
border-top: 1px solid black;
border-radius: 0px 10px 10px 0px ;
}
I hope this is what you want.
A simple example is below. for further clarifications visit w3schools
<p class="round3">Roundest border</p>
p.round3 {
border: 2px solid red;
border-radius: 12px;
}
Try these values:
#menu{
margin: 0px;
padding: 100px 0px 0px 20px;
//padding: top right bottom left
float: left;
border: 1px solid black;
border-radius: 10px ;
}
Try this, this is working for me
#menu p{
text-align: center;
margin: 0 auto;
border: 1px solid black;
padding: 50px;
border-radius: 20px;
width: 300px;
}
<div id="menu">
<p>Hello</p>
</div>
If the padding has four values:
padding:10px 5px 15px 20px;
This means:
- top padding is 10px
- right padding is 5px
- bottom padding is 15px
- left padding is 20px
And similar is for border-radius:
border-radius: 15px 50px 30px 5px;
(first value applies to top-left corner, second value applies to top-right corner,third value applies to bottom-right corner, and fourth value applies to bottom-left corner)
So you can try this:
#menu {
margin: 0px;
padding: 100px 0px 0px 20px;
float: left;
border: 1px solid black;
border-radius: 10px;
}
I'm trying to create an input form and the right side of my input boxes keep getting cut off. My code is as follows:
HTML/CSS
.add_idea_box {
background-color: #ffffff;
min-width: 1110px;
margin: 0px 20px 20px 20px;
overflow: hidden;
border: solid 1px #6a6a6a;
box-shadow: 3px 3px 3px #cecdcd;
-moz-box-shadow: 3px 3px 3px #cecdcd;
-webkit-box-shadow: 3px 3px 3px #cecdcd;
text-align: center;
padding-right: 25px;
}
.add_idea_box_left {
float: left;
overflow: hidden;
width: 130px;
height: 200px;
}
.add_idea_box_left_top {
width: 100%;
padding: 15px 20px 20px 0px;
}
.add_idea_box_left_bottom {
width: 100%;
text-align: left;
padding-left: 22px;
}
.add_idea_box_left_bottom_row {
width: 100%;
height: 27px;
font-family: "Arial";
font-size: 85%;
color: #363636;
}
.red_circle {
display: inline;
float: left;
width: 15px;
height: 15px;
border-radius: 50%;
background-color: #ff5f57;
margin-right: 7px;
}
.yellow_circle {
display: inline;
float: left;
width: 15px;
height: 15px;
border-radius: 50%;
background-color: #ffbd2e;
margin-right: 7px;
}
.green_circle {
display: inline;
float: left;
width: 15px;
height: 15px;
border-radius: 50%;
background-color: #29cb41;
margin-right: 7px;
}
.add_idea_box_right {
overflow: hidden;
text-align: left;
min-height: 200px;
padding: 20px 0px 0px 25px;
border-left: solid 1px #bab6b6;
}
.add_idea_box_right_top {
overflow: visible;
width: 100%;
}
.add_idea_box_right_bottom {
overflow: hidden;
float: right;
height: 40px;
margin-top: 10px;
margin-bottom: 10px;
}
input[type=submit] {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #ffffff;
padding: 10px 10px;
background: -moz-linear-gradient(
top,
#fa8e00 0%,
#ab0000);
background: -webkit-gradient(
linear, left top, left bottom,
from(#fa8e00),
to(#ab0000));
border: 1px solid #7d0000;
-moz-box-shadow:
0px 1px 3px rgba(000,000,000,0.5),
inset 0px 0px 2px rgba(255,255,255,0.7);
-webkit-box-shadow:
0px 1px 3px rgba(000,000,000,0.5),
inset 0px 0px 2px rgba(255,255,255,0.7);
box-shadow:
0px 1px 3px rgba(000,000,000,0.5),
inset 0px 0px 2px rgba(255,255,255,0.7);
text-shadow:
0px -1px 0px rgba(000,000,000,0.4),
0px 1px 0px rgba(255,255,255,0.3);
}
input[type=text] {
width: 100%;
height: 20px;
padding: 10px 10px;
border: 1px solid #bab6b6;
-webkit-border-radius: 6px;
border-radius: 6px;
font-family: "Arial";
color: #bab6b6;
background: #efeeee;
}
textarea {
width: 100%;
height: 60px;
padding: 10px 10px;
border: 1px solid #bab6b6;
-webkit-border-radius: 6px;
border-radius: 6px;
margin-top: 10px;
font-family: "Arial";
color: #bab6b6;
background: #efeeee;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="application/xml; charset=utf-8">
<meta name="viewport" content="initial-scale=1">
<html lang="en">
<head>
<title>GroupTrades</title>
<!-- CSS -->
<link type="text/css" href="css/ideaboard2.css" rel="stylesheet" media="screen">
</head>
<body>
<!-- ADD AN IDEA BOX -->
<div class="add_idea_box">
<div class="add_idea_box_left">
<div class="add_idea_box_left_top">
</div>
<div class="add_idea_box_left_bottom">
<div class="add_idea_box_left_bottom_row">
<div class="green_circle"></div>5 accepted
</div>
<div class="add_idea_box_left_bottom_row">
<div class="yellow_circle"></div>2 pending
</div>
<div class="add_idea_box_left_bottom_row">
<div class="red_circle"></div>3 rejected
</div>
</div>
</div>
<div class="add_idea_box_right">
<form method="post" action="dashboard.php">
<div class="add_idea_box_right_top">
<input type="hidden" name="group" value="<?echo $group;?>">
<input type="text" name="title" value="Title" autofocus>
<textarea value="idea" id="idea">Idea</textarea>
</div>
<div class="add_idea_box_right_bottom">
<input type="submit" id="Submit" name="Submit" value="Add Idea">
</div>
</form>
</div>
</div>
<br><br><br>
</body>
A live version is at: http://quickid.net/test2/ideaboard2.html ... You can see that the right side of the input box and the text box are both getting cut off and their right borders are not showing.
Any help would be greatly appreciated. Thanks!
Add box-sizing property to input and text-area and style accordingly
CSS
.add_idea_box_right_top input[type="text"],
.add_idea_box_right_top textarea{
box-sizing:border-box;
}
hope this helps..
It's because you have set all of these properties on your input element:
width: 100%
padding: 10px
border: 2px
So the input element takes up 100% of the width and it also has 10px padding both left and right on top of that and 2px border on top of that. They all add up so the total width of your element is more than 100% of the width of the containing element.
Try modifying the padding of this class, so try this one.
FROM THIS:
.add_idea_box_right {
overflow: hidden;
text-align: left;
min-height: 200px;
padding: 20px 0px 0px 25px;
border-left: solid 1px #bab6b6;
}
TO THIS:
.add_idea_box_right {
overflow: hidden;
text-align: left;
min-height: 200px;
padding: 20px 25px 0px 25px;
border-left: solid 1px #bab6b6;
}
Let me know if it helped you.
It is because 100% width as suggested is interfering with some of the padding, reduce the width to a smaller percentage and center your input field for it to scale better with increasing resolutions.
Edit: If you inspect element on mozilla you can clearly see where the overlap happens with the pick element thing!
Created a wrapper div called top div, got a p tag called Title aligned to the left and another div called buttonCP containing 4 p tags, aligned to the center with margin 0 auto. Now I want a final p tag called Button5 aligned to the right within top div, just cant seem to do it. Inspecting element shows that buttonCP margin auto could be pushing the final p tag out of the wrapper div. Any idea how I can have Button5 on the same line as Title and buttonCP? Thanks in advance!
Here is jsfiddle link:
https://jsfiddle.net/6r6jzypy/
<style> #topdiv {
background-color: #F0F0F0;
height: 40px;
width: 100%;
border: 2px solid #D8D8D8;
float:left;
}
p[name=heading] {
margin: 0;
font-weight: bold;
padding: 10px 8px 6px 8px;
float:left;
font-size: 1.0em;
}
#Result {
margin: 0;
float: right;
}
.button1 {
background-color: #D8D8D8;
margin-top: 3px;
float: left;
padding: 6px 8px 6px 8px;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
border: 2px solid #D8D8D8;
border-right: 1px;
}
.button2 {
background-color: #D8D8D8;
margin-top: 3px;
float: left;
padding: 6px 8px 6px 8px;
border: 2px solid #D8D8D8;
border-right: 1px;
}
.button3 {
background-color: #D8D8D8;
margin-top: 3px;
float: left;
padding: 6px 8px 6px 8px;
border: 2px solid #D8D8D8;
border-right: 1px;
}
.button4 {
background-color: #D8D8D8;
margin-top: 3px;
float: left;
padding: 6px 8px 6px 8px;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
border: 2px solid #D8D8D8;
}
#buttonCP {
height: 34px;
width: 290px;
margin: 0 auto;
}
</style>
<body>
<div id="topdiv">
<p name="heading">Title</p>
<div id="buttonCP">
<p class="button1">Button1</p>
<p class="button2">Button2</p>
<p class="button3">Button3</p>
<p class="button4">Button4</p>
</div>
<p id="Result">Button5</p>
</div>
</body>
try this :
<div id="topdiv">
<p name="heading">Title</p>
<p id="Result">Button5</p>
<div id="buttonCP">
<p class="button1">Button1</p>
<p class="button2">Button2</p>
<p class="button3">Button3</p>
<p class="button4">Button4</p>
</div>
</div>
Live demo
I'm using a container with a fixed width. Inside the container I have 2 divs floating left, the first div has a width of 9% and the second div has a width of 91% but for some reason there is a 1px white line that shows up on the very right. How do I fix this issue? It sometimes varies when zooming on the browser.
HTML:
<div id="main-container">
<div id="container1">
</div>
<div id="container2">
</div>
</div>
CSS:
#main-container {
margin: 0 auto;
margin-top: 45px;
width: 1110px;
height: 650px;
border: 3px solid red;
padding: 0px;
border-radius: 7px;
-moz-border-radius: 7px;
-webkit-border-radius: 7px; }
/*content*/
#container1 {
float: left;
width: 9%;
height: 100%;
border-radius: 7px 0px 0px 7px;
-moz-border-radius: 7px 0px 0px 7px;
-webkit-border-radius: 7px 0px 0px 7px;
background: yellow; }
#container2 {
float: left;
width: 91%;
height: 100%;
border-radius: 0 7px 7px 0;
-moz-border-radius: 0 7px 7px 0;
-webkit-border-radius: 0 7px 7px 0;
background: orange; }
demo
As the some others mentions it looks like the problem is caused by rounding differences in WebKit.
Your can add float: right; to the second container to fix the alignment and remove the gap. http://jsfiddle.net/Gw5AH/3/