Alignment image - html

I'm working on a site which needs an image centered in the div on the left side, centered off the right div with a background.
I tried to a common solution, but for some reason, it won't work. It must be responsive as well, so I'm a bit in the dark over here. See my fiddle for the example.
<div class="container-fluid">
<div class="row">
<div class="col-12 col-sm-6">
<div class="leftSide">
<img src="https://images.pexels.com/photos/3755760/pexels-photo-3755760.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" class="img-fluid imgLeft">
</div>
</div>
<div class="col-12 col-sm-6">
<div class="rightSide">
<h3>
Some text
</h3>
<p>
Some more text
</p>
<button type="button" class="btn btn-primary">Some text</button>
</div>
</div>
https://jsfiddle.net/Onno0297/grvwxby2/1/

If I understand your question correctly then below code will work.
Visit https://jsfiddle.net/alishapatel/n3ap1vjo/4/!
.leftSide {
height: 100%;
display: flex;
align-items: center;
}
.rightSide {
background: #313131;
height: 546px;
color: #fff;
}
.rightSide h3 {
text-align: center;
padding-top: 200px;
}
.rightSide p {
text-align: center;
}
.btn.btn-primary {
margin: 0 auto;
display: block;
}
.imgLeft {
max-height: 400px;
max-width: 300px;
margin: 0 auto;
width: 100%;
}
<div class="container-fluid">
<div class="row">
<div class="col-12 col-sm-6">
<div class="leftSide">
<img src="https://images.pexels.com/photos/3755760/pexels-photo-3755760.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" class="img-fluid imgLeft">
</div>
</div>
<div class="col-12 col-sm-6">
<div class="rightSide">
<h3>
Some text
</h3>
<p>
Some more text
</p>
<button type="button" class="btn btn-primary">Some text</button>
</div>
</div>
</div>
</div>

Related

Putting a button in the bottom-right of a page

