Align span elements in div horizontally center











up vote
0
down vote

favorite












My problem is, that i cant align the span elements horizontally center or middle in the div, or inside the a element.



What i tryed, but didnt work:



.fejlec_kosar{text-align:center}
.fejlec_kosar a{display:block;text-align:center}


What am i doing wrong? My code looks like this:



<div class="col-md-2 col-xs-4 fejlec_kosar">
<a href="<?php echo $host; ?>/kosar" title="Kosár">
<span class="header_kosar_text"><i class="fa fa-shopping-cart fejlec_kosar_ikon" aria-hidden="true"></i> Kosár</span>
<span id="header_kosar_text"></span>
<div class="clearfix"></div>
</a>
</div>


.fejlec_kosar {
margin-top: 18px;
-webkit-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;
border: none;
border-radius: 25px;
background-color: #fbab35;
color: #173f62;
padding: 10px 0;
}
.fejlec_kosar_ikon {
color: #173f62;
margin-right: 10px;
font-size: 20px;
}
.header_kosar_text {
color: #173f62;
font-size: 16px;
font-weight: 500;
float: left;
line-height: 30px;
}
#header_kosar_text {
border-radius: 50%;
background-color: #d5902b;
color: #fff;
font-size: 12px;
font-weight: bold;
display: block;
float: left;
height: 30px;
width: 30px;
text-align: center;
line-height: 30px;
margin-left: 10px;
}









share|improve this question






















  • You can achieve that with flex box
    – Bhimashankar Mantur
    Nov 10 at 18:20

















up vote
0
down vote

favorite












My problem is, that i cant align the span elements horizontally center or middle in the div, or inside the a element.



What i tryed, but didnt work:



.fejlec_kosar{text-align:center}
.fejlec_kosar a{display:block;text-align:center}


What am i doing wrong? My code looks like this:



<div class="col-md-2 col-xs-4 fejlec_kosar">
<a href="<?php echo $host; ?>/kosar" title="Kosár">
<span class="header_kosar_text"><i class="fa fa-shopping-cart fejlec_kosar_ikon" aria-hidden="true"></i> Kosár</span>
<span id="header_kosar_text"></span>
<div class="clearfix"></div>
</a>
</div>


.fejlec_kosar {
margin-top: 18px;
-webkit-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;
border: none;
border-radius: 25px;
background-color: #fbab35;
color: #173f62;
padding: 10px 0;
}
.fejlec_kosar_ikon {
color: #173f62;
margin-right: 10px;
font-size: 20px;
}
.header_kosar_text {
color: #173f62;
font-size: 16px;
font-weight: 500;
float: left;
line-height: 30px;
}
#header_kosar_text {
border-radius: 50%;
background-color: #d5902b;
color: #fff;
font-size: 12px;
font-weight: bold;
display: block;
float: left;
height: 30px;
width: 30px;
text-align: center;
line-height: 30px;
margin-left: 10px;
}









share|improve this question






















  • You can achieve that with flex box
    – Bhimashankar Mantur
    Nov 10 at 18:20















up vote
0
down vote

favorite









up vote
0
down vote

favorite











My problem is, that i cant align the span elements horizontally center or middle in the div, or inside the a element.



What i tryed, but didnt work:



.fejlec_kosar{text-align:center}
.fejlec_kosar a{display:block;text-align:center}


What am i doing wrong? My code looks like this:



<div class="col-md-2 col-xs-4 fejlec_kosar">
<a href="<?php echo $host; ?>/kosar" title="Kosár">
<span class="header_kosar_text"><i class="fa fa-shopping-cart fejlec_kosar_ikon" aria-hidden="true"></i> Kosár</span>
<span id="header_kosar_text"></span>
<div class="clearfix"></div>
</a>
</div>


.fejlec_kosar {
margin-top: 18px;
-webkit-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;
border: none;
border-radius: 25px;
background-color: #fbab35;
color: #173f62;
padding: 10px 0;
}
.fejlec_kosar_ikon {
color: #173f62;
margin-right: 10px;
font-size: 20px;
}
.header_kosar_text {
color: #173f62;
font-size: 16px;
font-weight: 500;
float: left;
line-height: 30px;
}
#header_kosar_text {
border-radius: 50%;
background-color: #d5902b;
color: #fff;
font-size: 12px;
font-weight: bold;
display: block;
float: left;
height: 30px;
width: 30px;
text-align: center;
line-height: 30px;
margin-left: 10px;
}









share|improve this question













My problem is, that i cant align the span elements horizontally center or middle in the div, or inside the a element.



