Two definition of the same item in the same div class - html

I need to use an item, in this case img, in the same div class but with different definitions.
Example:
section .row img {
margin: 0 0 30px;
width: 100%;
border: 4px solid #18a00e;
}
section .row img {
margin: 0 0 30px;
border: 4px solid #18a00e;
max-height: 300px;
}
How can I create and use this two definitions without the last one overwriting the former?
Thank you.
Later edit (for more info):
//this is the html code scenario 1 where I need the width: 100%//
<section class="container">
<div class="row">
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<img src="img/m3.jpg"/>
</figure>
</div>
</section>
//this is the html code for scenario 2, where I need max-height: 300px//
<section class="jumbotron">
<div class="unlockedl">
<div class="row">
<img src="img/pm1.jpg"/>
</div>
</div>
</section>

You have classes that you can use to uniquely target those elements. use .container and .jumbotron to target the .row img in those individual sections instead of the generic section element.
.container .row img {
margin: 0 0 30px;
width: 100%;
border: 4px solid #18a00e;
}
.jumbotron .row img {
margin: 0 0 30px;
border: 4px solid #18a00e;
max-height: 300px;
}
<section class="container">
<div class="row">
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<img src="img/m3.jpg" />
</figure>
</div>
</section>
<section class="jumbotron">
<div class="unlockedl">
<div class="row">
<img src="img/pm1.jpg" />
</div>
</div>
</section>
You can also use other unique classes/elements in those 2 blocks, like figure and .unlockedl
section figure img {
margin: 0 0 30px;
width: 100%;
border: 4px solid #18a00e;
}
section .unlockedl img {
margin: 0 0 30px;
border: 4px solid #18a00e;
max-height: 300px;
}
<section class="container">
<div class="row">
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<img src="img/m3.jpg" />
</figure>
</div>
</section>
<section class="jumbotron">
<div class="unlockedl">
<div class="row">
<img src="img/pm1.jpg" />
</div>
</div>
</section>
Or you can use :nth-child() to target individual sections
section:nth-child(1) .row img {
margin: 0 0 30px;
width: 100%;
border: 4px solid #18a00e;
}
section:nth-child(2) .row img {
margin: 0 0 30px;
border: 4px solid #18a00e;
max-height: 300px;
}
<section class="container">
<div class="row">
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<img src="img/m3.jpg" />
</figure>
</div>
</section>
<section class="jumbotron">
<div class="unlockedl">
<div class="row">
<img src="img/pm1.jpg" />
</div>
</div>
</section>

You should assign an unique id and assign the css to the distinct id
<div id ='id1' class='same_class'> </div>
<div id='id2' class='same_class'> </div>
#id1 {
width: 100%;
}
#id2 {
max-height: 300px;
}
.same_class{
margin: 0 0 30px;
border: 4px solid #18a00e;
}

Related

same img size in a row /// col-8 <-> col-4

I am absolute newbee and wanna create 2 rows. One with 2 img col-4 size and col-8 size and the other row à 3 x col-4 size.
My problem is that the col-8 img is a little bit bigger (height) then the col-4 img.
How can I fix it? I tried a lot but nothing worked.
Thanks for your help.
[problem
.col-4 {
padding-left: 5px;
padding-right: 5px;
}
.col-8 {
padding-left: 5px;
padding-right: 5px;
}
.x1 {
border: 1px solid black;
}
.x2 {
border: 1px solid black;
}
.x1_pic {
width: 100%;
height: auto;
position: relative;
}
.x2_pic {
width: 100%;
height: auto;
position: relative;
}
.x1_header {
position: absolute;
margin-top: -95%;
text-align: center;
}
.x2_header {
position: absolute;
margin-top: -95%;
text-align: center;
}
<div class="container">
<div class="row">
<div class="col-4">
<div class="x1">
<img class="x1_pic" src="./img/header-background.jpg">
</div>
</div>
<div class="col-8">
<div class="x2">
<img class="x2_pic" src="./img/maschine_2.jpg">
</div>
</div>
</div>
<div class="row">
<div class="col-4">
<div class="x1">
<img class="x1_pic" src="./img/header-background.jpg">
</div>
</div>
<div class="col-4">
<div class="x1">
<img class="x1_pic" src="./img/header-background.jpg">
</div>
</div>
<div class="col-4">
<div class="x1">
<img class="x1_pic" src="./img/header-background.jpg">
</div>
</div>
</div>
</div>
]1