How can I put this View More button in the bottom-right of the container? I am having a hard time on putting the view more button on the bottom right of the 'back' div.
.back {
border: #6ACEBC 4px solid;
margin: 0 20px;
border-radius: 15px;
max-width: 100%!important;
min-height: 200px;
}
.content {
max-width: 60%;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="back">
<div class="content">
<div class="row ps-3 text-center">
<div class="col">Order #</div>
<div class="col">Order Name</div>
<div class="col">Quantity</div>
<div class="col">Price per pcs</div>
<div class="col">Total Price</div>
</div>
<div class="row ps-3 text-center">
<div class="col">3</div>
<div class="col">Pencil</div>
<div class="col">5</div>
<div class="col">10</div>
<div class="col">50</div>
</div>
<div class="float-end">
<button>VIEW MORE</button>
</div>
</div>
</div>
Use absolute positioning to place the button on the bottom right of the container. The container needs to be position: relative; to get the context of the button in the right place.
.back {
border: #6ACEBC 4px solid;
margin: 0 20px;
border-radius: 15px;
max-width: 100%!important;
min-height: 200px;
background-color: darkorange;
position: relative;
}
.content {
max-width: 60%;
}
button {
position: absolute;
bottom: 10px;
right: 10px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class = "back">
<div class="content">
<div class="row ps-3 text-center">
<div class="col">Order #</div>
<div class="col">Order Name</div>
<div class="col">Quantity</div>
<div class="col">Price per pcs</div>
<div class="col">Total Price</div>
</div>
<div class="row ps-3 text-center">
<div class="col">3</div>
<div class="col">Pencil</div>
<div class="col">5</div>
<div class="col">10</div>
<div class="col">50</div>
</div>
<div class = "float-end">
<button>VIEW MORE</button>
</div>
</div>
</div>
You can use position: absolute. Create a new containing block with position: relative on the parent however this takes the button outside of the flow so you may end up with other elements clashing with it (e.g. the button appearing over text content).
.back {
border: #6ACEBC 4px solid;
margin: 0 20px;
border-radius: 15px;
max-width: 100%!important;
min-height: 200px;
position: relative; /* create new containing block */
}
.content {
max-width: 60%;
}
.view-more {
position: absolute;
bottom: 1rem;
right: 1rem;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="back">
<div class="content">
<div class="row ps-3 text-center">
<div class="col">Order #</div>
<div class="col">Order Name</div>
<div class="col">Quantity</div>
<div class="col">Price per pcs</div>
<div class="col">Total Price</div>
</div>
<div class="row ps-3 text-center">
<div class="col">3</div>
<div class="col">Pencil</div>
<div class="col">5</div>
<div class="col">10</div>
<div class="col">50</div>
</div>
<div class="view-more">
<button>VIEW MORE</button>
</div>
</div>
</div>
The other way is to move your view-more div outside the content div and then use display: flex to move it to the bottom right hand corner. We make sure the div fills the parent div. This will always make sure the table above and the button do not clash.
.back {
border: #6ACEBC 4px solid;
margin: 0 20px;
border-radius: 15px;
max-width: 100%!important;
min-height: 200px;
display: flex; /* make this a flex container */
flex-direction: column; /* make the flex divs stack on top of each other rather than side by side */
}
.content {
max-width: 60%;
}
.view-more {
flex-grow: 1; /* make the bottom div grow to fill the container */
display: flex; /* make this a flex container also */
justify-content:flex-end; /* put the button to the right hand side of the parent div */
align-items: flex-end; /* put the button at the bottom of the div */
padding:0.5rem; /* put a bit of padding round it to put some space between the green border and the button */
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="back">
<div class="content">
<div class="row ps-3 text-center">
<div class="col">Order #</div>
<div class="col">Order Name</div>
<div class="col">Quantity</div>
<div class="col">Price per pcs</div>
<div class="col">Total Price</div>
</div>
<div class="row ps-3 text-center">
<div class="col">3</div>
<div class="col">Pencil</div>
<div class="col">5</div>
<div class="col">10</div>
<div class="col">50</div>
</div>
</div>
<div class="view-more">
<button>VIEW MORE</button>
</div>
</div>
Have you tried adding "position: relative" to the container and then positioning the button absolutely?
.back {
border: #6ACEBC 4px solid;
margin: 0 20px;
border-radius: 15px;
max-width: 100%!important;
min-height: 200px;
position: relative;
}
.content {
max-width: 60%;
font-size: 5px;
}
.float-end {
position: absolute;
right: 0;
bottom: 0;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class ="back">
<div class="content">
<div class="row ps-3 text-center">
<div class="col">Order #</div>
<div class="col">Order Name</div>
<div class="col">Quantity</div>
<div class="col">Price per pcs</div>
<div class="col">Total Price</div>
</div>
<div class="row ps-3 text-center">
<div class="col">3</div>
<div class="col">Pencil</div>
<div class="col">5</div>
<div class="col">10</div>
<div class="col">50</div>
</div>
</div>
<div class="float-end">
<button>VIEW MORE</button>
</div>
</div>

How to create a layout using flex?

I'm trying to create the following layout for one of my web projects. What's the best way to create that using HTML, CSS (Flex)?
I'm struggling with bottom-margin for C & D in Desktop screens, for D in Mobile screens.
As we don't have your code, so based on your question here i provide solution let me know if you have any question..
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-6 mb-5">
<div class="card p-5">
A
</div>
</div>
<div class="col-md-6 mb-5">
<div class="card p-5">
B
</div>
</div>
<div class="col-md-6 mb-5">
<div class="card p-5">
C
</div>
</div>
<div class="col-md-6 mb-5">
<div class="card p-5">
D
</div>
</div>
</div>
</div>
You can do it like this.
.main_container {
display: grid;
grid-template-columns: auto auto;
grid-row-gap: 30px;
grid-column-gap: 30px;
}
.sections {
height: 200px;
text-align: center;
background-color: aqua;
}
/*here for mobiles inside mobile media query put this*/
.main_container {
display: grid;
grid-template-columns: auto;
grid-row-gap: 30px;
grid-column-gap: 30px;
}
<div class="main_container">
<div class="sections">A</div>
<div class="sections">B</div>
<div class="sections">C</div>
<div class="sections">D</div>
</div>
<div class="row">
<div class="col-md-6 col-lg-6 col-xl-6 col-sm-12 col-xs-12">
<p>Write text here A</p>
</div>
<div class="col-md-6 col-lg-6 col-xl-6 col-sm-12 col-xs-12">
<p>Write text here B</p>
</div>
</div>
<div class="cs-t20">
<!-- spacer -->
</div>
</div>
<div class="row">
<div class="col-md-6 col-lg-6 col-xl-6 col-sm-12 col-xs-12">
<p>Write text here C</p>
</div>
<div class="col-md-6 col-lg-6 col-xl-6 col-sm-12 col-xs-12">
<p>Write text here D</p>
</div>
</div>
<div class="cs-t20">
<!-- spacer -->
</div>
</div>
<style>
.cs-t20{
width: 100%;
height: 30px;
}
</style>
Hope it will help you!! All the Best !!
here your go..
.cs-t20 {
width: 100%;
height: 30px;
}
.continer {
width: 100%;
height: 100%;
}
.webpage-page-display {
float: none;
display: table-cell;
}
.webpage-page-column {
z-index: 1;
float: left;
position: relative;
min-height: 1px;
}
.webpage-page-half {
margin-left: 6%;
width: 47%;
}
.webpage-page-first {
margin-left: 0px;
clear: left;
}
.webpage-page-half {
width: 100%;
}
.webpage-page-column {
margin: 0;
margin-bottom: 20px;
width: 100%;
}
#media only screen and (min-width: 320px) and (max-width: 767px) {
.webpage-page_column_table_cell {
display: block;
}
.webpage-page-half {
width: 100%;
}
.webpage-page-column {
margin: 0;
margin-bottom: 20px;
width: 100%;
}
}
<div id="webpage_section">
<div class="container">
<div class="webpage-page-column webpage-page_column_table_cell webpage-page-first webpage-page-half webpage-page-display">
<p>Write text here A</p>
</div>
<div class="webpage-page-column webpage-page_column_table_cell webpage-page-half webpage-page-display">
<p>Write text here B</p>
</div>
<div class="cs-t20"></div>
</div>
</div>
<div id="webpage_section">
<div class="container">
<div class="webpage-page-column webpage-page_column_table_cell webpage-page-first webpage-page-half webpage-page-display">
<p>Write text here C</p>
</div>
<div class="webpage-page-column webpage-page_column_table_cell webpage-page-half webpage-page-display">
<p>Write text here D</p>
</div>
<div class="cs-t20"></div>
</div>
</div>

boostrap 4 Equal heights not working

What is the way of making div's have equal heights within the row?
it says everywhere that bootstrap4 is flex by default, but it doesn't work for some unknown reason
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="content" >
<div class="sub_title"> HISTORY </div>
<div class="desc"> Sometext </div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-6 col-md-6 col-lg">
<div class="content">
<div class="sub_title">
<div class="number"> 2012 </div>
</div>
<div class="desc"> some other text </div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-6 col-lg ">
<div class="content">
<div class="sub_title">
<div class="number"> 2014 </div>
</div>
<div class="desc"> More text </div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-6 col-lg ">
<div class="content">
<div class="sub_title">
<div class="number"> 2017 </div>
</div>
<div class="desc"> Text here too </div>
</div>
</div>
</div>
the scss
.content {
#extend .effect8;
background: white;
margin: 10px;
padding: 10px 30px 20px;
span {
display: block;
p {
font-weight: bold;
}
}
}
.sub_title {
font-size: 1.5em;
font-weight: 700;
text-transform: uppercase;
display: block;
color: $blue;
margin: 10px auto;
}
this is the scss for the content and the sub_title class
If you want .content to be full height on each .col, the content should have height:100%;. I don't know the CSS def of .effect8.
.content {
background: white;
margin: 10px;
padding: 10px 30px 20px;
height: 100%;
span {
display: block;
p {
font-weight: bold;
}
}
}
https://www.codeply.com/go/B4g6TlSDkA
Actually it depend of browser, e.g In Safari it may not work, and also in Internet Explorer may have unwanted behaviors.
If you're really want equal and avoid cross browser issue try JS solution e.g http://brm.io/jquery-match-height/

BootStrap / CSS fix position of a div

Hello, i'm kinda new at css/bootstrap, i'm learning actually.
In this case, i will probably need to add some css at "chat_funcs" div, but i don't know what to write to get what i want.
The problem:
What i want is:
My code so far:
HTML:
<div id="chat" class="col-md-3 col-xs-12">
<span class="titulo">Chat</span>
<div class="msg">Mensagem teste</div>
<div class="msg">Mensagem teste</div>
<div class="msg">Mensagem teste</div>
</div>
<div id="chat_funcs" class="pull-right col-md-3 col-xs-12">
<div class="pull-left">
<input class="form-control" type="text">
<input class="btn btn-default" type="button" value="Enviar">
</div>
</div>
CSS:
#chat {
background-color: red ;
overflow: scroll;
overflow-x: hidden;
height: 80%;
position: absolute;
right: 0;
display: inline-block;
}
In order to achieve this you are going to use additional html div container. There're other ways too, but this one came to my mind first.
Here is html markup:
<div id="chat-container" class="col-md-3 col-xs-12">
<div class="row">
<div id="chat" class="col-md-12 col-xs-12">
<span class="titulo">Chat</span>
<div class="msg">Mensagem teste</div>
<div class="msg">Mensagem teste</div>
<div class="msg">Mensagem teste</div>
</div>
</div>
<div class="row">
<div id="chat_funcs" class="col-md-12 col-xs-12">
<div class="pull-left">
<input id="message-text" class="form-control" type="text"><br/>
<input class="btn btn-default" type="button" value="Enviar">
</div>
</div>
</div>
</div>
and here is css:
#chat-container{
position: absolute;
right: 0;
width: 160px;
}
#chat {
background-color: red ;
overflow: scroll;
overflow-x: hidden;
height: 80%;
width: 100%;
display: inline-block;
}
#message-text{
width: 140px;
}
here is a fiddle
I hope this helps

