I've an issue at my project. At one of my page, I'm using a markup like this:
<div class="row">
<div class="col-md-6">
<h2>Step 1</h2>
<p>Some text</p>
<p>Some text</p>
<h2>Step 3</h2>
<p>Some text</p>
<p>Some text</p>
</div>
<div class="col-md-6">
<h2>Step 2</h2>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
Fiddle: http://jsfiddle.net/learner73/RW747/
So, it'll look like this at desktop:
But, it looks at mobile like this:
It should be like that as bootstrap's responsive layout. No doubt with that. But, definitely, I need step 1, 2 and 3 in serial (not step 1, 3, 2) at mobile:
This will be generated if I arranged my HTML code like this:
<div class="row">
<div class="col-md-6">
<h2>Step 1</h2>
<p>Some text</p>
<p>Some text</p>
</div>
<div class="col-md-6">
<h2>Step 2</h2>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h2>Step 3</h2>
<p>Some text</p>
<p>Some text</p>
</div>
<div class="col-md-6">
</div>
</div>
Fiddle: http://jsfiddle.net/learner73/gLjG4/
Now, at mobile, it looks perfect. But, at problem is at the desktop, if the height of "step 2" content is high, it push the "step 3" content below much:
But, it should be like my first image.
Have bootstrap classes or event to handle scenario like this? If not how can I handle this issue properly? Thanks in advance.
Try offsett or column ordering classes.
Now i've tested column responsive reset, it works for your intent
<div class="row">
<div class="col-md-6">
<h2>Step 1</h2>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
</div>
<div class="col-md-6">
<h2>Step 2</h2>
<p>Some text</p>
<p>Some text</p>
</div>
<!-- reset -->
<div class="clearfix visible-md"></div>
<!-- reset -->
<div class="col-md-6">
<h2>Step 3</h2>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
here the fiddle http://jsfiddle.net/keypaul/9nh86/
You can style it better, but here is an approach using jQuery
Basically, I've splited it into independent divs named "one", "two" and "three", and used this:
$(window).resize(function() {
winWidth = $(window).width();
winHeight = $(window).height();
if(winWidth <= 986) {
$("#two").insertBefore("#three");
} else {
$("#three").insertBefore("#two");
}
});
http://jsfiddle.net/XF6Uq/3/
Here you have another approach. Instead of using insertBefore, I'm using classes.
Basicaly, you float left every div, but the "Step 2" one, you change it to float right when it's "desktop wide"
http://jsfiddle.net/hige/3TPec/
Hope it helps!
Related
I am creating a new react website while I am trying to create cards on the home page after 100vh of height the background color is not showing up?
.Home {
background: #121212;
color: #b9b9b9;
height: 100vh;
width: 100%;
}
<div className="Home">
<TopBar />
<SearchBar />
<div className="container">
<div className="row">
<div className="column">
<div className="card">
<h3>Card 1</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div className="column">
<div className="card">
<h3>Card 2</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div className="column">
<div className="card">
<h3>Card 3</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div className="column">
<div className="card">
<h3>Card 4</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
</div>
</div>
</div>
Here is the image of this, please help me solve this problem
The body of the index.html has a margin of 8px.
Add this to your main stylesheet:
body {
margin: 0;
}
I can't see the image, but I think this is the problem.
If the "Home" component has a parent with flex or inline display, and the background is not going to move (i.e. changing your card with an animation.)
You can set the .Home style like this:
.Home{
position: fixed;
top: 0;
left: 0;
background: #121212;
color: #b9b9b9;
width: 100vw; //Remember to use 100vw instead of 100% for the width
min-height: 100vh;
}
Easy way to achive this is setting body and html to height: 100vh.
Also I changed className instead of class since this question is not related with react.js.
body, html {
background-color: #121212;
height: 100vh;
}
.Home {
color: #b9b9b9;
width: 100%;
}
<div class="Home">
<TopBar />
<SearchBar />
<div class="container">
<div class="row">
<div class="column">
<div class="card">
<h3>Card 1</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 2</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 3</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 4</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
</div>
</div>
</div>
i am writing a bootstrap code, inside columns i have defined div with background color but, background color roll till content only and due to data variation so, it look uneven data some columns taller and some smaller. I opted this approach because i need spacing between columns so, that it should look like cards with rounded edges. how can i have same height of column.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xl-2">
<div class="rounded" style="background-color:aqua">
<span>some text here</span>
</div>
</div>
<div class="col-xl-2">
<div class="rounded" style="background-color:pink">
<span>some text here</span>
<p>some more text</p>
<p>some more text</p>
</div>
</div>
<div class="col-xl-2">
<div class="rounded" style="background-color:green">
<span>some text here</span>
<p>some more text here</p>
<h5>extra work</h5>
</div>
</div>
</div>
</div>
Basically this is a duplicate.
The columns are the same height because Bootstrap 4 uses flexbox. Just add h-100 (height:100%) to the rounded containers to that the fill the height of the columns.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="rounded h-100" style="background-color:aqua">
<span>some text here</span>
</div>
</div>
<div class="col">
<div class="rounded h-100" style="background-color:pink">
<span>some text here</span>
<p>some more text</p>
<p>some more text</p>
</div>
</div>
<div class="col">
<div class="rounded h-100" style="background-color:green">
<span>some text here</span>
<p>some more text here</p>
<h5>extra work</h5>
</div>
</div>
</div>
</div>
From what I understand of your problem, you want all the .col to be the same height...
Adding CSS property of height: 150px; (enter whatever size you'd like) to the .col. However, if you want the background to be the entire background of the .col, you need to move that to that .col div element (where I put blue and orange).
P.S. the blue and orange is just to show you the height of each .col
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xl-2" style="height: 150px; background-color: orange;">
<div class="rounded" style="background-color:aqua">
<span>some text here</span>
</div>
</div>
<div class="col-xl-2" style="height: 150px; background-color: blue;">
<div class="rounded" style="background-color:pink">
<span>some text here</span>
<p>some more text</p>
<p>some more text</p>
</div>
</div>
<div class="col-xl-2" style="height: 150px; background-color: orange;">
<div class="rounded" style="background-color:green">
<span>some text here</span>
<p>some more text here</p>
<h5>extra work</h5>
</div>
</div>
</div>
</div>
This question already has answers here:
Align child elements of different blocks
(3 answers)
Closed 3 years ago.
Here is example code of what I have:
The CSS:
<style>
* {
box-sizing: border-box;
}
/* Create four equal columns that floats next to each other */
.column {
float: left;
width: 25%;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>
The Code:
<h2>Four Equal Columns</h2>
<div class="row">
<div class="column" style="background-color:#aaa;">
<h2>Column 1</h2>
<p>Some text..</p>
<p>Some text..</p>
</div>
<div class="column" style="background-color:#bbb;">
<h2>Column 2</h2>
<p>Some text..</p>
</div>
<div class="column" style="background-color:#ccc;">
<h2>Column 3</h2>
<p>Some text..</p>
<p>Some text..</p>
<p>Some text..</p>
<p>Some text..</p>
</div>
<div class="column" style="background-color:#ddd;">
<h2>Column 4</h2>
<p>Some text..</p>
<p>Some text..</p>
<p>Some text..</p>
</div>
</div>
This is what I don't want:
<div class="row">
<div class="column" style="background-color:#aaa;">
<h2>Column 1</h2>
<h2>Column 1</h2>
<p>Some text..</p>
<p>Some text..</p>
</div>
<div class="column" style="background-color:#bbb;">
<h2>Column 2</h2>
<p>Some text..</p>
</div>
When you add more titles (h2 tags) into the box, it'll push the text down in that box but the other boxes remain the same. This renders everything uneven, meaning, if there's more text in one box then makes all of the other boxes look weird.
How do I make it so that if one box has a longer title that the other text in the other four boxes will move down their contents to match the height of the box with the most text?
Like this:
example of what I want
I would prefer to do this using only HTML/CSS.
Take advantage of flexbox and margin-top: auto; for the bottom element, like so:
.container {
display: flex;
justify-content: center;
}
.box {
display: flex;
flex-direction: column;
margin: 20px;
background: rgba(0, 0, 0, .3);
padding: 20px;
}
.text {
margin-top: auto;
}
<div class="container">
<div class="box">
<h1 class="title">Title 1</h1>
<h1 class="title">Title 2</h1>
<p class="text">Some text some text some text</p>
</div>
<div class="box">
<h1 class="title">Title 1</h1>
<p class="text">Some text some text some text</p>
</div>
<div class="box">
<h1 class="title">Title 1</h1>
<p class="text">Some text some text some text</p>
</div>
<div class="box">
<h1 class="title">Title 1</h1>
<p class="text">Some text some text some text</p>
</div>
</div>
I have a page with some bootstrap wells: http://jsfiddle.net/LmwbkLo6/
<div style="margin:15px;">
<br>
<div class="well">
<div class="col-sm-8">
<h4>Test Title</h4>
<p>Some test text</p>
<p>More text..</p>
</div>
<div class="col-sm-4">
</div>
<p>And Some Text Here
<p>
</div>
</div>
Im having an issue with the content overflowing the parent containers.
For Example, the content here is overflowing the Well div. I can "fix" this by adding class="col-xs-12" to the Well Div, but then the div itself will overflow the outer div.
Does anyone have any Ideas?
You need to wrap your class="col-* divs in <div class="row"></div> or it will not apply the negative margin.
Here is how it should look like.
<div style="margin:15px;">
<br>
<div class="container-fluid">
<div class="row">
<div class="well">
<div class="col-sm-8">
<h4>Test Title</h4>
<p>Some test text</p>
<p>More text..</p>
</div>
<div class="col-sm-4">
</div>
<p>And Some Text Here<p>
<p>And Some Text Here<p>
<p>And Some Text Here<p>
<p>And Some Text Here<p>
</div>
</div>
</div>
</div>
I have a div with width:500px and height:300px in the middle of a page.
I want inside this div to have my navbar-fixed-top.
Can you please correct my html/css to accomplish that?
Thanks
http://jsfiddle.net/MgcDU/7874/
<div class="container" style="width:500px;height:300px;border:solid black 1px;overflow:scroll">
<div class="row">
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar-inner" style="padding:10px">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" style="height:70px;" data-toggle="dropdown">
<div class="icon-some"></div>Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Dropdown link
</li>
<li>Dropdown link
</li>
</ul>
</div>
</div>
</nav>
</div>
<div id="wrapper">
<div id="content">
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
<p>some content</p>
</div>
<div id="padding-bottom"></div>
</div>
</div>
Based on what you said you want the nav bar with the class navbar-fixed-top to be inside the div, it seems simple enough.
All I did was add a position:relative to the css file for the .navbar class
.navbar{
position:relative;
}
Here is it working
http://jsfiddle.net/tKCm6/
Now if you wanted the nav to stay fixed in the div as you scroll down the page thats a different story.
Here is the code for that
.container{
position:absolute;
}
.navbar{
position:fixed;
width:500px;
}
and live
http://jsfiddle.net/vARTv/