How can i put 3 divs side by side with a margin and a border?

I'm trying to put three divs side by side which works fine but when i add a border and a small gap between each div the 3rd div goes onto a new line. Is there a way to auto resize the divs so they fit?
HTML:
<div class="trendingContainer">
<div class="col-lg-4 trendingBox">
<div class="block-title"><h3>Trending</h3> </div>
123
</div>
<div class="col-lg-4 trendingBox hidden-sm hidden-xs">
<div class="block-title"><h3>Trending</h3> </div>
123
</div>
<div class="col-lg-4 trendingBox hidden-sm hidden-xs">
<div class="block-title"><h3>Trending</h3> </div>
123
</div>
</div>
CSS:
.trendingContainer {
margin: 0 auto;
}
.trendingBox {
border: 1px solid #e5e5e5;
background: #fff;
margin: 0 2px 0 0;
}
You can always use calc and percentage based widths:
.trendingBox {
border: 1px solid #e5e5e5;
background: #fff;
margin: 0 2px 0 0;
width: calc(100% / 3 - 4px);
}
If you want to support multiple browser widths separately you can use media queries:
#media(max-width: 600px) {
.trendingBox {
border: 1px solid #e5e5e5;
background: #fff;
margin: 0 2px 0 0;
width: calc(100% / 2 - 4px);
}
}
#media(min-width: 601px) {
.trendingBox {
border: 1px solid #e5e5e5;
background: #fff;
margin: 0 2px 0 0;
width: calc(100% / 3 - 4px);
}
}
You can use either float or flex model, but make sure you have border-box set. And when you are using margin along with a fixed layout like this, ensure the widths correctly:
* {
box-sizing: border-box;
}
.trendingContainer {
margin: 0 auto;
overflow: hidden;
}
.trendingBox {
border: 1px solid #e5e5e5;
background: #fff;
float: left;
width: 30%;
margin: 0 0.5%
}
<div class="trendingContainer">
<div class="col-lg-4 trendingBox">
<div class="block-title">
<h3>Trending</h3>
</div>
123
</div>
<div class="col-lg-4 trendingBox hidden-sm hidden-xs">
<div class="block-title">
<h3>Trending</h3>
</div>
123
</div>
<div class="col-lg-4 trendingBox hidden-sm hidden-xs">
<div class="block-title">
<h3>Trending</h3>
</div>
123
</div>
</div>
Preview
One more try, this time totally different, added a child DIV to specify the content with margin and border:
(This maintains the original sizing and other bootstrap stuff, only defines the additional styling on a separate div, which is more clean to use)
HTML:
<div class="trendingContainer">
<div class="col-lg-4 trendingBox">
<div class="trendingBox-content">
<div class="block-title"><h3>Trending</h3> </div>
123
</div>
</div>
<div class="col-lg-4 trendingBox hidden-sm hidden-xs">
<div class="trendingBox-content">
<div class="block-title"><h3>Trending</h3> </div>
123
</div>
</div>
<div class="col-lg-4 trendingBox hidden-sm hidden-xs">
<div class="trendingBox-content">
<div class="block-title"><h3>Trending</h3> </div>
123
</div>
</div>
</div>
CSS:
.trendingContainer {
margin: 0 auto;
}
.trendingBox {
/* Add other style here */
}
.trendingBox-content{
border: 1px solid #e5e5e5;
margin: 0 2px 0 0;
background: #fff;
}
You can try this.
.trendingContainer {
margin: 0 auto;
}
.trendingBox {
border: 1px solid #e5e5e5;
display: inline-block;
position: relative;
float: left;
background: #fff;
margin: 0 2px 0 0;
}
<div class="trendingContainer">
<div class="col-lg-4 trendingBox">
<div class="block-title"><h3>Trending</h3> </div>
123
</div>
<div class="col-lg-4 trendingBox hidden-sm hidden-xs">
<div class="block-title"><h3>Trending Big</h3> </div>
123
</div>
<div class="col-lg-4 trendingBox hidden-sm hidden-xs">
<div class="block-title"><h3>Trending</h3> </div>
123
</div>
</div>
.trendingBox {
border: 1px solid #e5e5e5;
background: #fff;
margin: 0 2px 0 0;
display: inline-block;
float: left;
width: calc(33.3% - 4px);
}
calc is new in css3 I believe.
4px is 2px(margin) + 2*1px(border)
Another thing you can try is using outline. I believe its width would is considered as a port of the box element, haven't tried though.
I believe rest all is clear
.trendingBox {
border: 1px solid #e5e5e5;
background: #fff;
margin: 0 2px 0 0;
box-sizing: border-box;
}
The box-sizing: border-box; does the trick. This makes sure the div doesn't resize when adding padding to it.
EDIT: See my other answer, which is the right way to do it in my opinion.

