I'm trying to set the left border of siginimage to 40px, but since the height of the signinimage is 25px, the border height is also being set as 25px.
.top-header {
float: left;
border-left: 2px solid #CCCCCC;
height: 30px;
margin-top: 0px;
}
#signinimage {
padding-top: 6px;
padding-left: 10px;
height: 25px;
width: 25px;
}
<img src="images/signinimage.png" class="top-header" id="signinimage">
Two approaches.
Either create a container and put the image inside it
In your question, you said you wanted to extend the border to the left
(but I mean that's just a matter of simple float:, but you can apply
this approach in general
img {
width: 100px;
height: 100px;
float: right;
}
#container {
border: 3px solid black;
width: 150px;
height: 100px;
}
<div id ="container">
<img src=https://i.imgur.com/QIsNrpM.png/>
</div>
The other alternative, if you insist on using only one element instead of two, you can set the image as a background-image of a differently sized div
#imganddiv {
border: 3px solid black;
width: 150px;
height: 100px;
background-image: url('https://i.imgur.com/QIsNrpM.png');
background-size: 100px 100px;
background-repeat: no-repeat;
background-position: right center;
}
<div id="imganddiv"></div>
I personally prefer the first option as it's a bit more intuitive and generally considered a common practice on to how containers (elements inside elements) should be handled.
To get a border taller than the image, you can wrap the image in a container, and apply the border to that container.
.top-header{
float: left;
border-left: 2px solid #CCCCCC;
height: 40px;
margin-top: 0px;
/* Center the image vertically */
display: flex;
align-items: center;
}
#signinimage{
height: 25px;
width: 25px;
padding-left: 10px;
}
<div class="top-header">
<img src="http://placekitten.com/25/25" id="signinimage">
</div>
Related
my text is overflowing see the screenshot https://drive.google.com/file/d/1i_9VvP54CAJJSvtsArZiTMMfMzACDS11/view?usp=sharing
here is css:
.card_main {
border: 1px solid black;
margin-top: 30px;
border-radius: 5px;
height: 900px;
background: #ffffff;
width: 100%;
}
.blog_content__text {
width: 95%;
height: 320px;
border-bottom: 1.5px solid lightgray;
margin-left: 2.5%;
margin-top: 20px;
}
.blog_heading {
font-size: 24px;
color: black;
}
.blog_details {
font-size: 16px;
color: black;
opacity: 0.7;
margin-top: 20px;
}
my html
<div className="card_main">
<div className="blog_content__text">
<h1 className="blog_heading">{data.blog_title}</h1>
<p className="blog_details">{data.blog_body}</p>
</div>
<div/>
how to prevent overflowing my text and make the div responsive. I am not an CSS expert. I just start learning css
When using fixed height for a div, you also need to say how the scroll should work. In this case using overflow-y:auto makes sense. You may prefer overflow-y:hidden or always show scrollbars overflow-y:scroll;
If there is no serious limitation in terms of graphics, do not specify the height for a Div to make its height responsive to the content.
.blog_content__text {
width: 95%;
height: 320px;
overflow-y:auto;
border-bottom: 1.5px solid lightgray;
margin-left: 2.5%;
margin-top: 20px;
}
remove the height: 320px;
if you must, use it as min-height: 320px;
try setting a margin-bottom css attribute to the div that contains the text, the value of the margin should equal the height of that white footer that is hiding the text on the bottom.
You can also make use of the following property if you really want to set the height:
height: min-content;
I have three social media images (Facebook, Twitter and LinkedIn) which I want to embedded on to my home page with links within, I have got the CSS for each logo but I just can't get them to line up (three in a row, centralized), any advises?
CSS:
.twitter-logo {
width: 40px;
height: 40px;
background: url("https://www.sites.com/Twitter_web.png") no-repeat;
float: left;
}
.facebook-logo {
width: 39px;
height: 40px;
background: url("https://www.sites.com/Facebook_web.png")no-repeat;
float: left;
}
.linkedin-logo {
width: 41px;
height: 40px;
background: url("https://www.sites.com/LinkedIn_web.png") no-repeat;
float: left;
}
.follow-us-three {
margin: 10px 0;
border-bottom: 1px solid #000000;
border-top: 1px solid #000000;
}
HTML
<div class="follow-us-three">
<a class="facebook-logo" href="link"></a>
<a class="twitter-logo" href="link"></a>
<a class="linkedin-logo" href="link"></a>
</div>
Try This, I think by three in a row and centralized you mean you want to set the size of the background as your link's size.
I have just added background-size:cover;
.twitter-logo {
width: 40px;
height: 40px;
background: url("download.png") no-repeat;
background-size: cover;
float: left;
}
.facebook-logo {
width: 39px;
height: 40px;
background: url("download.png") no-repeat;
background-size: cover;
float: left;
}
.linkedin-logo {
width: 41px;
height: 40px;
background: url("download.png") no-repeat;
background-size: cover;
float: left;
}
.follow-us-three {
margin: 10px 0;
border-bottom: 1px solid #000000;
border-top: 1px solid #000000;
}
you can try below css code.
.linkedin-logo,.twitter-logo,.facebook-logo{
width: 40px;
height: 40px;
background-image: url("https://pbs.twimg.com/profile_images/666407537084796928/YBGgi9BO.png");
float: left;
background-position: center;
background-size: 40px 40px;
}
.follow-us-three {
margin: 10px 10px;
border-bottom: 1px solid #000000;
border-top: 1px solid #000000;
float: left;
}
<div class="follow-us-three">
<a class="facebook-logo" href="link"></a>
<a class="twitter-logo" href="link"></a>
<a class="linkedin-logo" href="link"></a>
</div>
I just added "background-position: center; background-size: 40px 40px;" so that you can see the icons in proper way.
In the spirit of reducing replicated code I have done the following:
Created a generic logo class
Used CSS sprites to position the image.
Changed from float to inline-block to center the links easier and more efficiently.
NOTE Don't use the sprite as provided, use your own. Also note inline-block introduces about a px space between the links.
.follow-us-three .logo
{
width: 40px;
height: 40px;
background: url("http://67.media.tumblr.com/b2336d673e315081b6d657f8258c313d/tumblr_mv98xzSiJu1qhori9o1_500.jpg") no-repeat;
display:inline-block;
}
.logo.twitter {
background-position:-120px 0px ;
}
.logo.facebook {
background-position:-80px 0px ;
}
.logo.linkedin {
background-position:-325px 0px ;
}
.follow-us-three {
margin: 10px auto;
border-bottom: 1px solid #000000;
border-top: 1px solid #000000;
text-align:center;
}
<div class="follow-us-three">
<a class="logo facebook" href="link"></a>
<a class="logo twitter" href="link"></a>
<a class="logo linkedin" href="link"></a>
</div>
What i would like to suggest is use <img> tag inside your <a> tags and avoid using background property of link like
CSS:
.twitter-logo {
width: 40px;
height: 40px;
float: left;
}
.facebook-logo {
width: 39px;
height: 40px;
float: left;
margin-left:10px;
}
.linkedin-logo {
width: 41px;
height: 40px;
float: left;
margin-left:10px;
}
.follow-us-three {
margin: 10px 0;
border-bottom: 1px solid #000000;
border-top: 1px solid #000000;
}
HTML:
<div class="follow-us-three">
<img class="twitter-logo" src="https://g.twimg.com/Twitter_logo_blue.png"></img>
<img class="facebook-logo" src="https://www.facebookbrand.com/img/fb-art.jpg"/>
<img class="linkedin-logo" src="http://www.freeiconspng.com/uploads/linkedin-logo-3.png"/>
</div>
Mention whatever you like to mention in href attribute of your links and also Your links were not working so added new links.Hope it helps.
Another tip i would like to give you is start learning bootstrap because it has pre-defined icons for sites like facebook,twitter and thore icons are very good looking and easy to use.
There are two issues...
Anchor elements <a> default display is inline
You need to restore document flow with clear fix
You can easily change the display of your anchor tags by setting the display property to display: block or display: inline-block. This will allow these element to have a width and a height.
Because you are floating the elements you need to restore document flow by applying a clear fix to the parent element.
Here is an example...
https://jsfiddle.net/kennethcss/5jzqyhjh/
Also note, that you could remove the floats and just change the display property to inline-block and get the same result but either is valid.
Additional reading:
CSS Display Property
Clear Fix and Floats
I've got a div within a div, both are percentage based for the page but the nested div overlaps slightly to the right.
I'm actually trying to get the white box sit inside the first light blue div with a small margin on all sides so you can see a bit of the darker backround color, making it stand out more.
Editing to point out that the point of the position:fixed is to make the white box move as you scroll.
A solution was posted that involved chaning the position to relative, although this obviously stops the box from moving.
JSFiddle
div {
border-radius: 5px;
}
#header {
height: 50px;
background-color: #F38630;
margin-bottom: 10px;
}
.left {
height: 1300px;
width: 25%;
background-color: #A7DBD8;
float: left;
margin-bottom: 10px;
}
.right {
height: 1300px;
width: 75%;
background-color: #E0E4CC;
float: right;
margin-bottom: 10px;
}
#footer {
height: 50px;
background-color: #69D2E7;
clear: both;
}
#fixedleft {
height: 50px;
width: 25%;
background-color: #FFFFFF;
position: fixed;
margin: 1px 1px 1px 1px;
}
<html>
<head>
<title>Result</title>
</head>
<body>
<div id="header"></div>
<div class="left"><div id="fixedleft"></div></div>
<div class="right"></div>
<div id="footer"></div>
</body>
</html>
Your margin is increasing with the width.
Try:
#fixedleft {
height: 50px;
width: calc(25% - 2px);
background-color: #FFFFFF;
position: fixed;
margin: 1px;
}
I guess that this issue is due to default body margin as it doesn't affect the width of your fixed div(as you can see in the example, it's width is always the same, no matter what margin value you set, unlike it's container's width) :
body { margin:0; }
There is still a problem with the inner margin (1px) that pushes it out of the container, you can use calc for it, here is an example:
JSFiddle
#fixedleft {
background-color: #ffffff;
height: 50px;
margin: 2px;
position: relative;
width: 98%;
}
Please try this instear of
#fixedleft {
height: 50px;
width: 25%;
background-color: #FFFFFF;
position: fixed;
margin: 1px 1px 1px 1px;
}
if you load jQuery..
$(window).bind("resize", function(){
$("#fixedleft").width( parseInt($(".left").width()) -2)
})
$(function(){$(window).resize()})
tried text-align center and margin auto, both doesn't work and I do not want to used to use the 'margin hack' for centering..
http://jsfiddle.net/st9AM/1/
.circle{
float: left;
position: relative;
width: 120px;
height: 120px;
border-radius: 50%;
border: 2px solid #DDD;
}
.inner{
float: left;
position: relative;
width: 60px;
height: 60px;
border-radius: 50%;
border: 2px solid #DDD;
}
First of all, using margin: auto; is not a hack
And to center your circle inside the circle, you can use positioning techniques, like position: absolute;. Here, I am using position: absolute; on the inner circle, than am assigning top and left properties with a value of 50% and than am using margin-top and margin-left and deducting 1/2 of the height and width.
Why am deducting 32px? As I already said am deducting exactly half the total width and height so this also includes the border of your element which is set to 2px which makes your element 64px in height and width respectively.
To vertical-align the + symbol, am using line-height property as I can only see a single character to be vertically aligned(you didn't said but technically I can assume what shape are you looking for), alternatively you can also use vertical-align: middle; but you need to set the container element to display: table-cell;
Demo
Last but not the least, you should nest the span tag inside the inner circle div.
.circle{
float: left;
position: relative;
width: 120px;
height: 120px;
border-radius: 50%;
border: 2px solid #DDD;
}
.inner{
text-align: center;
line-height: 60px;
position: absolute;
top: 50%;
margin-top: -31px;
left: 50%;
margin-left: -31px;
width: 60px;
height: 60px;
border-radius: 50%;
border: 2px solid #DDD;
}
Here's a cleaner solution.
with one HTML element only.
HTML:
<div class='circle'></div>
CSS:
*
{
margin: 0;
padding: 0;
}
.circle, .circle:after
{
border-radius: 50%;
border: 2px solid #DDD;
text-align: center;
}
.circle
{
width: 120px;
height: 120px;
font-size: 0;
}
.circle:before {
content:'';
display: inline-block;
height: 100%;
vertical-align: middle;
}
.circle:after
{
content:'+';
font-size: 20px;
padding: 20px 0; /* 2*padding + font size = innerCircle height*/
display: inline-block;
vertical-align: middle;
width: 50%;
}
You had "float: left" in the inner circle, which you didn't need
//float: left;
Working fiddle
remove float left and use margin: 0 auto;
.circle{
position: relative;
width: 120px;
height: 120px;
border-radius: 50%;
border: 2px solid #DDD;
margin:0 auto;
}
Have a look at this fiddle. You wrote float:left; and wanted to center the image. Remove the float:left; and it works fine.
Current browsers (May-22) work with this (replace 261px and 165x by 50% of your image size... mine is 522px x 330px ):
{
position:absolute;
left: calc( 50% - 261px );
top: calc( 50% - 165px );
}
I do not understand why in this simple code my .slot or .card classes seems to have a bigger margin/distance to their border at the bottom than at the top.
Thanks in advance,
JsFiddle: http://jsfiddle.net/Tighttempo/LgeAf/
<div id="hand">
<div class="card" id="card1"></div>
<div class="card" id="card2"></div>
<div class="card" id="card3"></div>
<div class="card" id="card4"></div>
</div>
<div id="playfield">
<div class="slot" id="slot1"></div>
<div class="slot" id="slot2"></div>
<div class="slot" id="slot3"></div>
<div class="slot" id="slot4"></div>
</div>
The CSS:
#hand{
text-align: center;
width: 320px;
border: solid black 3px;
padding: 5px;
}
.card{
display: inline-block;
width: 60px;
height: 90px;
border-radius: 5%;
background: teal;
margin: 0px 5px 0px 5px;
}
#playfield{
width: 320px;
text-align: center;
border: solid black 3px;
padding: 5px;
}
.slot{
display: inline-block;
width: 60px;
height: 90px;
border-radius: 5%;
border: dashed grey 2px;
margin: 0px 5px 0px 5px;
}
Thanks in advance!
If you are not comfortable with making the font-size:0 then here is a solution that i personally prefer.
Display:inline-block is tricky and has strange issues with margins. What i personally do is, i use float instead of inline-block. See this :
.card{
width: 60px;
height: 90px;
border-radius: 5%;
background: teal;
margin: 0px 10px;
float:left;
}
.slot{
width: 60px;
height: 90px;
border-radius: 5%;
border: dashed grey 2px;
margin: 0px 8px;
float:left;
}
What i did is, i added float:left to your .slot and .card and then created a new class .cls(clear:both) and applied that in the div structure. See if this helps.
http://jsfiddle.net/LgeAf/3/
Inline-block elements are tricky - because they are not treated as block elements when it comes to positioning them in the document flow. Their positions and spacings are influenced by CSS properties that control text, like line-height, word-spacing, letter-spacing and font-sizes.
If you set font-size in the parent containers, #card and #playfield, to 0, you will remove the extra bottom margin. See fiddle - http://jsfiddle.net/teddyrised/GwqcV/
#hand, #playfield {
font-size: 0;
}
The drawback of this method is that you will have to redeclare the font-size in the child elements if you are using relative font sizes, like ems.