What i tryed, but didnt work:



.fejlec_kosar{text-align:center}
.fejlec_kosar a{display:block;text-align:center}


What am i doing wrong? My code looks like this:



<div class="col-md-2 col-xs-4 fejlec_kosar">
<a href="<?php echo $host; ?>/kosar" title="Kosár">
<span class="header_kosar_text"><i class="fa fa-shopping-cart fejlec_kosar_ikon" aria-hidden="true"></i> Kosár</span>
<span id="header_kosar_text"></span>
<div class="clearfix"></div>
</a>
</div>


.fejlec_kosar {
margin-top: 18px;
-webkit-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;
border: none;
border-radius: 25px;
background-color: #fbab35;
color: #173f62;
padding: 10px 0;
}
.fejlec_kosar_ikon {
color: #173f62;
margin-right: 10px;
font-size: 20px;
}
.header_kosar_text {
color: #173f62;
font-size: 16px;
font-weight: 500;
float: left;
line-height: 30px;
}
#header_kosar_text {
border-radius: 50%;
background-color: #d5902b;
color: #fff;
font-size: 12px;
font-weight: bold;
display: block;
float: left;
height: 30px;
width: 30px;
text-align: center;
line-height: 30px;
margin-left: 10px;
}






html css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 18:15









max777

31




31












  • You can achieve that with flex box
    – Bhimashankar Mantur
    Nov 10 at 18:20




















  • You can achieve that with flex box
    – Bhimashankar Mantur
    Nov 10 at 18:20


















You can achieve that with flex box
– Bhimashankar Mantur
Nov 10 at 18:20






You can achieve that with flex box
– Bhimashankar Mantur
Nov 10 at 18:20














2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










As you read in the comments, yo can achieve this using flexbox, what you need to do is



.fejlec_kosar {
margin-top: 18px;
-webkit-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;
border: none;
border-radius: 25px;
background-color: #fbab35;
color: #173f62;
padding: 10px 0;
display: flex; //ADDED
justify-content: center; //ADDED
}


And that should work, here you have an article that will help you to understand how flexbox work;






share|improve this answer





















  • Thanks, its okay!
    – max777
    Nov 10 at 21:45


















up vote
0
down vote













you can create same in other way. try below code snippet.






.try-btn{
width: 40%;
margin-top: 18px;
-webkit-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;
border: none;
border-radius: 25px !important;
background-color: #fbab35;
color: #173f62;
padding: 10px 0;
}

<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
<div class="col-md-2 col-xs-4">
<a href="#" class="btn btn-lg btn-default try-btn"><span class="fa fa-shopping-cart"></span> Kosár</a>
</div>
</div>