Bootstrap Add Space between Columns

I have closely followed the most popular example of how to add space between columns, but it doesn't work. You can view it in action at
codepen.io
What I've done is put a col-sm-12 inside of a col-sm-4 for each column. According to the most popular answer here this should automatically render some space between the 2 divs.
HTML:
<div class="row blocks-grid">
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
</div>
CSS:
body {
background: #BEB7A4;
}
.blocks-grid {
max-width:75.0rem;
margin:0 auto;
.item {
cursor: pointer;
margin-bottom:1rem;
position:relative;
height:34.0rem;
padding-top:2.5rem;
background:#FFFFFC;
&:hover {
background:#FF0000;
color:white;
img {
display:none;
}
}
h2 {
font-size:2.0rem;
margin-top:1rem;
text-align: center;
}
img {
max-width: 100%;
margin:auto;
display:block;
}
}
}
Basically, I would think the result would look like the following photo, but it does not:
you can try this: Demo
Add your "item" class with "col-sm-12"
body {
background: #BEB7A4;
}
I made some changes on your code.
HTML
Note the subitem class added to col-sm-12 divs.
<div class="row blocks-grid">
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
</div>
LESS
body {
background: #BEB7A4;
}
.blocks-grid {
max-width:75.0rem;
margin:0 auto;
.item {
cursor: pointer;
margin-bottom:1rem;
position:relative;
height:34.0rem;
padding-top:2.5rem;
.subitem {
background:#FFFFFC;
height: 100%;
padding-top: 50px;
&:hover {
background:#FF0000;
color:white;
img {
display:none;
}
}
h2 {
font-size:2.0rem;
margin-top:1rem;
text-align: center;
}
img {
max-width: 100%;
margin:auto;
display:block;
}
}
}
}
Take a look: http://codepen.io/anon/pen/KgzVRK
Hope it can helps you.
You can actually remove all the extra junk and let bootstrap do it for you... NEVER change margins / widths on the framework. This is all you need....
HTML
<div class="row">
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x250">
<h2>This is me</h2>
</div>
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x150">
<h2>This is me</h2>
</div>
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x150">
<h2>This is me</h2>
</div>
</div>
CSS
img { width: 100%; }
You may try to move the class item from col-xs-6 to col-sm-12
The snippet:
body {
background: #BEB7A4;
}
.blocks-grid {
max-width: 75.0rem;
margin: 0 auto;
}
.blocks-grid .item {
cursor: pointer;
margin-bottom: 1rem;
position: relative;
height: 34.0rem;
padding-top: 2.5rem;
background: #FFFFFC;
}
.blocks-grid .item:hover {
background: #FF0000;
color: white;
}
.blocks-grid .item:hover img {
display: none;
}
.blocks-grid .item h2 {
font-size: 2.0rem;
margin-top: 1rem;
text-align: center;
}
.blocks-grid .item img {
max-width: 100%;
margin: auto;
display: block;
}
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>
<style>
body {
background: #BEB7A4;
}
.blocks-grid {
max-width: 75.0rem;
margin: 0 auto;
}
.blocks-grid .item {
cursor: pointer;
margin-bottom: 1rem;
position: relative;
height: 34.0rem;
padding-top: 2.5rem;
background: #FFFFFC;
}
.blocks-grid .item:hover {
background: #FF0000;
color: white;
}
.blocks-grid .item:hover img {
display: none;
}
.blocks-grid .item h2 {
font-size: 2.0rem;
margin-top: 1rem;
text-align: center;
}
.blocks-grid .item img {
max-width: 100%;
margin: auto;
display: block;
}
</style>
</head>
<body>
<div class="row blocks-grid">
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
</div>
</body>

