EDIT: Please disregard the phone/email row.
I would like to reach this kind of result:
Since I need the side texts to be as the same height of the icon, I am having some issues with the relative and absolute div wrappers and how to set them right.
HTML
<div class="row topWrapper">
<div class="iconWrapper">
<i class="fa fa-user-circle-o fa-2x"></i>
</div>
<div class="captionWrapper">
<h5><strong>Liat </strong></h5>
<h5>Your recruitment counsel</h5>
</div>
</div>
SCSS
.topWrapper {
background-color: #d9534f;
height: 150px;
.iconWrapper {
background-color: #f7ecb5;
display: inline-block;
position: relative;
width:16.67%;
i{
position: absolute;
top: 50%;
#include translate(0, -50%);
}
}
.captionWrapper{
background-color: #245580;
display: inline-block;
}
}
You don't need to use absolute position to get what you want, just a few things and you are good to go.
See code snippet:
Note: i didn't use SCSS for demonstration purpose
.topWrapper {
background-color: #d9534f;
height: 150px;
padding: 5px;
}
.iconWrapper {
display: inline-block;
font-size: 17px;
}
.captionWrapper {
display: inline-block;
}
.captionWrapper h5 {
margin: 2px;
/*reduce the margin to make the two texts aligned with the icon*/
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="row topWrapper">
<div class="iconWrapper">
<i class="fa fa-user-circle-o fa-2x"></i>
</div>
<div class="captionWrapper">
<h5><strong>Liat </strong></h5>
<h5>Your recruitment counsel</h5>
</div>
</div>
Related
I'm trying to create a top bar with the following structure
Tel:4949494949 social media icons
In the middle I'm trying to have contact info and at almost in right my social media icons.
I'm not able to place social media in right. CSS always gets them to the middle, next to contact info.
What is wrong?
#tpbr_box .a {
width: 10%;
height: 20%;
text-align: center;
display: inline;
font-size: 20px!important;
}
#tpbr_box .social2 {
float: right;
}
#tpbr_box {
font-size: 20px!important;
}
<div class="info">
<i class="fa fa-home"></i> |
<a style="color:white;" href="tel:54543">354353535</a>
</div>
<div class="social2">
</div>
I switched out the div classes because when you use a new one, it writes itt in a new line. I fixed this by using a a-class instead of a div, still giving an class to each one. The reason why I used width and margin-left with percents is no matter the length, the html will adjust(ex. you resize the window, it resizes with it).
.topbar {
width: 100%
}
.info {
margin-left: 45%
}
.social2 {
margin-left: 55%
}
<div class="info">
<a class='center'>
<i class="fa fa-home"></i>
354353535
</a>
<a class='social2'>
f
t
i
y
</a>
</div>
Based on your requirements, Info to the middle, and social to the right side!
Try this:
<!-- Html code -->
<div class="top_nav">
<div class="info">
<i class="fa fa-home"></i> |
<a style="color:whites;" href="tel:54543">354353535</a>
</div>
<div class="social2">
</div>
</div>
And here is the CSS style:
#tpbr_box .a {
width: 10%;
height: 20%;
text-align: center;
display: inline;
font-size: 20px!important;
}
#tpbr_box .social2{
float:right;
}
#tpbr_box {
font-size: 20px!important;
}
.top_nav{
display: flex;
}
.top_nav .social2 {
position: absolute;
right: 14px;
}
.info{
margin: 0 auto;
}
Make sure add parent div with "top_nav" class to control the style.
I think the problem comes from the fact that you put a text-align: center; on your links. Putting a text-align: center; on the tags a, all your links present on your page will go to the middle.
I have to differentiate value 1 and value 2 using dot icon so I wrote css for that and placed in div but it is overlapping on each other I just want to show two div side by side with icon and text without overlapping
.dot {
height: 12px;
width: 12px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
.user-values-color{
background-color: #1BBC9B;
float: left;
}
.default-values-color{
background-color: #2D3E50;
float: left;
}
<div class="user-values-color dot" ><span style="float:left;">Value 1</span></div>
<div class="default-values-color dot"><span style="float:left;"> value 2</span></div>
take the span out of the div put it side by side in a parent container like below:
.dot {
height: 12px;
width: 12px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
.user-values-color{
background-color: #1BBC9B;
float: left;
}
.default-values-color{
background-color: #2D3E50;
float: left;
}
.container {
display: inline-block;
}
<div class="container">
<div class="user-values-color dot" ></div>
<span style="float:left;">Value 1</span>
</div>
<div class="container">
<div class="default-values-color dot"></div>
<span style="float:left;"> value 2</span>
</div>
If you are really using bootstrap then you shall learn about Grid system, it 's the basic.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container">
<div class="row justify-content-start">
<div class="col-2">
Value 1
</div>
<div class="col-2">
value 2
</div>
</div>
</div>
now you are just using inline css
This question already has answers here:
How do you make div elements display inline?
(20 answers)
Display Images Inline via CSS
(3 answers)
How to make the <img> tags line up horizontally in the div?
(5 answers)
How to put img inline with text
(3 answers)
Closed 5 years ago.
Im just having a frustrating time trying to emulate this - where the arrows function as buttons and text sits below the img -
For CSS, Ive tried as other questions suggest:
.ico-selector {
display: inline-block;
width: 123px;
float: left;
}
Example
.ico-selector {
display: inline-block;
width: 123px;
float: left;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="ico-selector">
<i class="fa fa-chevron-left"></i>
<img src="https://d1j8pt39hxlh3d.cloudfront.net/development/emojione/2.2/843/2270.svg" />
<p>My Icon</p>
<i class="fa fa-chevron-right"></i>
</div>
but they remain vertically stacked. How can I do this?
You can simply do this :
.ico-selector {
width: 123px;
text-align: center;
display: inline-block;
}
/*adjust these values as you need*/
.ico-selector img {
width: 65%;
margin: 0 5px;
}
.ico-selector>* {
vertical-align: middle;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="ico-selector">
<i class="fa fa-chevron-left"></i>
<img src="https://d1j8pt39hxlh3d.cloudfront.net/development/emojione/2.2/843/2270.svg" />
<i class="fa fa-chevron-right"></i>
<p>My Icon</p>
</div>
I assume your ico-selector box has fixed dimensions. Why not just position the chevrons absolutely within that box?
.ico-selector {
position:relative;
display: inline-block;
width: 123px;
}
.fa-chevron-left{
position: absolute;
left:0;
top: 50%;
}
.fa-chevron-right{
position: absolute;
right:0;
top: 50%;
}
Its a rather rough example but it illustrates the idea.
You can use divs to surround each part of your icon selector like this:
.ico-selector {
width: 123px;
height: 200px;
line-height: 200px;
}
.left-arrow, .icon, .right-arrow {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="ico-selector">
<div class="left-arrow">
<i class="fa fa-chevron-left"></i>
</div>
<div class="icon">
<img src="https://d1j8pt39hxlh3d.cloudfront.net/development/emojione/2.2/843/2270.svg" />
<p>My Icon</p>
</div>
<div class="right-arrow">
<i class="fa fa-chevron-right"></i>
</div>
</div>
I have a <div> with a number of sub-elements (which happen to be custom-sized buttons). It can have between 1 and 3 buttons.
Example of HTML with 2 buttons:
<div id="head">
<div id="control-buttons-container">
<button class="control-button">some button text</button>
<button class="control-button">proceed with this button</button>
</div>
</div>
When there are 3 buttons, they fill the entire <div>, so it is not an issue. However, when there are 1 or 2 buttons, they need to be centered but I can't seem to accomplish this without introducing ridiculous conditional margins or something.
How can I modify this CSS so that <div> elements with 1 or 2 of these buttons show the buttons centered within the div?
Please refer to the Fiddle: https://jsfiddle.net/bf33wc6w/1/
Edit: With only 2 buttons, I don't want them to be spread out. I want them to be in the center with only ~2px between them similar to their spacing for when there are 3 buttons.
You could set inline block on the items, with container set to text align center.
.control-buttons-container {
text-align: center;
font-size: 0; /*fix inline block gap*/
}
.control-button {
display: inline-block;
vertical-align: top;
font-size: 12px; /*reset font size*/
}
JSFIDDLE DEMO
.control-buttons-container {
text-align: center;
font-size: 0; /*fix inline block gap*/
}
.control-button {
background-color: #0E80B4;
color: white;
outline: none;
height: 73px;
width: 128px;
margin: 3px 1.5px;
display: inline-block;
vertical-align: top;
font-size: 12px; /*reset font size*/
}
.control-button:hover {
background-color: #3FA9DB;
}
#head, #body, #foot {
border: 1px solid red;
position: absolute;
width: 396px;
height: 80px;
left: 0;
}
#head {
top: 0;
}
#body {
bottom: 50%;
-ms-transform: translateY(50%);
-webkit-transform: translateY(50%);
transform: translateY(50%);
}
#foot {
bottom: 0;
}
<div id="head">
<div class="control-buttons-container">
<button class="control-button">some button text</button>
<button class="control-button">proceed with this button</button>
<button class="control-button">Seth Rollins, WWE Champion</button>
</div>
</div>
<div id="body">
<div class="control-buttons-container">
<button class="control-button">proceed with this button</button>
<button class="control-button">Seth Rollins, WWE Champion</button>
</div>
</div>
<div id="foot">
<div class="control-buttons-container">
<button class="control-button">Seth Rollins, WWE Champion</button>
</div>
</div>
Updates:
Fixed same id being used multiple times on a single page, which is in valid HTML - changed it to class.
Improved the position of middle block, make it to always stay in the middle more accurately - by using CSS transform.
Merged some duplicated CSS rules.
Like this:https://jsfiddle.net/bf33wc6w/7/
All I did was change your float to none and the margin to auto for the left and right margin?
.control-button {
background-color: #0E80B4;
color: white;
outline: none;
border: none;
height: 73px;
width: 128px;
margin: 3px auto;
}
Add these style rules:
#head, #body, #foot { text-align: center; }
#control-buttons-container { display: inline-block; }
As an aside, you shouldn't use the same id (control-buttons-container) multiple times in one document. You should use a classname instead.
Updated fiddle: https://jsfiddle.net/mr8e7kyt/
Try something like this:
<div id="control-buttons-container">
<div class="col-1">
<button class="control-button">some button text</button>
</div>
<div class="col-2">
<button class="control-button">proceed with this button</button>
</div>
<div class="col-3">
<button class="control-button">Seth Rollins, WWE Champion</button>
</div>
</div>
<div id="control-buttons-container">
<div class="col-1">
</div>
<div class="col-2">
<button class="control-button">proceed with this button</button>
</div>
<div class="col-3">
</div>
</div>
.control-button {
background-color: #0E80B4;
color: white;
outline: none;
border: none;
float: left;
height: 73px;
width: 100%;
}
.control-button:hover {
background-color: #3FA9DB;
}
#control-buttons-container {
max-width: 400px;
padding: 1px;
border: 1px solid red;
}
.col-1, .col-2, .col-3 {
width: 32.6%;
display: inline-block;
margin: auto
}
Isn't flawless, but it was made in a couple of minutes and gets the job done: JSFiddle
For the containers without 3 items you should remove the float: left; for the buttons inside it. Leave it for the one with 3 items. Then you can just set text-align: center; on the container.
You can add a class like no-float on the containers you want to control whether its children should be floated or not.
https://jsfiddle.net/bf33wc6w/10/
This answer will probably help you out. Wrap your buttons in a container, give it a fixed width, and change margin to auto. Be sure to remove float: left.
I need to display a gallery of images where over each image I have an icon and a number.
These elements are inside an overlay DIV which shows when the mouse is over.
I am trying to do two things:
The vote div should be vertically aligned inside the overlay div;
I would like the heart font size to adapt depending on the image width.
Can these two problems be solved?
My code and JSFiddle Example:
<div class="gallery">
<div class="image">
<img src="http://placehold.it/600x600" alt="" />
<div class="overlay">
<div class="vote">
<i class="fa fa-heart"></i>
<span>350</span>
</div>
</div>
</div>
<div class="image">
<img src="http://placehold.it/600x600" alt="" />
<div class="overlay">
<div class="vote">
<i class="fa fa-heart"></i>
<span>350</span>
</div>
</div>
</div>
<div class="image">
<img src="http://placehold.it/600x600" alt="" />
<div class="overlay">
<div class="vote">
<i class="fa fa-heart"></i>
<span>350</span>
</div>
</div>
</div>
<div class="image">
<img src="http://placehold.it/600x600" alt="" />
<div class="overlay">
<div class="vote">
<i class="fa fa-heart"></i>
<span>350</span>
</div>
</div>
</div>
<div class="image">
<img src="http://placehold.it/600x600" alt="" />
<div class="overlay">
<div class="vote">
<i class="fa fa-heart"></i>
<span>350</span>
</div>
</div>
</div>
</div>
* {
-webkit-box-sizing: box-model;
-moz-box-sizing: box-model;
box-sizing: box-model;
}
*:before, *:after {
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
.gallery {
overflow: hidden;
}
.image {
position: relative;
text-align: center;
float: left;
width: 100%;
}
#media screen and (min-width: 600px) {
.image {
width: 50%;
}
}
img {
display: block;
height: auto;
max-width: 100%;
outline: 0;
}
.overlay {
background-color: #404040;
color: #FFFFFF;
display: none;
height: 100%;
font-size: 0.75rem;
padding: 4px;
position: absolute;
top: 0;
overflow: hidden;
width: 100%;
}
.image:hover .overlay {
display: block;
-moz-opacity: 0.8;
-khtml-opacity: 0.8;
-webkit-opacity: 0.8;
opacity: 0.8;
}
.vote {
}
.vote a {
text-decoration: none;
}
.vote i {
color: red;
display: block;
line-height: 1.0;
font-size: 8rem;
}
.vote span {
display: block;
font-size: 2rem;
}
You can center the vote class like this:
.vote {
position: relative;
top: 50%;
transform: translateY(-50%)
}
See http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/ for how this works.
Scaling the font is trickier since you're using font-awesome. I don't think you can do so with CSS.
Here's a JavaScript solution, which sets the font-size as 30% of the height of each image:
var images= document.querySelectorAll('.image');
for(var i = 0 ; i < images.length ; i++) {
var height= images[i].offsetHeight;
var heart= images[i].querySelector('.fa');
var span= images[i].querySelector('span');
heart.style.fontSize= span.style.fontSize= (height*0.3)+'px';
}
Fiddle
Ok, #1 is easy: there are multiple possible solutions. Actually was a a really good extensive article about that on the internet some time ago: Vertical Centering With CSS
Or, you could use a modern solution like flexbox:
<div class="wrapper">
<div>
Centered vertically and horizontally
</div>
</div>
.wrapper {
display: flex;
align-items: center;
justify-content: center;
}
Please remember to include prefixed versions for that if and where needed and check caniuse.com to see what browsers don't support this solution before deploying it.
As for #2: Took me quite some time to figure out that it's actually much easier than I thought:
.vote {
font-size: 30vw;
}
#media screen and (min-width: 600px) {
.vote {
font-size:15vw;
}
}
Adjust the value to your liking. Again: Viewport units are not totally supported by all browsers (cough IE cough), please check caniuse. I don't have a copy of IE handy just now, but I think vw should be supported, so I see no problems here. And keep in mind that Safari on iOS does some weird stuff, although to my knowledge that only affects vh and not vw.