Make width of <a> to have a width equal to its content - css

In the first example below, the id="A_2" has a width equal to its content, while the one second, it id="A_4" has a width equal to its parent. How can I change the second snippet to have width equal to its content?
This snippet is from Google
Play Store Code
#H1_1 {
box-sizing: border-box;
color: rgb(51, 51, 51);
font-family: Roboto, UILanguageFont, Arial, sans-serif;
font-size: 28px;
font-weight: 100;
height: 75px;
line-height: 39.2000007629395px;
min-height: 37px;
min-width: 680px;
padding: 5px;
position: relative;
text-align: left;
width: 1088px;
perspective-origin: 544px 37.5px;
transform-origin: 544px 37.5px;
border: 0px none rgb(51, 51, 51);
font: normal normal 100 normal 28px/39.2000007629395px Roboto, UILanguageFont, Arial, sans-serif;
margin: 0px 50px 0px 248px;
outline: rgb(51, 51, 51) none 0px;
padding: 5px;
}/*#H1_1*/
#A_2 {
color: rgb(51, 51, 51);
font-family: Roboto, UILanguageFont, Arial, sans-serif;
font-size: 28px;
font-weight: 100;
line-height: 39.2000007629395px;
text-align: left;
text-decoration: none;
font: normal normal 100 normal 28px/39.2000007629395px Roboto, UILanguageFont, Arial, sans-serif;
}/*#A_2*/
#A_3 {
color: rgb(85, 85, 85);
display: block;
font-family: Roboto, UILanguageFont, Arial, sans-serif;
font-size: 16px;
font-weight: 300;
height: 22px;
line-height: 22.3999996185303px;
padding-bottom: 4px;
text-align: left;
text-decoration: none;
width: 1078px;
font: normal normal 300 normal; 16px/22.3999996185303px Roboto, UILanguageFont, Arial, sans-serif;
padding: 0px 0px 4px;
}
<h1 id="H1_1">
Cricket Fever Get cool games + Cricket apps
</h1>
Here is
My Code
#H1_1 {
display: flex;
height: 60px;
min-height: 37px;
min-width: 680px;
position: relative;
width: 1088px;
align-items: stretch;
justify-content: flex-start;
flex-flow: column nowrap;
font: normal normal bold normal 32px/normal Roboto, UILanguageFont, Arial, sans-serif;
margin: 0px 50px 0px 248px;
padding: 5px;
}/*#H1_1*/
#A_2 {
color: rgb(85, 85, 85);
height: 34px;
text-decoration: none;
align-self: stretch;
border: 0px none rgb(85, 85, 85);
font: normal normal 100 normal 28px/normal Roboto, UILanguageFont, Arial, sans-serif;
}/*#A_2*/
#A_3 {
box-sizing: border-box;
color: rgb(85, 85, 85);
height: 23px;
text-decoration: none;
align-self: stretch;
border: 0px none rgb(85, 85, 85);
font: normal normal 300 normal 16px/normal Roboto, UILanguageFont, Arial, sans-serif;
margin: 3px 0px 0px;
padding: 0px 0px 4px;
}/*#A_3*/
<h1 id="H1_1">
<a id="A_2" href="">Cricket Fever</a> <a id="A_3" href="">Get cool games + Cricket apps</a>
</h1>

If I understand correctly, you want a#A_4 to be as width as it's content... right?
Then remove the display: block from it.
To make the link appear on a new line, simply add a line break to it.
Updated Codepen

