As in the BEM methodology is better Nativity elements nested within elements
I have the following markup:
<table class="product-list">
<tr>
<th>Your Items</th>
<th>Price</th>
<th>Qty</th>
<th>Remove</th>
</tr>
<tr>
<div class="product-list__wrapper-img"><img src="./images/mini-cart/1.jpg"></div>
</tr>
</table>
I have a block .product-list, it has the element .product-list__wrapper-img , in it there is a picture <img src="./images/mini-cart/1.jpg">
Stylizing the block I put
.product-list{
width: 680px
}
.product-list__wrapper-img{
position:relative;
z-index:0;
width: 77px;
height: 90px
}
.product-list__wrapper-img img {
position: absolute
z-index: 1
top: 50%
left: 50%
transform: translate(-50%, -50%)
max-width: 98%
max-height: 98%
}
I know that seems to be in the BEM to the tags contact is not desirable, i.e., so seems to be impossible to write
.product-list__wrapper-img img{
}
But what when give the img class to style it, and whether in the BEM , to be the element in the element.
I know that modificator can but the element I know.
I guess I need to call this picture
.product-list__img maybe
.product-list__wrapper-img__img
I would be glad for any help in this matter.
imho:
<table class="product-list">
<tr>
<td>
<div class="product-list__wrapper-img">
<img class="product-list__img" src="./images/mini-cart/1.jpg">
</div>
</td>
</tr>
</table>
or:
<table class="product-list">
<tr>
<td class="product">
<div class="product__wrapper">
<img class="product__img" src="./images/mini-cart/1.jpg">
</div>
</td>
</tr>
</table>
Related
I'm struggling to set custom widths of div elements inside a table cell. Various questions (e.g.) talk about position and display parameters, and I've tried too many variation to describe without success. I'd greatly appreciate it if someone could either assist to get this minimal example working, or refer me to a specific previous answer that does actually solve this problem. Thanks in advance.
In the example I want to set the divs as horizontal bars to reflect the values. The table is fixed with and all div ancestors set to width: 100%.
.bar-column {
width: 100%;
}
.bar {
/* some other tested parameters.. */
/* position: absolute; */
/* display: block; float: left; */
/* display: table-cell; */
position: relative;
display: inline-block;
height: 100%;
background-color: yellow;
}
tr { width: 100%; }
<table width="600px" style="background-color: #ddd;">
<tr>
<th>Value</th>
<th class="bar-column">Name and bar</th>
</tr>
<tr>
<td>20</td>
<td class="bar-column">
<div width="50%" class="bar"><a class="link" href="#">twenty</a></div>
</td>
</tr>
<tr>
<td>40</td>
<td class="bar-column">
<div width="100%" class="bar"><a class="link" href="#">forty</a></div>
</td>
</tr>
<tr>
<td>10</td>
<td class="bar-column">
<div width="25%" class="bar"><a class="link" href="#">ten</a></div>
</td>
</tr>
</table>
The problem is using width="100%" for div when you need to use style="width:100%"
So for following line:
<div width="100%" class="bar"><a class="link" href="#">twenty</a></div>
Should be:
<div style="width:100%" class="bar"><a class="link" href="#">twenty</a></div>
Apply that for lines for the div containing 50% and 25%
I am having a hard time explaining in words what I am looking for, so here's an example:
http://jsfiddle.net/toaeb0zt/
<div style="width:800px ">
<div style="width:200px;height:500px; background:purple; float:left"></div>
<div style="width:200px;height:200px; background:blue; float:left"></div>
<div style="width:200px;height:200px; background:green; float:left"></div>
<div style="width:200px;height:400px; background:yellow; float:right"></div>
<div style="width:400px;height:200px; background:orange; float:left"></div>
<div style="width:200px;height:200px; background:brown; float:left"></div>
<div style="width:400px;height:200px; background:gray; float:left"></div>
<div style="width:200px;height:100px; background:red; float:left;"></div>
</div>
This layout was done with CSS combining left and right floats. I read about flexbox to see if it could do it, but seems like that's a negative.
I realize it could be done by nesting divs into bigger divs, but I need to make this responsive and this solution would make responsive a nightmare.
I have been trying to stay away from jQuery and deeper programming, but I understand it might be the best option. I appreciate this community's help; thank you in advance.
Would you are doing seems to me like a nightmare ! there are alot of libs out there that will help you get this grid together. A masonry grid would be the most aligned with your requirement.
masonry works by placing elements in optimal position based on available vertical space, sort of like a mason fitting stones in a wall. You’ve probably seen it in use all over the Internet.
I have used Isotope alot ! this is one of the many things you can do with Isotope:
http://codepen.io/desandro/pen/mEinp
$( function() {
$('.isotope').isotope({
layoutMode: 'fitColumns',
itemSelector: '.item'
});
});
study the website very carefully
http://isotope.metafizzy.co/
Hope this helps/ this solution will require JavaScript (and jQuery)
You could use a table of blocks and just color each one. You can do this using css and a simple table.
Here is a fiddle, http://jsfiddle.net/r3vycfa1/
I'm not positive what your looking for, but this will be more responsive.
The classes .a, .b, .c each have a different color and you can apply them to the blocks.
HTML
<table>
<tr>
<td class="a"> </td>
<td class="a"> </td>
<td class="b"> </td>
<td> </td>
</tr>
<tr>
<td class="a"> </td>
<td> </td>
<td class="b"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td class="b"> </td>
<td> </td>
</tr>
<tr>
<td class="c"> </td>
<td class="c"> </td>
<td class="c"> </td>
<td> </td>
</tr>
</table>
CSS:
* {
margin: 0;
padding: 0;
}
table {
width: 500px;
height: 500px;
border-spacing: 0px;
}
td {
width: 10%;
height: 10%;
}
.a {
background-color: #00FF00;
}
.b {
background-color: #FF0000;
}
.c {
background-color: #0000FF;
}
I searched a lot, but now want to ask because I found no answer:
If have two div elements that should be located next to each other with full width (each exactly 50% of the full width). It could be that the first or the second div is hidden (style="display=none"). In this case the other div should be displayed in full width.
My solution is this:
<table style="width: 100%;">
<tr>
<td style="padding: 0px;">
<div id="div1">
...
</div>
</td>
<td style="padding: 0px;">
<div id="div2">
...
</div>
</td>
</tr>
</table>
That works almost perfect, BUT when both divs are displayed the first one seems to be 55% and the second one 45% of the width.
If course I can set the width of the div when hiding the other to 100%, but I want to avoid doing that.
Does anyone have a solution to make them both 50% when both are displayed.
A JQuery approach with no tables
You can achieve this with JQuery (or plain javascript) which I am assuming you are using to show/hide the elements anyway.
$("#ButtonOne").click(function () {
$(".one").toggle();
if($(".one").is(":visible")){
$(".two").css("width", "50%");
}
else{
$(".two").css("width", "100%");
}
});
$("#ButtonTwo").click(function () {
$(".two").toggle();
if($(".two").is(":visible")){
$(".one").css("width", "50%");
}
else{
$(".one").css("width", "100%");
}
});
The above JQuery assumes two buttons for toggling the visibility of the elements.
Here is an example
With the example, it should be noted that using 50% width with inline-block requires zero whitespace in between the elements. Hence the </div><div... requirement.
You will need some vertical-align:top; aswell to ensure the DIV elements stay in line.
Incase the link ever breaks, here is the accompanying HTML...
<div class="main">
<div class="one">this is one</div><div class="two">this is two</div>
</div>
<input type="button" id="ButtonOne" value="Toggle one" />
<input type="button" id="ButtonTwo" value="Toggle two" />
...and CSS...
body{
margin:0;
padding:0;
}
div{
margin:0;
padding:0;
}
.one {
background-color:red;
height:100px;
width:50%;
display:inline-block;
}
.two {
background-color:blue;
height:100px;
width:50%;
display:inline-block;
}
Can you place both divs in the same table cell?
<table style="width: 100%;">
<tr>
<td>
<div id="div1">
...
</div>
<div id="div2">
...
</div>
</td>
</tr>
</table>
You could simply toggle a class....
table { width: 100%; padding:0; }
td { padding:0; margin:0; }
td > div { width: 50%; display: block; float: left; height: 50px; cursor: pointer; }
#div1 {background: #a00;}
#div2 {background: #00a;}
.wide {width: 100%;}
.hide { display: none;}
and the jquery...
$('div').click(function () {
$(this).toggleClass('wide');
$('div').not(this).toggleClass('hide');
});
DEMO HERE
Would work for multiple divs easily: demo 2
Use table-layout:fixed:
EDIT:
You have to set the display:none on the td, not on the div.
<table style="width: 100%; table-layout:fixed">
<tbody>
<tr>
<td style="padding: 0px; width:50%">
<div id="div1" style="border: 1px solid black">
This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text
</div>
</td>
<td style="padding: 0px; width:50%; display: none;">
<div id="div2" style="border: 1px solid black">
This isn't as long as the other text.
</div>
</td>
</tr>
</tbody>
</table>
I've tested it on Chrome, Firefox and IE10
ok guys,
thanks for your help. now i found what i was searching for:
<table style="width: 100%;">
<tr>
<td id="td1" style="padding: 0px; min-width:50%;">
<div>
...
</div>
</td>
<td id="td2" style="padding: 0px; min-width:50%;">
<div>
...
</div>
</td>
</tr>
</table>
both td tags are next to each other and both take exactly 50%. when hiding td1 or td2, the other td goes into full width automatically.
best regards...
You can achieve this by setting width in the td itself, and when you want to hide any one div just add "display:none;" in the specified td instead of the div, then the remaining div will have 100% width.
<table style="width: 100%;">
<tr>
<td style="padding: 0px; width:50%;">
<div id="div1" >
hii
</div>
</td>
<td style="padding: 0px;width:50%;">
<div id="div2" style="">
byyee
</div>
</td>
</tr>
</table>
Whats the best way to split up a table element <td>? I don't really want to use nested tables. I need the internal element to have two elements one that is left justified and the other to be right justified with no border.
For example:
<table>
<tr>
<td>LEFT, RIGHT</td>
</tr>
</table>
any other ways to do this besides the following?
<table>
<tr>
<td>LEFT</td>
<td>RIGHT</td>
</tr>
</table>
I want the internal element to be a <span> or whatever is best for this.
<table>
<tr>
<td>
<div style="float:left">LEFT</div><div style="float:right">RIGHT</div>
</td>
</tr>
</table>
I would do something like:
<td><div class="left>LEFT</div><div class="right">RIGHT</div></td>
then my css would resemble:
td{position: relative;}
td .left{position: absolute; text-align: left; left: 0;}
td .right{position: absolute; text-align: right; right: 0;}
... or something along those lines.
You could do it like this, although spans and divs are much better imo.
<table width="100%">
<tr width="100%">
<td width="100%">
<span style="float:left;">left</span>
<span style="float:right;">right</span>
</td>
</tr>
</table>
The floats didn't seem to look right so I used flexbox:
https://jsfiddle.net/6rc8w709/
.td-content{
display:flex;
}
.child{
flex:1;
}
.right{
text-align:right;
}
HTML:
<table>
<tr>
<td>
<div class="td-content">
<div class="child">
LEFT
</div>
<div class="child right">
RIGHT
</div>
</div>
</td>
</tr>
</table>
Flexbox is the right approach since it is now supported by all major browsers. This is an alternative approach if you need to target an older browsers or you don't like the drawbacks of floats. With this approach you can control the overflow of the left and right segment better and you can easily add a centered segment if you need one.
CSS:
table{
width: 100%;
}
.container{
width: 100%;
display: table;
}
.cell{
display: table-cell;
}
.cell .left{
text-align: left;
}
.cell.right{
text-align: right;
}
HTML:
<table>
<tr>
<td>
<div class="container">
<span class="cell left">LEFT</span>
<span class="cell right">RIGHT</span>
</div>
</td>
</tr>
</table>
I have a div in the html and after the Div and I have another div which contains the HTml table Which is coming on the top of div. How to bring the table down.
<div id='testupdate2' >Mynumber: ". $num." </div>
<div id="test">
<table cellspacing=0 cellpadding=0 border=0 width="100%">
<tbody>
<tr>
<td id="Header" class="navUPD">MY number</td>
</tr>
<tr>
<td id="tls" class="navUPD">MY DETAILS </td>
</tr>
<tr>
<td id="mgmnt" class="navOFFTDUPD"> ADDR. MGMT </td>
</tr>
</tbody>
</table>
</div>
How to bring the table down to the DIV?
To push your table off the top of your <div id="test"> you can use CSS padding:
#test {
padding-top: 20px;
}
Or alternatively:
#test table {
padding-top: 20px;
}
If you have something else in <div id="test"> except that table and you want to table be always aligned to bottom of the div, you can do something like this in your CSS
#id{
position: relative;
}
#id table{
position: absolute; /*this is absolute to #id not to body tag*/
bottom: 0px;
left: 0px;
}
This should do the job, I think (I didn't check it).