I'm looking to minimize the size of this Button I created. Currently, the background color of the button extends too far beyond the expected range. How can I fix

https://i.sstatic.net/kJcRX.pngThe background color of my button is extending too far out on both the right and left sides. I attempted to correct it by adjusting the width, but then the button ended up being off-center. I'm having trouble fixing this issue. What steps should I take to resolve the problem.

.destination-reccomendations{
    background-image: url(Images/*****************);
    background-position: center;
    background-size: cover;
    position: relative;
    min-height: 50vh;
    width: 100%;
}
.dr-text{
    text-align: center;
    color: white;
    position: absolute;
    transform: translate(-50%, -50%);
    left: 50%;
    top: 40%;
}
.dr-text h1{
    text-align: center;
    font-size: 50px;
}
.dr-text h3{
    text-align: center;
    font-size: 25px;
    padding-bottom: 20px;
}
.button{
    background-color: green;
    border-radius: 30px;
    padding: 5px;
}
.button-text h1{
    color: black;
    font-size: 30px;
}
<section class="destination-reccomendations">
        <div class="dr-text">
            <h1>Explore the Beauty of our State</h1>
            <h3>Read more about destinations and reccomendations</h3>
            <div class="button">
                <div class="button-text">
                    <h1>Read More</h1>
                </div>
            </div>
        </div>

Answer №1

In order to adjust the size of the button, it's recommended to decrease the padding within the .dr-text and .dr-text h3 CSS properties.

Answer №2

To ensure your button is a specific width and remains centered, simply adjust the following class:

.button{
    background-color: green;
    border-radius: 30px;
    padding: 5px;
    width:200px;
    margin-left:auto;
    margin-right:auto;
}

Take a look at this example snippet for reference.

.destination-reccomendations{
    background-image: url(https://dummyimage.com/800x405/8a8a8a/fff&text=+);
    background-position: center;
    background-size: cover;
    position: relative;
    min-height: 50vh;
    width: 100%;
}
.dr-text{
    text-align: center;
    color:white;
    position: absolute;
    transform: translate(-50%, -30%);
    left: 50%;
    top: 40%;
}
.dr-text h1{
    text-align: center;
    font-size: 50px;
}
.dr-text h3{
    text-align: center;
    font-size: 25px;
    padding-bottom: 20px;
}
.button{
    background-color: green;
    border-radius: 30px;
    padding: 5px;
    width:200px;
    margin-left:auto;
    margin-right:auto;
}
.button-text h1{
    color: black;
    font-size: 30px;
}
<section class="destination-reccomendations">
        <div class="dr-text">
            <h1>Explore the Beauty of our State</h1>
            <h3>Read more about destinations and reccomendations</h3>
            <div class="button">
                <div class="button-text">
                    <h1>Read More</h1>
                </div>
            </div>
        </div>
</section>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Failure to Include jQuery in Header.php File

After adding the jQuery library to header.php, I encountered an issue where index.php was unable to access the library. Surprisingly, when the library was referenced directly from index.php, access to the jQuery library worked without any problems. Here i ...

Error: Unable to locate the reference

Having trouble with my JavaScript code not recognizing the linked .js files I added. I initially linked them through CodePen, but manual references don't seem to be working. Attempted suggestions from this page Why does jQuery or a DOM method such as ...

problem when trying to establish the minimum height for a div element prior to the website being fully loaded, considering the

Having trouble with a CSS issue that seems simple but I can't find a solution for. I have a main div with a min-height set to a certain value, specified in %. Since there is no outer div, the min-height won't display if it's given in px. I ...

Is it possible for me to create a PHP daily reward system?

I have a MySQL database with a column titled "heart" set up like this: ID NAME HEART 001 AAA 5 002 BBB 22 003 CCC 15 004 DDD 12 Now, I want to implement a daily reward function where users receive an additional heart each day they log in. Can s ...

Displaying data retrieved from PostgreSQL query

I'm currently developing a PHP data analysis tool that pulls data from our production server, which uses Postgres, and displays it. During the process, I run a select query in a loop where the date is passed as a variable, resulting in output like th ...

Loading indicator for buttons

Issue with submit button onclick function (onClick="mandatoryNotes()"). It is taking a while to load, so a preloader script was added. The preloader is now working, but the function is not being called. Seeking assistance. Thank you. function mandatoryN ...

Update the content of an image in a Div without altering its filename

My application's backend updates an image file and sends the filename back to the front-end: $('#giffinal').html(ResponseGo); However, when I update the image again through the backend, the code in the div on the front-end does not change. ...

Attach a tab-icon to a picture

I am looking to add a tab to the bottom border of an image within a gallery. This tab needs to be right up against the image border with no space in between. When clicked, this tab should activate a small JavaScript function that will display the content ...

html2canvas bottom margin

I coded this in react function download(element) { html2canvas(element).then((canvas) => { window.open(canvas.toDataURL('image/png')); }); } return ( <div className='box' onClick={( ...

Stop the selection of text within rt tags (furigana)

I love incorporating ruby annotation to include furigana above Japanese characters: <ruby><rb>漢</rb><rt>かん</rt></ruby><ruby><rb>字</rb><rt>じ</rt></ruby> However, when attemp ...

What is the best way to align a flex container both vertically and horizontally, all while keeping a footer in place?

Is there a way to center a sentence both vertically and horizontally within one flex container, while also keeping a footer visible on the screen? <div class="d-flex flex-column h-100 p-3 bg-primary"> <div class="p-3 bg-info flex-grow-1"> ...

When the specified width is reached, jQuery will reveal hidden circular text upon page load instead of keeping it hidden

My current issue involves utilizing jQuery to hide circular text when the window width is below 760px. Although the functionality works as intended, there is a minor problem when the page loads under 760px width - the text briefly shows up before hiding ag ...

New HTML output is displaying strangely when using jQuery AJAX

My jQuery AJAX function retrieves new HTML content from a PHP script. The PHP script is functioning correctly and sending back the accurate HTML to jQuery. However, when I utilize the html() function, the displayed HTML is incorrect. To verify the returned ...

Tips for identifying if the cursor is hovering over the :before or :after section of an element

One of the challenges I am facing involves CSS and defining drop areas for users to interact with, allowing them to either drop a section before or after existing sections. .section:before, .section:after { content: "[insert here]"; height: 64px; ...

Issue with jQuery DataTables column.width setting failing to meet expectations

Currently, I am utilizing datatables for my project. According to the datatables documentation found here, it suggests using the columns.width option to manage column width. However, when I implement columns.width and render the table, it seems to disreg ...

Navigation through Image Filters

Everything seems fine with my code, but when I click on the navigation links, they direct me to index.html or the landing project instead of filtering the images. How can I modify the links to properly filter the images? This is the Javascript and html co ...

Overflow of dropdown menus in HTML CSS

Hello, I am new to both html and stack overflow. Please forgive me if this question has already been asked, as I couldn't find anything (but maybe I didn't search enough?). I have tried using overflow and clear properties, but I am struggling to ...

Why Aren't Static Positioned Divs Aligning at the Parent's Top?

I am facing an issue where I have 3 divs with content inside them, and the two smaller ones are aligning at the bottom of the larger div. Despite no presence of margin or padding, this alignment mystery has left me puzzled. body { width: 100% } .cont ...

Utilizing /deep/ and the triple greater than symbol (>>>) within Angular 2

After researching the /deep/ and ::shadow selectors, I've come across conflicting information. In a discussion on Stack Overflow: What do /deep/ and ::shadow mean in a CSS selector? It was noted that Chrome has deprecated the /deep/ combinator and i ...

Guide on crafting a scrollable and touch-responsive grid using CSS and JavaScript

I am seeking guidance on creating a grid with a variable number of columns and rows. It should be contained within a separate div and should not interfere with other objects or alter the parent's size. The grid needs to be square and I am currently u ...