share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241993%2falign-span-elements-in-div-horizontally-center%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    As you read in the comments, yo can achieve this using flexbox, what you need to do is



    .fejlec_kosar {
    margin-top: 18px;
    -webkit-transition: .3s linear;
    -o-transition: .3s linear;
    transition: .3s linear;
    border: none;
    border-radius: 25px;
    background-color: #fbab35;
    color: #173f62;
    padding: 10px 0;
    display: flex; //ADDED
    justify-content: center; //ADDED
    }


    And that should work, here you have an article that will help you to understand how flexbox work;






    share|improve this answer





















    • Thanks, its okay!
      – max777
      Nov 10 at 21:45















    up vote
    0
    down vote



    accepted










    As you read in the comments, yo can achieve this using flexbox, what you need to do is



    .fejlec_kosar {
    margin-top: 18px;
    -webkit-transition: .3s linear;
    -o-transition: .3s linear;
    transition: .3s linear;
    border: none;
    border-radius: 25px;
    background-color: #fbab35;
    color: #173f62;
    padding: 10px 0;
    display: flex; //ADDED
    justify-content: center; //ADDED
    }


    And that should work, here you have an article that will help you to understand how flexbox work;






    share|improve this answer





















    • Thanks, its okay!
      – max777
      Nov 10 at 21:45













    up vote
    0
    down vote



    accepted







    up vote
    0
    down vote



    accepted






    As you read in the comments, yo can achieve this using flexbox, what you need to do is



    .fejlec_kosar {
    margin-top: 18px;
    -webkit-transition: .3s linear;
    -o-transition: .3s linear;
    transition: .3s linear;
    border: none;
    border-radius: 25px;
    background-color: #fbab35;
    color: #173f62;
    padding: 10px 0;
    display: flex; //ADDED
    justify-content: center; //ADDED
    }


    And that should work, here you have an article that will help you to understand how flexbox work;






    share|improve this answer












    As you read in the comments, yo can achieve this using flexbox, what you need to do is



    .fejlec_kosar {
    margin-top: 18px;
    -webkit-transition: .3s linear;
    -o-transition: .3s linear;
    transition: .3s linear;
    border: none;
    border-radius: 25px;
    background-color: #fbab35;
    color: #173f62;
    padding: 10px 0;
    display: flex; //ADDED
    justify-content: center; //ADDED
    }


    And that should work, here you have an article that will help you to understand how flexbox work;







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 10 at 19:18









    MartinBA

    70513




    70513












    • Thanks, its okay!
      – max777
      Nov 10 at 21:45


















    • Thanks, its okay!
      – max777
      Nov 10 at 21:45
















    Thanks, its okay!
    – max777
    Nov 10 at 21:45




    Thanks, its okay!
    – max777
    Nov 10 at 21:45












    up vote
    0
    down vote













    you can create same in other way. try below code snippet.






    .try-btn{
    width: 40%;
    margin-top: 18px;
    -webkit-transition: .3s linear;
    -o-transition: .3s linear;
    transition: .3s linear;
    border: none;
    border-radius: 25px !important;
    background-color: #fbab35;
    color: #173f62;
    padding: 10px 0;
    }

    <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

    <div class="container">
    <div class="col-md-2 col-xs-4">
    <a href="#" class="btn btn-lg btn-default try-btn"><span class="fa fa-shopping-cart"></span> Kosár</a>
    </div>
    </div>








    share|improve this answer

























      up vote
      0
      down vote













      you can create same in other way. try below code snippet.






      .try-btn{
      width: 40%;
      margin-top: 18px;
      -webkit-transition: .3s linear;
      -o-transition: .3s linear;
      transition: .3s linear;
      border: none;
      border-radius: 25px !important;
      background-color: #fbab35;
      color: #173f62;
      padding: 10px 0;
      }

      <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
      <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

      <div class="container">
      <div class="col-md-2 col-xs-4">
      <a href="#" class="btn btn-lg btn-default try-btn"><span class="fa fa-shopping-cart"></span> Kosár</a>
      </div>
      </div>








      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        you can create same in other way. try below code snippet.






        .try-btn{
        width: 40%;
        margin-top: 18px;
        -webkit-transition: .3s linear;
        -o-transition: .3s linear;
        transition: .3s linear;
        border: none;
        border-radius: 25px !important;
        background-color: #fbab35;
        color: #173f62;
        padding: 10px 0;
        }

        <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

        <div class="container">
        <div class="col-md-2 col-xs-4">
        <a href="#" class="btn btn-lg btn-default try-btn"><span class="fa fa-shopping-cart"></span> Kosár</a>
        </div>
        </div>








        share|improve this answer












        you can create same in other way. try below code snippet.






        .try-btn{
        width: 40%;
        margin-top: 18px;
        -webkit-transition: .3s linear;
        -o-transition: .3s linear;
        transition: .3s linear;
        border: none;
        border-radius: 25px !important;
        background-color: #fbab35;
        color: #173f62;
        padding: 10px 0;
        }

        <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

        <div class="container">
        <div class="col-md-2 col-xs-4">
        <a href="#" class="btn btn-lg btn-default try-btn"><span class="fa fa-shopping-cart"></span> Kosár</a>
        </div>
        </div>








        .try-btn{
        width: 40%;
        margin-top: 18px;
        -webkit-transition: .3s linear;
        -o-transition: .3s linear;
        transition: .3s linear;
        border: none;
        border-radius: 25px !important;
        background-color: #fbab35;
        color: #173f62;
        padding: 10px 0;
        }

        <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

        <div class="container">
        <div class="col-md-2 col-xs-4">
        <a href="#" class="btn btn-lg btn-default try-btn"><span class="fa fa-shopping-cart"></span> Kosár</a>
        </div>
        </div>





        .try-btn{
        width: 40%;
        margin-top: 18px;
        -webkit-transition: .3s linear;
        -o-transition: .3s linear;
        transition: .3s linear;
        border: none;
        border-radius: 25px !important;
        background-color: #fbab35;
        color: #173f62;
        padding: 10px 0;
        }

        <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

        <div class="container">
        <div class="col-md-2 col-xs-4">
        <a href="#" class="btn btn-lg btn-default try-btn"><span class="fa fa-shopping-cart"></span> Kosár</a>
        </div>
        </div>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 19:22









        Shiv Kumar Baghel

        1,0622617




        1,0622617






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241993%2falign-span-elements-in-div-horizontally-center%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values