This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Closed 10 months ago.
I have three divs that I would like to line up vertically, unfortunately every solution I find only uses either position:absolute or flexbox and I cannot use either because it will affect other things on the page that I do not have control over.
At the moment here is my code:
<div
class="search-wrapper text-center "
style=""
>
<div
class="col-md-7 perfect-vacation white "
style="font-family:lora;letter-spacing:0px;font-style:italic;font-size:clamp(1.3rem, 3.9vw, 2.9em);white-space:nowrap;"
>
<div> find your perfect cruise vacation</div>
</div>
<div id="search-cruises" class=" col-md-2" style="">
<a
href="/search-cruise/cruises"
class="green-btn button"
data-track="search-track"
data-track-id="search-widget"
style="background:#6D9D5B;padding:10px;
border-color:#6D9D5B;font-size:clamp(1.1em, 1vw, 1.4em);white-space:nowrap;"
>
Search Cruises
</a>
</div>
<div class="col-md-3" style="">
<a
class="white recent-cruise "
style="font-family:Roboto;white-space:nowrap;font-size:clamp(.8em, 1vw, 1.4em);color:white;overflow:visible;"
>
See Recently Viewed Cruises
</a>
</div>
</div>
Which looks like this (without the red line) I am looking to get all 3 items to line up with that red line. Any suggestions would be very much appreciated.
If you don't want to use flexbox (which would make it very easy) you can use inline-block with vertical-align:middle; and line-height.
a working abstract example
:root {
--nav-height: 100px;
}
.col {
text-align: center;
background-color: gray;
height: var(--nav-height);
}
.col > div {
display: inline-block;
vertical-align:middle;
line-height:var(--nav-height);
width: 25%;
background: lightgreen;
}
.d1 {
font-size:30px;
}
.d2 {
font-size:10px;
}
.d3 {
font-size:50px;
}
<div class="col">
<div class="d1">text 1</div>
<div class="d2">text 2</div>
<div class="d3">text 3</div>
</div>
Related
This question already has answers here:
How to vertically align an image inside a div
(37 answers)
Center image using text-align center?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
How can I center text (horizontally and vertically) inside a div block?
(27 answers)
Closed 2 years ago.
I am trying to create circle cards using HTML and CSS. Upon click I am trying to open a web URL which is working perfectly fine for me.
But then I am not able set the alignment properly.
I tried display: flex to get the images side by side but the space between circle card is more but minimize space?
And I am not able to set the name of the circle in the center of the image. Can anyone please help me how to do this?
.circle {
background: rgba(15, 28, 63, 0.125);
border-radius: 50%;
height: 8em;
object-fit: cover;
width: 8em;
}
h1 {
text-align: center;
}
.row {
display: flex;
}
.circle-one, .circle-two, .circle-three {
flex: 33.33%;
padding: 5px;
}
<div>
<!-- your widget template -->
<h1> Hello World </h1>
<div class="row">
<div class="circle-one">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://images.unsplash.com/photo-1555448248-2571daf6344b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" alt="Tyler">
</a>
<h5> Circle One</h5>
</div>
<div class="circle-two">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDk0fQ&auto=format&fit=crop&w=1000&q=80" alt="Tyler">
</a>
<h5> Circle Two</h5>
</div>
<div class="circle-three">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://cdn.pixabay.com/photo/2015/02/24/15/41/dog-647528_960_720.jpg" alt="Tyler">
</a>
<h5>Circle Three</h5>
</div>
</div>
</div>
This is what I get
use display flex
use align-items:center
.circle {
background: rgba(15, 28, 63, 0.125);
border-radius: 50%;
height: 8em;
object-fit: cover;
width: 8em;
}
h1 {text-align: center;}
.row {
display: flex;
align-items:center;
justify-content:space-around;
}
.circle-one, .circle-two, .circle-three {
flex: 33.33%;
padding: 5px;
display:flex;
flex-direction:column;
align-items:center;
}
<div>
<!-- your widget template -->
<h1> Hello World </h1>
<div class="row">
<div class="circle-one">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://images.unsplash.com/photo-1555448248-2571daf6344b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" alt="Tyler">
</a>
<h5> Circle One</h5>
</div>
<div class="circle-two">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDk0fQ&auto=format&fit=crop&w=1000&q=80" alt="Tyler">
</a>
<h5> Circle Two</h5>
</div>
<div class="circle-three">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://cdn.pixabay.com/photo/2015/02/24/15/41/dog-647528_960_720.jpg" alt="Tyler">
</a>
<h5> Circle Three</h5>
</div>
</div>
</div>
well, It is quite a simple task,
can be done in many ways. one of them is,
add div around your text (circle one , circle two, and circle three) and (img + a) tag
and apply css properties to the classes in css.
display: flex;
align-items: center;
justify-content-center;
This question already has answers here:
Vertically align text next to an image?
(26 answers)
Closed 4 years ago.
I have added an image and text. Text has 1 <h6> and 2 <p> tags. I tried using float:left but it does not get displayed side by side.
content.js:
<div className="col l4">
<div className="card1">
<img className="javacardimg" src={java} alt="Java" height="65" width="65"></img>
<h6 className="cardtitle1">New Launch</h6>
<p className="cardcontent1">JAVA</p><p></p>
<p className="cardcontent1">Foundations</p>
</div>
</div>
<div className="col l4">
<div className="card2">
<img className="neuralcard" src={neural} alt="Neural Network" height="65" width="65"></img>
<h6 className="cardtitle2">Enroll Now</h6>
<p className="cardcontent2">Neural Newtwork</p><p></p>
<p className="cardcontent2">Foundations</p>
</div>
</div>
css:
.cardcontent{
float: left;
}
.card1 {
width: 100%;
}
.card1 > h6 {
margin: 0px;
}
I want to display New Launch JAVA Foundations on right of image similarly for card2 but current css does not work I tried few css styling but does not work.
Screenshot:
Try to use Flexbox here...and also wrap your right side content into a div for better practice and readability
.card1 {
display: flex;
align-items: flex-start;
}
h6 {
margin-top: 0;
}
.item {
padding-left: 10px;
}
<div class="card1">
<img className="javacardimg" src="http://via.placeholder.com/100x100?text=JAVA" alt="Java">
<div class="item">
<h6 className="cardtitle1">New Launch</h6>
<p className="cardcontent1">JAVA Foundations</p>
</div>
</div>
I am using Bootstrap 4 Alpha 5 and I have the following HTML:
<div class="home-content">
<div class="container">
<div class="row flex-items-xs-middle">
<div class="col-md-7">
<h1 class="site-title text-xs-center text-md-left">
<span class="name">I'm Shivam Paw</span>
<span class="title">I create beautiful and bespoke websites to fit your needs</span>
</h1>
</div>
<div class="col-md-5">
<img src="https://www.shivampaw.com/wp-content/uploads/2016/10/shivampaw.png" class="float-md-right img-fluid logo-me mx-auto" alt="Shivam Paw">
</div>
</div>
</div>
</div>
However, if you see the image below then you will see that the content is misaligned to the left. I saw a post on this on SO but it said you have to put the row class in a container which I have already done.
You can see the site live at https://www.shivampaw.com
I looked at the .row CSS which has margin for left and right of -15px. Removing those margins fixed it but I don't think that's how it should be?
If this is what you expect then look at your CSS. This is the line centering your content
.text-xs-center {
text-align: center!important;
}
This should fix it though
.site-title {
font-size: 36px;
color: white;
font-weight: bold;
text-align: left !important;
}
Turns out I had some offending CSS in my style.css:
*, img.full-size{
max-width: 100%;
}
Changing it to:
img.full-size{
max-width: 100%;
}
Fixed the problem.
This question already has answers here:
CSS: Vertical column layout without <table>
(3 answers)
Closed 9 years ago.
I have the below html code. What I need to do is split wuiInPageNav into two sections. LeftArea and wuiMainPageNav and they need to be side by side all the time. LeftAre div will hold my jstree nodes and wauiMainPageNave div will hold my charts and data etc. When I do the following, left goes left and wuiMainPageNav goes to the right. But when I resize the browser window, make it smaller, wuiMainPageNave goes down to the botttom. How do I make sure that LeftArea is always on the left and wuiMainPageName is always on the right, regardles of the browser window and size?missing here. Any ideas?
div id="wuiLeftArea">
<div id="wuiLefthandNavRoot">
<h2 class="wui-hidden">Section Navigation</h2>
<h3 class="wui-navigation-title">Applicaion</h3>
<div id=tree></div>
</div>
</div>
<div id=wuiMainArea>
<div id=wuiMainContent>
<div id=wuiInpageNav>
<div id="top_chart" class="center"> </div>
</div>
</div>
</div>
css:
#wuiInpageNav {left:300px; float:right; width:1200px !important; overflow:hidden; }
div#wuiLeftArea{
float: left;
width: 16.25em;
background-color: #f2f4f5;
padding-top: .5833em;
position: relative;
}
UPDATE
Make sure you don't do your CSS inline:
http://jsfiddle.net/FE79R/1/
HTML
<div id=wuiMainArea>
<div id=wuiMainContent>
<div id=wuiInpageNav>
<div id="left">
<div id="tree">tree</div>
</div>
<div id=main>
<div id="top_charts" class="center"> </div>
<div class="main1">
<div id="top_chart1" class="center">top chart 1</div>
<div id="top_chart2" class="center">top chart 2</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS
#wuiInpageNav { width:300px; overflow:hidden; }
#left { width:100px; float:left; position:relative; background-color:#f2f4f5;}
#main { width:200px; float:left; background-color:orange;}
I am working on a photo gallery, each thumbnail is in its own DIV and floated to the left in a containing DIV. It has been displaying properly up until vertical thumbnails entered the equation. Now, when the next row should start, the first item of the following row is to the left of the last vertical DIV (thumbnail), rather than flush to the left of the containing DIV.
alt text http://tapp-essexvfd.org/images/capture1.jpg
Here is the CSS:
#galleryBox {
width: 650px;
background: #fff;
margin: auto;
padding: 10px;
text-align: center;
overflow: auto;
}
.item {
display: block;
margin: 10px;
padding: 20px 5px 5px 5px;
float: left;
background: url('/images/content_bottom.png') repeat-x scroll bottom #828282;
}
and the HTML:
<div id="galleryBox" class="ui-corner-all">
<div id="file" class="ui-corner-all">
<form name="uploadPhoto" id="uploadPhoto" method="post" action="" enctype="multipart/form-data">
<p><label for="photo">Photo:</label><input type="file" name="photo" id="photo"/></p>
<p><label for="caption">Caption: <small>Optional</small></label><input type="text" id="caption" name="caption"/></p>
<p align="center"><input type="submit" value="Upload" name="send" id="send" class="addButton ui-state-default ui-corner-all"/></p>
</form>
<a name="thumbs"></a>
</div>
<div class="item ui-corner-all">
<a href="http://tapp-essexvfd.org/gallery/photos/201004211802.jpg" class="lightbox" title="test1">
<img src="http://tapp-essexvfd.org/gallery/photos/thumbs/201004211802_thumb.jpg" alt="test1"/></a><br/>
<p><span class="label">test1</span></p>
</div>
<div class="item ui-corner-all">
<a href="http://tapp-essexvfd.org/gallery/photos/201004211803.jpg" class="lightbox" title="test3">
<img src="http://tapp-essexvfd.org/gallery/photos/thumbs/201004211803_thumb.jpg" alt="test3"/></a><br/>
<p><span class="label">test3</span></p>
</div>
</div>
You can use Inline-Blocks as described in this article:
The Inline-Block Thumbnail Gallery
The article solves the same exact problem you are having with thumbnails.
I also found this simple example using inline-block thumbnails. Note how the thumbnails wrap nicely and remain vertically aligned within their line.
UPDATE:
Here is another detailed article that tackles this problem with the inline-block:
Cross-Browser Inline-Block
As you can notice from these articles, it is a bit tricky to make it work cross-browser.
Two options:
Set a maximum height for the thumbnail DIVs, so that they layout correctly, regardless of whether they are horizontal or vertical.
Use "clear: left" to reset the float on the thumbnail DIV next to the vertical.
The default behavior appears correct, based on what happens when text flows around a floated DIV. Based on what you're trying to do, I would choose option #1.
you could try using css table displays for your divs...
ie.
#galleryBox {
display: table;
...
}
.item {
display: table-cell;
...
}
.row {
display: table-row;
}
so you'd have to add another div to wrap around the items in each row
<div id="galleryBox">
<div class="row">
<div class="item">image</div>
<div class="item">image</div>
<div class="item">image</div>
<div class="item">image</div>
</div>
<div class="row">
<div class="item">image</div>
<div class="item">image</div>
<div class="item">image</div>
<div class="item">image</div>
</div>
</div>