How to center elements inside div

I'm using bootstrap 2.3.2. I have a div with some wells inside. Here is a Preview
My structure is
<body>
<div class="page-header">
<h1 id="title">Title</h1>
</div>
<div class="row">
<div class="span3 my_span">
<div class="well my_well">
<h1>Text</h1>
<hr>
<p>More Text</p>
<hr>
<button class="btn btn-primary">Button</button>
</div>
</div>
<div class="span3 my_span">
<div class="well my_well">
<h1>Textr</h1>
<hr>
<p>More Text</p>
<hr>
<button class="btn btn-primary">Button</button>
</div>
</div>
<div class="span3 my_span">
<div class="well my_well">
<h1>Textr</h1>
<hr>
<p>More Text</p>
<hr>
<button class="btn btn-primary">Button</button>
</div>
</div>
</div>
</body>
The wells are inside a row div, how to center all the wells horizontally?
Here is the jsfiddle with the code.
I think this is what you were describing: Fullscreen View
See jsfiddle
I modified my_span:
.my_span {
width: 300px;
margin: 0 33px;
float: none;
display:inline-block;
}
and added:
.row {
text-align: center;
margin: 0;
}
EDIT: I edited the fiddle a bit to fix the margins.
Just use margin: 0 auto to set your divs to be centered.
.my_span {
width: 300px;
margin: 0 auto;
}
http://jsfiddle.net/BVmUL/367/
You can do
.parent-of-centered-div {
text-align: center;
}
.centered-div {
display:inline-block;
width: 20px; /* needs fixed width */
}