How to place the same image at the top and at the bottom of the same column?

So the title pretty much explains my problem. For now, I have my image placed at the top of the column and at the same time I need it to be at the bottom. How can I do this?
My Codepen
HTML
<div class="content">
<div class="row">
<div class="col-md-10 first-column"></div>
<div class="col-md-2 back-to-blog">
<a href="/">
<img class="img-responsive" src="https://api.asm.skype.com/v1/objects/0-neu-d1-6d077751650ba9cb23f065b16e4d4581/views/imgpsh_fullsize">
</a>
</div>
</div>
</div>
</div>
CSS
.content {
padding: 0 35px;
}
.first-column {
border: 1px solid;
height: 200px;
}
Flexbox can do that:
.content {
padding: 0 35px;
}
.row {
display: flex; /* columns now equal height */
}
.first-column {
border: 1px solid;
height: 200px;
flex: 10; /* replicates md-10 */
}
.back-to-blog {
flex: 2; /* replicates md-2 */
display: flex;
flex-direction: column; /* sets directionality */
justify-content: space-between; /* separates elements across direction */
}
a {
display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="content">
<div class="row">
<div class="col-md-10 first-column"></div>
<div class="col-md-2 back-to-blog">
<a href="/">
<img class="img-responsive" src="http://lorempixel.com/image_output/abstract-q-c-25-25-3.jpg">
</a>
<a href="/">
<img class="img-responsive" src="http://lorempixel.com/image_output/abstract-q-c-25-25-3.jpg">
</a>
</div>
</div>
</div>
</div>
Here is another way if you want to stick into Bootstrap column classes:
HTML:
<div class="content">
<div class="row">
<div class="col-xs-2 col-sm-10 col-md-10 first-column">aaa</div>
<div class="col-xs-2 col-sm-2 col-md-2 back-to-blog">
<img class="img-responsive" src="https://api.asm.skype.com/v1/objects/0-neu-d1-6d077751650ba9cb23f065b16e4d4581/views/imgpsh_fullsize">
<img class="img-responsive" src="https://api.asm.skype.com/v1/objects/0-neu-d1-6d077751650ba9cb23f065b16e4d4581/views/imgpsh_fullsize">
</div>
</div>
</div>
</div>
CSS:
.content {
padding: 0 35px;
}
.first-column {
border: 1px solid;
height: 200px;
}
.back-to-blog{
height: 200px;
}
.btm-link{
position: absolute;
bottom: 0;
}
Codepen:
http://codepen.io/anon/pen/xZyGoQ

Bootstrap div with an image next another div

I'm trying to do the next thing:
so I tried it by:
http://jsfiddle.net/7ewrM/22/
<div class="container">
<div class="row-fluid">
<div class="col-xs-4">
<div class='img-container'>
<img src='http://graph.facebook.com/112845672063384/picture?type=square' />
<div class='img-text'>Mark zuckerberg</div>
</div>
</div>
<div class="col-xs-8">
some text
</div>
</div>
</div>
Any help appreciated!
.container {
border: 1px solid red;
padding: 0;
}
.img-container{
padding: 0 10px;
}
.imggg {
display: inline-block;
width: 25%;
padding: 10px;
border-right: 1px solid red;
}
.text {
width: 70%;
display: inline-block;
}
.marc-zuckerberg{
border-top: 1px solid red;
width: 100%
display:inline-block;
}
<div class="container">
<div class='img-container'>
<div class="imggg">
<img src='http://graph.facebook.com/112845672063384/picture?type=square' />
</div>
<div class='text'>text</div>
</div>
<div class='marc-zuckerberg'>Mark zuckerberg</div>
</div>
Here you go: http://jsfiddle.net/7ewrM/24/