I already tried using align-self: flex-start, but nothing happened. I got the main flex container on the right of my page (flex-direction: column), and now I want one block of my flex columns to be sticky once I scrolled down to them. I wrapped a container around the flex columns I want to be sticky, and I gave that container the position sticky. I will just post a snippet of my HTML and CSS, so it won't become too long of a code. I commented next to the code where my columns are and what each container does:
.rightside_container {
display: flex;
flex-direction: column;
gap: 0px;
margin-top: 60px;
right: 17%;
position: absolute;
z-index: 0;
border-radius: 10px;
background-color: black;
padding-left: 0px;
padding-right: 20px;
padding-top: 8px;
padding-bottom: 8px;
}
.sticky_container {
border: 1px solid white;
position: sticky;
top: 0px;
}
<div class="rightside_container">
<!--big main container-->
<div class="sticky_container">
<!--since I want a few of my columns to be sticky, I wrapped
a little div container around them which I gave the position sticky-->
<div class="follow_flex">
<!--COLUMN 1-->
<div class="follow_pic_container">
<img src="thumbnails/twitterlogo.jpg" class="follow_pic">
</div>
<div class="follow_text_container">
<div class="follow_name">Twitter</div>
<div class="follow_at">#Twitter</div>
</div>
<div class="follow_button_container">
<button class="follow_button">Follow</button>
</div>
</div>
<div class="follow_flex">
<!--COLUMN 2-->
<div class="follow_pic_container">
<img src="thumbnails/youtubelogo.jpg" class="follow_pic">
</div>
<div class="follow_text_container">
<div class="follow_name">YouTube</div>
<div class="follow_at">#YouTube</div>
</div>
<div class="follow_button_container">
<button class="follow_button">Follow</button>
</div>
</div>
</div>
</div>
I think that the code portion that you provide is not enough, but in your snippet if you set a height (for testing purposes) and remove the margin it does the sticky effect. You need to consider that if you got any parent with overflow: hidden sticky position is not going to work.
.rightside_container {
display: flex;
flex-direction: column;
gap: 0px;
right: 17%;
position: absolute;
z-index: 0;
border-radius: 10px;
background-color: black;
padding-left: 0px;
padding-right: 20px;
padding-top: 8px;
padding-bottom: 8px;
height: 600px;
}
.sticky_container {
border: 1px solid white;
position: sticky;
top: 0px;
}
<div class="rightside_container"> <!--big main container-->
<div class="sticky_container"> <!--since I want a few of my columns to be sticky, I wrapped
a little div container around them which I gave the position sticky-->
<div class="follow_flex"> <!--COLUMN 1-->
<div class="follow_pic_container">
<img src="thumbnails/twitterlogo.jpg" class="follow_pic">
</div>
<div class="follow_text_container">
<div class="follow_name">Twitter</div>
<div class="follow_at">#Twitter</div>
</div>
<div class="follow_button_container">
<button class="follow_button">Follow</button>
</div>
</div>
<div class="follow_flex"> <!--COLUMN 2-->
<div class="follow_pic_container">
<img src="thumbnails/youtubelogo.jpg" class="follow_pic">
</div>
<div class="follow_text_container">
<div class="follow_name">YouTube</div>
<div class="follow_at">#YouTube</div>
</div>
<div class="follow_button_container">
<button class="follow_button">Follow</button>
</div>
</div>
</div>
</div>
Related
I want to position a div according to the picture:
I'm successful so far by using Bootstrap's row class and using z-index in my CSS. But when I resize the browser, it's not responsive, it just floats off the right side of the page. By the way, I'm using position: absolute (I read online that I have to use this in order to make use of z-index). Is there any other more elegant way to do this? I want it to be responsive but can't seem to find any other workaround than the wonky one I implemented.
Code:
#div2 {
float: inherit;
position: absolute;
top: inherit;
left: 60%;
width: 320px;
height: 1290px;
z-index: 5;
}
<div class="container">
<div class="div-container">
<div class="row">
<div id="div1">
<p>Div 1</p>
</div>
<div id="div2" align='center'>
<p>Div 2</p>
</div>
</div>
<div class="row">
<div id="div3">
<p>Div 3</p>
</div>
</div>
</div>
</div>
You need to make use of the nested rows inside a column. See here - Bootstrap Nesting. Ignore the CSS here as it is for snippet styling and height is used for ignoring the content.
.B {
min-height: 130px;
background: #393276;
margin-bottom: 20px;
}
.A {
min-height: 100px;
margin-bottom: 20px;
background: #393276;
}
.C {
min-height: 250px;
background: #393276;
}
div {
text-align: center;
color: #fff;
font-size: 32px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container mt-4">
<div class="row">
<!-- First Column -->
<div class="col-sm-6">
<!--Rows nested inside a column-->
<div class="row">
<div class="col-12">
<div class="A">A</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="B">B</div>
</div>
</div>
</div>
<!-- Second Column -->
<div class="col-sm-6">
<div class="C">C</div>
</div>
</div>
</div>
I have used flexbox to keep responsive design and some margin positioning to keep the formation together.
.container{
display: flex;
flex-wrap: wrap;
width: 150px;
}
.div1, .div3{
margin-right: 5px;
width: 50px;
height: 50px;
}
.div2{
margin-right: 5px;
width: 50px;
height: 110px;
}
<div class="container">
<div class="div1"> div1 </div>
<div class="div2"> div2 </div>
<br/>
<div class="div3" style="margin-top: -55px;"> div 3 </div>
</div>
This is how it looks so far:
And this is what I need to achieve:
<section class="section sub-masthead--TC2"></section>
<section class="section qualifiers--Q1"></section>
The first <section class=sub-masthead--TC2> element contains the image in some nested divs. With the design above is very clear what I need. I already set position: relative to both sections and z-index: 1 to the upper section and z-index: 3 to the down one but it doesn't work.
This is the whole HTML for the section that contains the image:
<section class="section sub-masthead--TC2">
<div class="sub-masthead__wrapper">
<div class="sub-masthead__tiles">
<div class="sub-masthead-item">
<div class="sub-masthead-item__content">
<div class="sub-masthead-item__copy">
<p><!-- text --></p>
</div>
</div>
<div class="sub-masthead-item__image-container">
<!-- IMAGE HERE -->
<img class="sub-masthead-item__image" src="assets/images/bg_phone-unique.png" alt="" role="img">
</div>
</div>
</div>
</div>
</section>
Here is my try. I have created an example for you to follow along.
First add position: relative to the parent element of both sections or if there is none then the body.
Then add position absolute to image section and manipulate top values.
.sub-masthead--TC2 {
position: absolute;
top: 40px;
right: 0;
}
Result:
.wrapperDiv {
position: relative;
}
.sub-masthead--TC2 {
width: 100%;
height: 100px;
background-color: tomato;
}
.qualifiers--Q1{
width: 300px;
height: 300px;
position: absolute;
top: 40px;
right: 0;
border: 1px solid #000;
padding: 20px;
}
img{
width: 100%;
height: auto;
}
<div class ="wrapperDiv">
<section class="section sub-masthead--TC2"></section>
<section class="section qualifiers--Q1">
<img src="https://placeimg.com/640/480/any" />
</section>
</div>
How can I align div element at the bottom of parent element while using bootstrap col?
.wrapper {
background-color: green;
height: 200px;
}
.bottom {
position: relative;
}
.bottom-div {
height: 200px;
position: absolute;
bottom: 0;
}
<div class="wrapper">
<div class="col-md-3 bottom">
<div class="bottom-div"> TEST1 </div>
</div>
<div class="col-md-6">
TEST2
</div>
<div class="col-md-3">
TEST3
</div>
</div>
bottom div element does not align at bottom. What is correct way of doing this? Thanks.
UPDATE: Div element runs out of wrapper (it basically moves up)
Not sure exactly what you're trying to do, as #CBroe said flexbox would be the best way but try this:-
/* CSS used here will be applied after bootstrap.css */
.wrapper{
background-color:green;
height: 200px;
position: relative;
}
.bottom-div{
height: 50px;
width: 50px;
position: absolute;
bottom:0;
left: 0;
background-color: red;
}
.testclass {
height: 100%;
}
<div class="wrapper">
<div class="col-md-3 testclass">
<div class="bottom-div"> TEST1 </div>
</div>
<div class="col-md-6">
TEST2
</div>
<div class="col-md-3">
TEST3
</div>
</div>
http://i.imgur.com/Veauoig.png
I am currently trying to work out how to make the 'From £' text to keep in the same position as the buttons above. The page is responsive so I have been unable to keep the text in one position.
The CSS I have used so far -
element.style {position: absolute; width: 97%;}
I put each of the 'From £' parts in their own class. Not sure if there is an easier way?
<div class="price2">From £300</div>
Any help would be great. Thanks!
Add a container for the element for the price and button so that they remain in context with each other.
http://jsfiddle.net/05orkj1a/
.prices{
width: 100%;
}
.price-column{
display: table-cell;
width: 33%;
text-align: center;
margin: 0 auto;
padding: 0 5px;
}
<div class="prices">
<div class="price-column">
<button>Bass</button>
<div class="price2">From £65</div>
</div>
<div class="price-column">
<button>Mid</button>
<div class="price2">From £300</div>
</div>
<div class="price-column">
<button>Treble</button>
<div class="price2">From £715</div>
</div>
</div>
You could also Float the columns left to cause them to collapse vertically as the screen shrinks with the same html. Just change the margin or padding depending on how far apart you want them spaced
http://jsfiddle.net/z6agt11e/
.prices{
width: 100%;
overflow: hidden;
}
.price-column{
display: block;
float: left;
text-align: center;
padding: 5px 5px;
}
You can also add an outer container and then create a inner container for each button-price set.
Here is the HTML code:
<div class="outter">
<div class="block">
<div class="button">button1</div>
<div class="price2">From £65</div>
</div>
<div class="block">
<div class="button">button2</div>
<div class="price2">From £300</div>
</div>
<div class="block">
<div class="button">button3</div>
<div class="price2">From £715</div>
</div>
</div>
Here the CSS:
.outter{
width:100%;
}
.block{
width:33%;
background-color: yellow;
float:left;
text-align: center;
}
And here a jsfiddle:
http://jsfiddle.net/SoniaGM/ej4mdwx9/1/
Hope it helps.
You can use the CSS3 ::after pseudo-selector.
Give at button class:
position: relative;
Then you have to write something lime this:
.button-class::after {
content: 'From £300';
background: transparent;
height: 1%;
width: 3%;
position: absolute;
top: 20px;
left: 0px;
}
Obviously, you have to change height: 1%; width: 3%; and top: 20px; left: 0px;with whatever you want!
I am trying to center some so that they are displayed within the center, however the tricky part is the html is within a number of (part of the html is static, and part of it is dynamic from a database).
See the screenshot as an example of how it currently looks (I want this content in the centre)
http://postimg.org/image/5fc6ecgy7/
note - the site is using the base 960 grid system
Below is the HTML:
<div class="">
<div class="">
<div class="">
<div id="national-prize-feed" class="panel-wrapper ">
<div class="border">
<div class="content clearfix add-radius">
<div style="padding:10px 0px;">
<div id="nation-prizes-collection" class="clearfix">
<div class="summary"></div>
<div class="">
<div class="national-prizes">
<div class="prizes">
<img class="prizes-img" alt="iPod Shuffle" src="/images/prizes/ipod-shuffle.png">
</div>
</div>
<div class="national-prizes">
<div class="prizes">
<img class="prizes-img" alt="Football" src="/images/prizes/football.png">
</div>
</div>
</div>
<div class="keys" title="/pages/index/slug/prizes" style="display:none">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
My specific css (there is a lot more.. it is based on a grid based layout)
div.prizes {
float: left;
}
div.prizes img {
width: 280px;
}
.prizes-img {
padding: 0 7px 0 7px;
margin: 7px 5px 7px 5px;
max-width: 100%;
height: auto;
}
In order to position a DIV to the center of a screen, you need to set a static width of the div to be centered, left: 0px, right: 0px, and the respective margins to auto.
Here is an example: http://jsfiddle.net/pR4hq/
<style>.center{
position: relative;
display: block;
width: 120px;
background: rgb(90,90,90);
left: 0px;
right: 0px;
margin-left: auto;
margin-right: auto;
text-align: center;
}</style>
<div class="center">Center Content</div>