The <h1> element has the same width as it content, or bigger if you define it.
There are inline elements and block elements. Inline elements a width equal to its content, the block elements use all the available width.
Since you defined 'A_4' as block, it will use all the available width.
Element <a> is an inline element, so it will have the same width as it content.
Remove the 'display:block' from the <a> elements, and all the fixed width or min-width values. To separate your link for different lines, separate then using <br/> element.
EDIT:
example:
HTML
<h1 id="H1_1">
<a id="A_2" href="">Cricket Fever</a>
<br/>
<a id="A_3" href="">Get cool games + Cricket apps</a>
</h1>
CSS
#H1_1 {
background-color: #000;
margin: 0px 50px 0px 248px;
padding: 5px;
}/*#H1_1*/
#A_2 {
background-color: #666;
color: rgb(85, 85, 85);
height: 34px;
text-decoration: none;
}/*#A_2*/
#A_3 {
background-color: #999;
color: rgb(85, 85, 85);
text-decoration: none;
margin: 3px 0px 0px;
padding: 0px 0px 4px;
}/*#A_3*/

Related

Adding a fav icon in a button using only CSS

https://codepen.io/danielworton/pen/ZZLEMO
Hello, I'm trying to re-create the button in the codepen linked above and I have an issue adding the stars without changing the script. Also the different colored double border ~ If anyone has any clue to a solution it would be very welcome!
#My solution is as follows:
a {
border: solid 3px #212121;
border-radius: 12px;
background-image: linear-gradient(0deg,#D3D3D3 0%,#D3D3D3 50%,#e8e8e8 51%);
color: #212121;
padding: 20px;
text-align: center;
text-decoration:none;
text-transform: uppercase;
font-family: "Lucida Console", Courier, monospace;
font-size: 18px;
width: 180px;
height: 14px;
display: inline-block;
margin: auto;
}
You can use pseudo elements to add more elements:
a {
border: solid 2px #555;
border-radius: 12px;
background-image: linear-gradient(0deg, #D3D3D3 0%, #D3D3D3 50%, #e8e8e8 51%);
color: #555;
padding: 20px 20px;
text-align: center;
text-decoration: none;
text-transform: uppercase;
font-family: "Arial";
font-size: 18px;
width: 180px;
height: 14px;
display: inline-block;
margin: auto;
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
text-shadow: 1px 1px 1px white;
font-weight: 600;
box-shadow: 0 0 0 6px #D3D3D3, 0 0 0 8px #555;
}
a:after, a:before {
content: '★';
position: absolute;
width: 100%;
left: 0;
top: 0;
display: flex;
align-items: center;
height: 100%;
padding: 0 20px;
box-sizing: border-box;
font-size: 24px;
line-height: 24px;
}
a:before {
justify-content: flex-end;
}
<a href="#">
Checkout
</a>
Although, the amount of borders on that button is kind of ridiculous to expect from one element I think.
Edit: you can add multiple borders with boxshadows

Bootstrap - why is my button not responsive?

As you can see on the screenshot below, my pink button is not fully responsive: below a certain width it gets cut instead of resizing to remain within the viewport width.
What is the issue?
Many thanks
.btn {
background-color: #ff00bf;
border: 0 none;
border-radius: 25px;
box-shadow: 0 11px 22px rgba(34, 34, 34, 0.2);
color: #fff;
display: inline-block;
font-size: 1rem;
letter-spacing: 0.025em;
padding: 1.1em 2.28em 1em;
text-decoration: none;
transition: all 0.3s ease-out 0s;
}
.btn {
-moz-user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: normal;
line-height: 1.42857;
margin-bottom: 0;
padding: 6px 12px;
text-align: center;
touch-action: manipulation;
vertical-align: middle;
white-space: nowrap;
}
The white-space: nowrap makes line-breaking impossible. Just remove it. Also I would set the max-width to 100%.
.btn {
background-color: #ff00bf;
border: 0 none;
border-radius: 25px;
box-shadow: 0 11px 22px rgba(34, 34, 34, 0.2);
color: #fff;
display: inline-block;
font-size: 1rem;
letter-spacing: 0.025em;
padding: 1.1em 2.28em 1em;
text-decoration: none;
transition: all 0.3s ease-out 0s;
}
.btn {
-moz-user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: normal;
line-height: 1.42857;
margin-bottom: 0;
padding: 6px 12px;
text-align: center;
touch-action: manipulation;
vertical-align: middle;
max-width: 100%;
}

Show text and icon in the middle of a button

I am coding a button with html5 and css3. Here are how it looks in different sizes:
You can see the icons are not in the middle. I know why it happens. But how can I set the icons in middle? Here is my code:
<i class="icon">a</i><span>start</span>
CSS:
.blue-pill {
display: block;
text-decoration: none;
width: 135px;
height: 50px;
margin-bottom: 15px;
position: relative;
background-color: #002032;
border: none;
color: #FFF;
text-transform: uppercase;
font-family: 'Open Sans Condensed', sans-serif;
font-weight: 700;
font-size: 14px;
padding: 0;
border-radius: 50px;
cursor: pointer;
z-index: 2;
text-align: center;
line-height: 50px;
-webkit-box-shadow: 0px 5px 0px #1488ae;
-moz-box-shadow: 0px 5px 0px #1488ae;
box-shadow: 0px 5px 0px #1488ae;
}
.blue-pill .icon {
display: inline-block;
margin: 0 5px;
color: #e57125;
font-size: 20px;
}
.blue-pill span {
display: inline-block;
}
.blue-pill.centered {
margin-left: auto;
margin-right: auto;
}
.blue-pill.inline {
display: inline-block;
margin-left: 5px;
margin-right: 5px;
}
I am using icon fonts for icons. Here is what I want:
add vertical-align:middle to .blue-pill .icon and .blue-pill span
Example

How to avoid these overlapping elements

I was toying with some made code on codepen, trying to get used to html/css since I am not really comfortable on the positioning. This must be pretty silly but I can't make it work.
HTML:
<div id="hh">
<h1>Wacom Hover Effect</h1>
</div>
<div id="cl">
Read More
Learn More
Read Article
Download
</div>
CSS:
*, :before, :after{ #include box-sizing('border-box'); }
body{ padding: 1em; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background: #eee; }
#hh{
position:absolute;
left:50%
}
h1{
position:relative;
left:-50%;
font: 300 3em/1em 'Open Sans', sans-serif;
border: solid 0.00019em #000;
margin-bottom: 0.2em;
padding: 0.4em 0.2em 0.4em 0.2em;
background-color:lightblue;
border-radius:0.2em;
}
#cl{
clear:both;
}
.button,
[class*="button-"]{
position: relative;
display: inline-block;
overflow: hidden;
float:left;
margin: 0 1em 1em 0;
padding: 0 4em;
height: 3.5em;
font: 300 1em/3.5em 'Open Sans', sans-serif;
text:{
decoration: none;
shadow: 0 1px 3px rgba(black, .35);
}
letter-spacing: .08em;
color: #fff;
background: #0090C0;
border: solid 1px #fff;
border-radius: 2px;
#include transition(.35s ease all);
}
}
There is some irrelevant code after that about hovering etc.
The result is this: http://codepen.io/roygbiv/full/FjLcA
So I wanted h1 at center and I found here the method of putting #hh absolute, left:50% and then h1 relative left:-50%. And it screwed up the positioning.
What I want is h1 on center top, then the 4 "a"s under it (not center, just not overlapping).
Putting position: absolute on an element makes all other elements ignore it. This can be solved by putting display: inline-block on the h1 and text-align: center on #hh:
Check new pen: http://codepen.io/anon/pen/kovaC
#hh {
text-align: center;
}
h1{
font: 300 3em/1em 'Open Sans', sans-serif;
border: solid 0.00019em #000;
margin-bottom: 0.2em;
padding: 0.4em 0.2em 0.4em 0.2em;
background-color:lightblue;
border-radius:0.2em;
display: inline-block;
}
inline-block makes the element's box adapt to the width of its text. I presume the desired look of the header is for the blue box to not be 100% width, which is otherwise the case with h1 and other block elements.
i have done the following modification in css and it is working as expected:
#hh{
text-align: center;
margin-left:auto;
margin-right:auto;
width:40%;
}
h1{
font: 300 3em/1em 'Open Sans', sans-serif;
border: solid 0.00019em #000;
margin-bottom: 0.2em;
padding: 0.4em 0.2em 0.4em 0.2em;
background-color:lightblue;
border-radius:0.2em;
}

