I'm creating a widget with a tabular structure and I'm not seeing why the two rows on the right are not expanding to full width (or why they don't have a red border around them).
My goal is for the black horizontal rule to run between rows 1 and 2 and reach the far right end of the entire table.
Demo Fiddle
.table {
display: table;
width: 100%;
white-space: nowrap;
border: 1px solid blue;
}
#cell1 {
display: table-cell;
padding-left: 30px;
border: 1px dashed orange;
}
#cell1 > #line1 {
display: inline-block;
font-size: 16px;
padding-top: 5px;
border: 1px solid red;
}
#cell1 > #line2 {
display: inline-block;
font-size: 30px;
border: 1px solid red;
}
#cell1 > #line3 {
display: inline-block;
padding-right: 20px;
border: 1px solid red;
}
#cell2 {
display: block;
width: 100%;
border: 1px dashed orange;
}
#cell2 > #topRow {
display: table-row;
width: 100%;
border: 1px solid red;
padding-top: 10px;
padding-bottom: 10px;
border-bottom: 1px solid black; // horizontal rule
}
#cell2 > #bottomRow {
display: table-row;
width: 100%;
border: 1px solid red;
padding-top: 10px;
padding-bottom: 10px;
}
<div class="table">
<div id="cell1">
<span id="line1">line 1</span>
<br>
<span id="line2">line 2</span>
<br>
<span id="line3">line 3</span>
</div>
<div id="cell2">
<div id="topRow">
This is the top row
</div>
<div id="bottomRow">
This is the bottom row
</div>
</div>
</div>
Remove display:table-row to make the bottom border visible
or use:
<div id="topRow">
This is the top row
</div>
<hr />
<div id="bottomRow">
This is the bottom row
</div>
What you have to do is create one full width row with your <hr> within it.
<tr><!-- table row 100% width -->
<hr></hr>
</tr>
Your defining a new full width table row with only the horizontal rule running through it.
Actually it appears you aren't even using tables, so this is kind of an odd question - but, in your case just make a full width div with the <hr> within it, or position the hr absolute with a higher z-index by adding a selector directly to hr element.
Related
In the following code when i specify margin-top for #thirdDiv, It doesn't work until i give it 36px.
What is the reason?
#Container {
border: 15px solid orange;
width: 350px;
}
#firstDiv {
display: inline-block;
border: 1px solid red;
font-size: 1em;
}
#secondDiv {
border: 1px solid green;
display: inline-block;
font-size: 2em;
}
#thirdDiv {
display: inline-block;
border: 1px solid pink;
font-size: 1em;
margin-top: 36px;
}
<div id="Container">
<div id="firstDiv"> a </div>
<div id="secondDiv"> b </div>
<div id="thirdDiv"> c </div>
</div>
Because the child elements of your Container element are based on the bottom of that div. If you add vertical-align: top to your child elements, any margin-top is possible. You can try it out in this CodePen where I copied you code and tidied the CSS up a bit. Note that you can choose to only put vertical-align: top in your #thirdDiv element. This way you can keep the other two divs in their original position.
What you are looking for is padding. The CSS margin properties are used to create space around elements, outside of any defined borders whereas the CSS padding properties are used to generate space around an element's content, inside of any defined borders.
Try the following instead of applying margin-top to #thirdDiv.
#Container {
padding-top: 36px;
border: 15px solid orange;
width: 350px;
}
#firstDiv {
display: inline-block;
border: 1px solid red;
font-size: 1em;
}
#secondDiv {
border: 1px solid green;
display: inline-block;
font-size: 2em;
}
#thirdDiv {
display: inline-block;
border: 1px solid pink;
font-size: 1em;
}
<div id="Container">
<div id="firstDiv"> a </div>
<div id="secondDiv"> b </div>
<div id="thirdDiv"> c </div>
</div>
You must specify a value for margin-top else it won't know how much margin to add.
What were typing for margin-top before, margin-top: ;?
What is your desired effect?
why the border of the span is next to top? if I delete the display of span, it works.
thank you.
div {
height: 80px;
border: 1px solid green;
line-height: 80px
}
.inner-span {
height: 20px;
display: inline-block;
border: 1px solid red;
}
<div>
<span class="inner-span">123123</span>
</div>
As other explained in the comments, the issue is that you have a fixed height of 20px and you set a line-height that get inherited from the parent to 80px so the line-box height is bigger thus you are having an overflow.
If you change the line-height of the inner span it will get fixed:
div {
height: 80px;
border: 1px solid green;
line-height: 80px
}
.inner-span {
height: 20px;
line-height: initial;
display: inline-block;
border: 1px solid red;
}
<div>
<span class="inner-span">123123</span>
</div>
Now why the border is positionned on the top?
It's because the default alignment is baseline and to define the baseline we consider the text.
Aligns the baseline of the element with the baseline of its parentref
If you change the vertical-align to be bottom, for example, you will see that the border will be on the bottom.
Aligns the bottom of the element and its descendants with the bottom
of the entire line.ref
div {
height: 80px;
border: 1px solid green;
line-height: 80px
}
.inner-span {
height: 20px;
display: inline-block;
vertical-align:bottom;
border: 1px solid red;
}
<div>
<span class="inner-span">123123</span>
</div>
If you add overflow:auto will clearly understand the overflow issue and you will also change the baseline of the element to make it the bottom border:
div {
height: 80px;
border: 1px solid green;
line-height: 80px
}
.inner-span {
height: 20px;
display: inline-block;
overflow:auto;
border: 1px solid red;
}
<div>
<span class="inner-span">123123</span>
</div>
If you remove the fixed height you will also notice that the height of the element will get defined by the line-height (the height of the line-box) and will logically be 80px:
div {
height: 80px;
border: 1px solid green;
line-height: 80px
}
.inner-span {
display: inline-block;
border: 1px solid red;
}
<div>
<span class="inner-span">123123</span>
</div>
The next image is currently what I have.
And this is what should be:
As you can see, the dots on the third column are not aligned. It should meet the next requirement:
As you can imagine, I might use two divs because of the two borders.
This next code is what I have tried all day long, I cannot achieve to position the dots in the middle with the background-color stretched (considering the two border colors). What am I wrong? Should I remove everything and change it by a flexbox? I'll appreciate your help.
Html code:
You have 4 items in your cart
<article class="cart-item">
<div class="left">
<img src="images/item1.jpg"></img>
</div>
<div class="center">
<h4 class="title">Dexter Men's Max Bowling Shoes (Right Handed Only)</h4>
<span class="description">Shipping 3-day with UPS</span>
<span class="description">Color: Gray</span>
<span class="description">Size: 28.5</span>
<span class="price">$60.00</span>
</div>
<div class="right">
<div class="grouped-dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
</article>
Css code
.cart-item
{
border-bottom: 1px solid #CCCCCC;
border-top: 1px solid #CCCCCC;
display: table;
height: 100%;
overflow: hidden;
}
.cart-item>div
{
display: table-cell;
}
.left,.center
{
padding-bottom: 10px;
padding-top: 10px;
}
.left
{
padding-left: 15px;
padding-right: 15px;
width: 33.33%;
}
.left img
{
max-width: 100%;
}
.center
{
padding-right: 15px;
text-align: left;
vertical-align: top;
width: auto;
}
.right
{
border-left: 1px solid #CCCCCC;
border-right: 1px solid #CCCCCC;
vertical-align: middle;
width: 15px;
}
.right .grouped-dots
{
background-color: #F5F5F5;
border-left: 1px solid #FFFFFF;
border-right: 1px solid #FFFFFF;
display: block;
height: 100%;
}
.cart-item .grouped-dots span::after
{
color: #CCCCCC;
content: '.';
font-family: 'Open Sans',sans-serif;
font-size: 40px;
line-height: 0;
}
This approach is using table and table-cells as display values. If you think I'm in the wrong path, please let me know.
It's because of this style:
.right .grouped-dots {
height: 100%;
}
Since its as tall as its parent, there's no room for it to move vertically to the "middle."
Remove that style, and move its background color to .right:
.right {
background-color: #F5F5F5;
}
Fiddle
http://s4.postimg.org/mbrpxn2d9/Untitled.png
Edit: Not a duplicate. The other question doesn't contain information about divs being automatically adjusted to the words on the inside.
I have 4 divs. I have 3 divs inside another div, and I'm trying to float one to the left, one to the center, and one to the right. I'm also trying to make the width and height of the divs on the inside to be automatically adjusted to the width and height of the words on the inside of the divs. I also want the divs on the inside to stack up on top of each other, instead of being on the same line. So far, I got the left div to float to the left, and the right div to float to the right, but I just cannot get the middle div to be centered, nor get it to adjust to the width and height of the word inside of it. Please take a look at my code:
#outer {
border: 1px solid black;
width: 500px;
height: 500px;
}
#innerLeft {
border: 1px solid red;
float: left;
}
#innerMiddle {
border: 1px solid red;
margin: auto;
}
#innerRight {
border: 1px solid red;
float: right;
}
<div id='outer'>
<div id='innerLeft'>Left</div>
<div id='innerMiddle'>Middle</div>
<div id='innerRight'>Right</div>
</div>
Depending on the output of the image, I think flexbox solution would be a good way to go.
Let the container have a flexible layout with column wrapping.
Align each item based on position in the container i.e. flex-start, center and flex-end
#outer {
display: flex;
display: -ms-flex;
flex-flow: column wrap; /* Wrap the items column wise */
justify-content: flex-start; /* Items to start from the top of the container */
border: 1px solid black;
width: 500px;
height: 500px;
}
#innerLeft {
align-self: flex-start; /* Equivalent to float: left of your code */
border: 1px solid red;
}
#innerMiddle {
align-self: center; /* Equivalent to margin: auto */
border: 1px solid red;
}
#innerRight {
align-self: flex-end; /* Equivalent to float: right */
border: 1px solid red;
}
<div id='outer'>
<div id='innerLeft'>Left</div>
<div id='innerMiddle'>Middle</div>
<div id='innerRight'>Right</div>
</div>
If changing your HTML just a bit is an option, you can add span elements in your divs which will give you want, and it will work in all browsers:
#outer {
border: 1px solid black;
width: 500px;
height: 500px;
}
#innerLeft {
text-align:left;
}
#innerMiddle {
text-align:center;
}
#innerRight {
text-align:right;
}
div > div > span {
border: 1px solid red;
}
<div id='outer'>
<div id='innerLeft'><span>Left</span></div>
<div id='innerMiddle'><span>Middle</span></div>
<div id='innerRight'><span>Right</span></div>
</div>
This is what you mean?? I had Edited
#outer {
border: 1px solid black;
width: 500px;
height: 500px;
}
#innerLeft {
border: 1px solid red;
/* width: 30%; */
float: left;
}
#innerMiddle {
border: 1px solid red;
float: left;
margin: 0 5px;
}
#innerRight {
border: 1px solid red;
float: right;
}
<div id='outer'>
<div id='innerLeft'>LeftLeftLeftLeft</div> <br>
<div id='innerMiddle'>MiddleMiddleMiddleMiddle</div> <br>
<div id='innerRight'>RightRightRightRight</div>
</div>
write your html tags like this hope it help!
<div id='outer'>
<div id='innerRight'>Right</div>
<div id='innerLeft'>Left</div>
<div id='innerMiddle'></div>
</div>
I'm trying to have something like this:
|--------------fixed width---------------|
Title1 .......................... value1
Title2 ................... another value
Another title ........ yet another value
Here is my html example code:
<div class="container">
<span class="left">Title</span>
<span class="center"> </span>
<span class="right">value</span>
</div>
And here my css:
.center {
text-align: center;
border-bottom: 1px dotted blue;
display: inline-block;
outerWidth: 100%;
}
.right {
display: block;
border: 1px dotted red;
float: right;
}
.left {
display: block;
text-align: right;
border: 1px dotted red;
margin-right: 0px;
float: left;
}
.container {
width: 200px;
border: 1px dotted red;
padding: 5px;
}
It's possible to make span "center" expand to fill the space between the other two span elements?
Code on jsfiddle: http://jsfiddle.net/XqHPh/
Thank you!
If you reorder your HTML, you can get a simple solution:
<div class="container">
<span class="left">Title</span>
<span class="right">value</span>
<span class="center"> </span>
</div>
Place the two floated elements ahead of the .center element. The .center element will be in regular content flow and wrap around the left and right content.
The CSS:
.center {
display: block;
border-bottom: 1px dotted blue;
overflow: auto;
position: relative;
top: -4px;
}
.right {
float: right;
margin-left: 10px;
}
.left {
float: left;
margin-right: 10px;
}
.container {
width: 200px;
border: 1px dotted red;
padding: 5px;
}
When you float an element, the display type computes to block, so no need to declare it.
Also, for .center, if you add overflow: auto, you constrain the block so it does not extend beyond the edges of the floated elements. As a result, your bottom border does not underline the title and value text.
Finally, you can add position: relative and move the .center up a few pixels to align the border closer to the baseline of the text.
Fiddle: http://jsfiddle.net/audetwebdesign/DPFYD/
for this you need to change the html structure like this
html
<div class="container">
<span class="left">Title</span>
<span class="right">value</span>
<span class="center"> </span>
</div>
and here is the css for .center span
.center {
text-align: center;
border-bottom: 1px dotted blue;
display:block;
}
jsFiddle File
Meanwhile Flexbox has full browser support, which allows for a more elegant solution without the center element.
.left, .right {
border: 1px dotted red;
}
.container {
display: flex;
justify-content: space-between;
width: 200px;
border: 1px dotted red;
padding: 5px;
}
<div class="container">
<span class="left">Title</span>
<span class="right">value</span>
</div>