Position div vertically in the middle

How would I go about setting up a div horizontally/vertically in the middle?
Here is my code so far:
HTML
<div id="outer">
<div id="inner">
<div id="signin_header">
Sign in
</div>
</div>
</div>
CSS
html, body {
height: 100%;
}
html {
display: table;
margin: auto;
height: 100%;
}
body {
display: table-cell;
}
#outer {
width: 100%;
text-align: center;
height: 100%;
}
#inner {
display: inline-block;
background-color: rgb(245, 245, 245);
background-image: none;
background-origin: padding-box;
background-size: auto;
border-bottom-color: rgb(229, 229, 229);
border-bottom-style: solid;
border-bottom-width: 1px;
border-left-color: rgb(229, 229, 229);
border-left-style: solid;
border-left-width: 1px;
border-right-color: rgb(229, 229, 229);
border-right-style: solid;
border-right-width: 1px;
border-top-color: rgb(229, 229, 229);
border-top-style: solid;
border-top-width: 1px;
display: block;
font-family: 'segoe ui', arial, helvetica, sans-serif;
font-size: 13px;
width: 300px;
padding: 25px;
}
#signin_header {
color: rgb(34, 34, 34);
display: block;
font-family: 'segoe ui', arial, helvetica, sans-serif;
font-size: 16px;
font-weight: normal;
height: 16px;
line-height: 16px;
margin-top: 0px;
width: 283px;
text-align: left;
}
Fiddle can be found here
http://jsfiddle.net/yaFeD/
Is this what you're after? I think this is what you were wanting?
html, body {
height: 100%;
}
html {
display: table;
margin: auto;
height: 100%;
}
body {
display: table-cell;
}
#outer {
width: 100%;
text-align: center;
height: 100%;
position:relative;
top:50%;
bottom:50%;
}
#inner {
display: inline-block;
background-color: rgb(245, 245, 245);
background-image: none;
background-origin: padding-box;
background-size: auto;
border-bottom-color: rgb(229, 229, 229);
border-bottom-style: solid;
border-bottom-width: 1px;
border-left-color: rgb(229, 229, 229);
border-left-style: solid;
border-left-width: 1px;
border-right-color: rgb(229, 229, 229);
border-right-style: solid;
border-right-width: 1px;
border-top-color: rgb(229, 229, 229);
border-top-style: solid;
border-top-width: 1px;
display: block;
font-family: 'segoe ui', arial, helvetica, sans-serif;
font-size: 13px;
width: 300px;
padding: 25px;
}
#signin_header {
color: rgb(34, 34, 34);
display: block;
font-family: 'segoe ui', arial, helvetica, sans-serif;
font-size: 16px;
font-weight: normal;
height: 16px;
line-height: 16px;
margin-top: 0px;
width: 283px;
text-align: left;
}
http://jsfiddle.net/EQjHz/
Assuming you are trying to center the Sign In div (not the lettering itself) this is the new CSS you would need, tested in your jsfiddle, by using margin: 0 auto; and position: relative; your setting the div in the middle of that div.
#signin_header {
color: rgb(34, 34, 34);
display: block;
font-family: 'segoe ui', arial, helvetica, sans-serif;
font-size: 16px;
font-weight: normal;
height: 16px;
line-height: 16px;
margin: 0 auto;
position: relative;
width: 283px;
}
edit: i also took your text-align: left; out
Adding margin:auto; to the inner-div will do the trick.
When you only want horizontal alignment, add only margin-left:auto;margin-right:auto;.
Likewise for vertical alignment, add margin-bottom:auto;margin-top:auto;

Resources